2018-07-18 17:37:09 +08:00
|
|
|
package s3api
|
|
|
|
|
|
|
|
import (
|
2018-07-22 08:39:10 +08:00
|
|
|
"encoding/base64"
|
|
|
|
"fmt"
|
2022-08-24 14:18:21 +08:00
|
|
|
"net/http"
|
|
|
|
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
2020-02-26 13:50:12 +08:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
2018-07-18 17:37:09 +08:00
|
|
|
)
|
|
|
|
|
2020-04-30 04:26:02 +08:00
|
|
|
var _ = filer_pb.FilerClient(&S3ApiServer{})
|
|
|
|
|
2021-12-26 16:15:03 +08:00
|
|
|
func (s3a *S3ApiServer) WithFilerClient(streamingMode bool, fn func(filer_pb.SeaweedFilerClient) error) error {
|
2018-07-18 17:37:09 +08:00
|
|
|
|
2023-01-20 17:48:12 +08:00
|
|
|
return pb.WithGrpcClient(streamingMode, s3a.randomClientId, func(grpcConnection *grpc.ClientConn) error {
|
2019-04-06 11:31:58 +08:00
|
|
|
client := filer_pb.NewSeaweedFilerClient(grpcConnection)
|
|
|
|
return fn(client)
|
2022-08-24 14:18:21 +08:00
|
|
|
}, s3a.option.Filer.ToGrpcAddress(), false, s3a.option.GrpcDialOption)
|
2018-07-18 17:37:09 +08:00
|
|
|
|
|
|
|
}
|
2021-10-11 18:03:56 +08:00
|
|
|
|
2021-01-29 06:36:29 +08:00
|
|
|
func (s3a *S3ApiServer) AdjustedUrl(location *filer_pb.Location) string {
|
|
|
|
return location.Url
|
|
|
|
}
|
2020-03-23 15:06:24 +08:00
|
|
|
|
2022-08-05 08:35:00 +08:00
|
|
|
func (s3a *S3ApiServer) GetDataCenter() string {
|
|
|
|
return s3a.option.DataCenter
|
|
|
|
}
|
|
|
|
|
2021-11-01 09:02:08 +08:00
|
|
|
func writeSuccessResponseXML(w http.ResponseWriter, r *http.Request, response interface{}) {
|
|
|
|
s3err.WriteXMLResponse(w, r, http.StatusOK, response)
|
2021-12-07 21:20:52 +08:00
|
|
|
s3err.PostLog(r, http.StatusOK, s3err.ErrNone)
|
2018-07-18 17:37:09 +08:00
|
|
|
}
|
2018-07-19 16:21:44 +08:00
|
|
|
|
2021-11-01 09:02:08 +08:00
|
|
|
func writeSuccessResponseEmpty(w http.ResponseWriter, r *http.Request) {
|
|
|
|
s3err.WriteEmptyResponse(w, r, http.StatusOK)
|
2018-07-19 16:21:44 +08:00
|
|
|
}
|
2018-07-22 01:39:02 +08:00
|
|
|
|
2023-12-21 08:21:11 +08:00
|
|
|
func writeFailureResponse(w http.ResponseWriter, r *http.Request, errCode s3err.ErrorCode) {
|
|
|
|
s3err.WriteErrorResponse(w, r, errCode)
|
|
|
|
}
|
|
|
|
|
2018-07-22 01:39:02 +08: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
|
|
|
|
}
|