2018-07-18 09:37:09 +00:00
|
|
|
package s3api
|
|
|
|
|
|
|
|
import (
|
2018-07-22 00:39:10 +00:00
|
|
|
"encoding/base64"
|
|
|
|
"fmt"
|
2020-09-19 21:09:58 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/s3api/s3err"
|
2020-02-26 05:50:12 +00:00
|
|
|
"google.golang.org/grpc"
|
2021-06-11 04:50:21 +00:00
|
|
|
"net/http"
|
2020-02-26 05:50:12 +00:00
|
|
|
|
2020-03-04 08:39:47 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
2020-02-26 05:50:12 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2018-07-18 09:37:09 +00:00
|
|
|
)
|
|
|
|
|
2020-04-29 20:26:02 +00:00
|
|
|
var _ = filer_pb.FilerClient(&S3ApiServer{})
|
|
|
|
|
2020-03-23 06:52:55 +00:00
|
|
|
func (s3a *S3ApiServer) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
|
2018-07-18 09:37:09 +00:00
|
|
|
|
2020-03-04 08:39:47 +00:00
|
|
|
return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
|
2019-04-06 03:31:58 +00:00
|
|
|
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
|
|
|
return fn(client)
|
2021-09-13 05:47:52 +00:00
|
|
|
}, s3a.option.Filer.ToGrpcAddress(), s3a.option.GrpcDialOption)
|
2018-07-18 09:37:09 +00:00
|
|
|
|
|
|
|
}
|
2021-01-28 22:36:29 +00:00
|
|
|
func (s3a *S3ApiServer) AdjustedUrl(location *filer_pb.Location) string {
|
|
|
|
return location.Url
|
|
|
|
}
|
2020-03-23 07:06:24 +00:00
|
|
|
|
2021-06-11 04:50:21 +00:00
|
|
|
func writeSuccessResponseXML(w http.ResponseWriter, response interface{}) {
|
|
|
|
s3err.WriteXMLResponse(w, http.StatusOK, response)
|
2018-07-18 09:37:09 +00:00
|
|
|
}
|
2018-07-19 08:21:44 +00:00
|
|
|
|
|
|
|
func writeSuccessResponseEmpty(w http.ResponseWriter) {
|
2021-06-11 04:50:21 +00:00
|
|
|
s3err.WriteEmptyResponse(w, http.StatusOK)
|
2018-07-19 08:21:44 +00:00
|
|
|
}
|
2018-07-21 17:39:02 +00:00
|
|
|
|
|
|
|
func validateContentMd5(h http.Header) ([]byte, error) {
|
|
|
|
md5B64, ok := h["Content-Md5"]
|
|
|
|
if ok {
|
|
|
|
if md5B64[0] == "" {
|
|
|
|
return nil, fmt.Errorf("Content-Md5 header set to empty value")
|
|
|
|
}
|
|
|
|
return base64.StdEncoding.DecodeString(md5B64[0])
|
|
|
|
}
|
|
|
|
return []byte{}, nil
|
|
|
|
}
|