refactoring

This commit is contained in:
Chris Lu 2021-10-31 18:05:34 -07:00
parent 006b4ec0f8
commit f17fa400d5
10 changed files with 90 additions and 90 deletions

View File

@ -362,7 +362,7 @@ func (iama *IamApiServer) DeleteAccessKey(s3cfg *iam_pb.S3ApiConfiguration, valu
func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInvalidRequest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
return
}
values := r.PostForm
@ -370,7 +370,7 @@ func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
s3cfgLock.RLock()
s3cfg := &iam_pb.S3ApiConfiguration{}
if err := iama.s3ApiConfig.GetS3ApiConfiguration(s3cfg); err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
s3cfgLock.RUnlock()
@ -411,14 +411,14 @@ func (iama *IamApiServer) DoActions(w http.ResponseWriter, r *http.Request) {
response, err = iama.CreatePolicy(s3cfg, values)
if err != nil {
glog.Errorf("CreatePolicy: %+v", err)
s3err.WriteErrorResponse(w, s3err.ErrInvalidRequest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
return
}
case "PutUserPolicy":
response, err = iama.PutUserPolicy(s3cfg, values)
if err != nil {
glog.Errorf("PutUserPolicy: %+v", err)
s3err.WriteErrorResponse(w, s3err.ErrInvalidRequest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
return
}
case "GetUserPolicy":

View File

@ -182,7 +182,7 @@ func (iam *IdentityAccessManagement) Auth(f http.HandlerFunc, action Action) htt
f(w, r)
return
}
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
}
}

View File

@ -36,7 +36,7 @@ func (s3a *S3ApiServer) ListBucketsHandler(w http.ResponseWriter, r *http.Reques
if s3a.iam.isEnabled() {
identity, s3Err = s3a.iam.authUser(r)
if s3Err != s3err.ErrNone {
s3err.WriteErrorResponse(w, s3Err, r)
s3err.WriteErrorResponse(w, r, s3Err)
return
}
}
@ -46,7 +46,7 @@ func (s3a *S3ApiServer) ListBucketsHandler(w http.ResponseWriter, r *http.Reques
entries, _, err := s3a.list(s3a.option.BucketsPath, "", "", false, math.MaxInt32)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
@ -100,14 +100,14 @@ func (s3a *S3ApiServer) PutBucketHandler(w http.ResponseWriter, r *http.Request)
}
return nil
}); err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
if exist, err := s3a.exists(s3a.option.BucketsPath, bucket, true); err == nil && exist {
errCode = s3err.ErrBucketAlreadyExists
}
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}
@ -123,7 +123,7 @@ func (s3a *S3ApiServer) PutBucketHandler(w http.ResponseWriter, r *http.Request)
// create the folder for bucket, but lazily create actual collection
if err := s3a.mkdir(s3a.option.BucketsPath, bucket, fn); err != nil {
glog.Errorf("PutBucketHandler mkdir: %v", err)
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
@ -136,7 +136,7 @@ func (s3a *S3ApiServer) DeleteBucketHandler(w http.ResponseWriter, r *http.Reque
glog.V(3).Infof("DeleteBucketHandler %s", bucket)
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
s3err.WriteErrorResponse(w, err, r)
s3err.WriteErrorResponse(w, r, err)
return
}
@ -158,7 +158,7 @@ func (s3a *S3ApiServer) DeleteBucketHandler(w http.ResponseWriter, r *http.Reque
err = s3a.rm(s3a.option.BucketsPath, bucket, false, true)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
@ -171,7 +171,7 @@ func (s3a *S3ApiServer) HeadBucketHandler(w http.ResponseWriter, r *http.Request
glog.V(3).Infof("HeadBucketHandler %s", bucket)
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
s3err.WriteErrorResponse(w, err, r)
s3err.WriteErrorResponse(w, r, err)
return
}
@ -216,7 +216,7 @@ func (s3a *S3ApiServer) GetBucketAclHandler(w http.ResponseWriter, r *http.Reque
glog.V(3).Infof("GetBucketAclHandler %s", bucket)
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
s3err.WriteErrorResponse(w, err, r)
s3err.WriteErrorResponse(w, r, err)
return
}
@ -256,18 +256,18 @@ func (s3a *S3ApiServer) GetBucketLifecycleConfigurationHandler(w http.ResponseWr
glog.V(3).Infof("GetBucketAclHandler %s", bucket)
if err := s3a.checkBucket(r, bucket); err != s3err.ErrNone {
s3err.WriteErrorResponse(w, err, r)
s3err.WriteErrorResponse(w, r, err)
return
}
fc, err := filer.ReadFilerConf(s3a.option.Filer, s3a.option.GrpcDialOption, nil)
if err != nil {
glog.Errorf("GetBucketLifecycleConfigurationHandler: %s", err)
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
ttls := fc.GetCollectionTtls(bucket)
if len(ttls) == 0 {
s3err.WriteErrorResponse(w, s3err.ErrNoSuchLifecycleConfiguration, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchLifecycleConfiguration)
return
}
response := Lifecycle{}
@ -292,7 +292,7 @@ func (s3a *S3ApiServer) GetBucketLifecycleConfigurationHandler(w http.ResponseWr
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketLifecycleConfiguration.html
func (s3a *S3ApiServer) PutBucketLifecycleConfigurationHandler(w http.ResponseWriter, r *http.Request) {
s3err.WriteErrorResponse(w, s3err.ErrNotImplemented, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNotImplemented)
}

View File

@ -34,13 +34,13 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
dir, name := fullPath.DirAndName()
entry, err := s3a.getEntry(dir, name)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
return
}
entry.Extended = weed_server.SaveAmzMetaData(r, entry.Extended, isReplace(r))
err = s3a.touch(dir, name, entry)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
return
}
writeSuccessResponseXML(w, r, CopyObjectResult{
@ -52,19 +52,19 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
// If source object is empty or bucket is empty, reply back invalid copy source.
if srcObject == "" || srcBucket == "" {
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
return
}
srcPath := util.FullPath(fmt.Sprintf("%s/%s%s", s3a.option.BucketsPath, srcBucket, srcObject))
dir, name := srcPath.DirAndName()
_, err = s3a.getEntry(dir, name)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
return
}
if srcBucket == dstBucket && srcObject == dstObject {
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopyDest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopyDest)
return
}
@ -75,7 +75,7 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
_, _, resp, err := util.DownloadFile(srcUrl, "")
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
return
}
defer util.CloseResponse(resp)
@ -84,7 +84,7 @@ func (s3a *S3ApiServer) CopyObjectHandler(w http.ResponseWriter, r *http.Request
etag, errCode := s3a.putToFiler(r, dstUrl, resp.Body)
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}
@ -128,7 +128,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
srcBucket, srcObject := pathToBucketAndObject(cpSrcPath)
// If source object is empty or bucket is empty, reply back invalid copy source.
if srcObject == "" || srcBucket == "" {
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
return
}
@ -137,7 +137,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
partID, err := strconv.Atoi(partIDString)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInvalidPart, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidPart)
return
}
@ -145,7 +145,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
// check partID with maximum part ID for multipart objects
if partID > globalMaxPartID {
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxParts, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxParts)
return
}
@ -158,7 +158,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
dataReader, err := util.ReadUrlAsReaderCloser(srcUrl, rangeHeader)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInvalidCopySource, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
return
}
defer dataReader.Close()
@ -167,7 +167,7 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Req
etag, errCode := s3a.putToFiler(r, dstUrl, dataReader)
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}

View File

@ -56,20 +56,20 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
_, err := validateContentMd5(r.Header)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInvalidDigest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidDigest)
return
}
if r.Header.Get("Cache-Control") != "" {
if _, err = cacheobject.ParseRequestCacheControl(r.Header.Get("Cache-Control")); err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInvalidDigest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidDigest)
return
}
}
if r.Header.Get("Expires") != "" {
if _, err = time.Parse(http.TimeFormat, r.Header.Get("Expires")); err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInvalidDigest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidDigest)
return
}
}
@ -87,12 +87,12 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
_, s3ErrCode = s3a.iam.reqSignatureV4Verify(r)
}
if s3ErrCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, s3ErrCode, r)
s3err.WriteErrorResponse(w, r, s3ErrCode)
return
}
} else {
if authTypeStreamingSigned == rAuthType {
s3err.WriteErrorResponse(w, s3err.ErrAuthNotSetup, r)
s3err.WriteErrorResponse(w, r, s3err.ErrAuthNotSetup)
return
}
}
@ -100,7 +100,7 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
if strings.HasSuffix(object, "/") {
if err := s3a.mkdir(s3a.option.BucketsPath, bucket+object, nil); err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
} else {
@ -113,7 +113,7 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
etag, errCode := s3a.putToFiler(r, uploadUrl, dataReader)
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}
@ -137,7 +137,7 @@ func (s3a *S3ApiServer) GetObjectHandler(w http.ResponseWriter, r *http.Request)
glog.V(3).Infof("GetObjectHandler %s %s", bucket, object)
if strings.HasSuffix(r.URL.Path, "/") {
s3err.WriteErrorResponse(w, s3err.ErrNotImplemented, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNotImplemented)
return
}
@ -215,13 +215,13 @@ func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *h
deleteXMLBytes, err := io.ReadAll(r.Body)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
deleteObjects := &DeleteObjectsRequest{}
if err := xml.Unmarshal(deleteXMLBytes, deleteObjects); err != nil {
s3err.WriteErrorResponse(w, s3err.ErrMalformedXML, r)
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedXML)
return
}
@ -317,7 +317,7 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des
if err != nil {
glog.Errorf("NewRequest %s: %v", destUrl, err)
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
@ -346,19 +346,19 @@ func (s3a *S3ApiServer) proxyToFiler(w http.ResponseWriter, r *http.Request, des
if postErr != nil {
glog.Errorf("post to filer: %v", postErr)
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
defer util.CloseResponse(resp)
if resp.StatusCode == http.StatusPreconditionFailed {
s3err.WriteErrorResponse(w, s3err.ErrPreconditionFailed, r)
s3err.WriteErrorResponse(w, r, s3err.ErrPreconditionFailed)
return
}
if (resp.ContentLength == -1 || resp.StatusCode == 404) && resp.StatusCode != 304 {
if r.Method != "DELETE" {
s3err.WriteErrorResponse(w, s3err.ErrNoSuchKey, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey)
return
}
}

View File

@ -29,23 +29,23 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
reader, err := r.MultipartReader()
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedPOSTRequest)
return
}
form, err := reader.ReadForm(int64(5 * humanize.MiByte))
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedPOSTRequest)
return
}
defer form.RemoveAll()
fileBody, fileName, fileSize, formValues, err := extractPostPolicyFormValues(form)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedPOSTRequest)
return
}
if fileBody == nil {
s3err.WriteErrorResponse(w, s3err.ErrPOSTFileRequired, r)
s3err.WriteErrorResponse(w, r, s3err.ErrPOSTFileRequired)
return
}
defer fileBody.Close()
@ -63,7 +63,7 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
if successRedirect != "" {
redirectURL, err = url.Parse(successRedirect)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedPOSTRequest)
return
}
}
@ -71,13 +71,13 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
// Verify policy signature.
errCode := s3a.iam.doesPolicySignatureMatch(formValues)
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}
policyBytes, err := base64.StdEncoding.DecodeString(formValues.Get("Policy"))
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrMalformedPOSTRequest, r)
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedPOSTRequest)
return
}
@ -86,7 +86,7 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
postPolicyForm, err := policy.ParsePostPolicyForm(string(policyBytes))
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrPostPolicyConditionInvalidFormat, r)
s3err.WriteErrorResponse(w, r, s3err.ErrPostPolicyConditionInvalidFormat)
return
}
@ -102,12 +102,12 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
lengthRange := postPolicyForm.Conditions.ContentLengthRange
if lengthRange.Valid {
if fileSize < lengthRange.Min {
s3err.WriteErrorResponse(w, s3err.ErrEntityTooSmall, r)
s3err.WriteErrorResponse(w, r, s3err.ErrEntityTooSmall)
return
}
if fileSize > lengthRange.Max {
s3err.WriteErrorResponse(w, s3err.ErrEntityTooLarge, r)
s3err.WriteErrorResponse(w, r, s3err.ErrEntityTooLarge)
return
}
}
@ -118,7 +118,7 @@ func (s3a *S3ApiServer) PostPolicyBucketHandler(w http.ResponseWriter, r *http.R
etag, errCode := s3a.putToFiler(r, uploadUrl, fileBody)
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}

View File

@ -45,7 +45,7 @@ func (s3a *S3ApiServer) NewMultipartUploadHandler(w http.ResponseWriter, r *http
glog.V(2).Info("NewMultipartUploadHandler", string(s3err.EncodeXMLResponse(response)), errCode)
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}
@ -69,7 +69,7 @@ func (s3a *S3ApiServer) CompleteMultipartUploadHandler(w http.ResponseWriter, r
glog.V(2).Info("CompleteMultipartUploadHandler", string(s3err.EncodeXMLResponse(response)), errCode)
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}
@ -91,7 +91,7 @@ func (s3a *S3ApiServer) AbortMultipartUploadHandler(w http.ResponseWriter, r *ht
})
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}
@ -107,13 +107,13 @@ func (s3a *S3ApiServer) ListMultipartUploadsHandler(w http.ResponseWriter, r *ht
prefix, keyMarker, uploadIDMarker, delimiter, maxUploads, encodingType := getBucketMultipartResources(r.URL.Query())
if maxUploads < 0 {
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxUploads, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxUploads)
return
}
if keyMarker != "" {
// Marker not common with prefix is not implemented.
if !strings.HasPrefix(keyMarker, prefix) {
s3err.WriteErrorResponse(w, s3err.ErrNotImplemented, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNotImplemented)
return
}
}
@ -131,7 +131,7 @@ func (s3a *S3ApiServer) ListMultipartUploadsHandler(w http.ResponseWriter, r *ht
glog.V(2).Infof("ListMultipartUploadsHandler %s errCode=%d", string(s3err.EncodeXMLResponse(response)), errCode)
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}
@ -146,11 +146,11 @@ func (s3a *S3ApiServer) ListObjectPartsHandler(w http.ResponseWriter, r *http.Re
uploadID, partNumberMarker, maxParts, _ := getObjectResources(r.URL.Query())
if partNumberMarker < 0 {
s3err.WriteErrorResponse(w, s3err.ErrInvalidPartNumberMarker, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidPartNumberMarker)
return
}
if maxParts < 0 {
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxParts, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxParts)
return
}
@ -165,7 +165,7 @@ func (s3a *S3ApiServer) ListObjectPartsHandler(w http.ResponseWriter, r *http.Re
glog.V(2).Infof("ListObjectPartsHandler %s count=%d", string(s3err.EncodeXMLResponse(response)), len(response.Part))
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}
@ -180,18 +180,18 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
uploadID := r.URL.Query().Get("uploadId")
exists, err := s3a.exists(s3a.genUploadsFolder(bucket), uploadID, true)
if !exists {
s3err.WriteErrorResponse(w, s3err.ErrNoSuchUpload, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchUpload)
return
}
partIDString := r.URL.Query().Get("partNumber")
partID, err := strconv.Atoi(partIDString)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInvalidPart, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidPart)
return
}
if partID > globalMaxPartID {
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxParts, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxParts)
return
}
@ -208,7 +208,7 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
_, s3ErrCode = s3a.iam.reqSignatureV4Verify(r)
}
if s3ErrCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, s3ErrCode, r)
s3err.WriteErrorResponse(w, r, s3ErrCode)
return
}
}
@ -225,7 +225,7 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
etag, errCode := s3a.putToFiler(r, uploadUrl, dataReader)
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, errCode, r)
s3err.WriteErrorResponse(w, r, errCode)
return
}

View File

@ -26,10 +26,10 @@ func (s3a *S3ApiServer) GetObjectTaggingHandler(w http.ResponseWriter, r *http.R
if err != nil {
if err == filer_pb.ErrNotFound {
glog.Errorf("GetObjectTaggingHandler %s: %v", r.URL, err)
s3err.WriteErrorResponse(w, s3err.ErrNoSuchKey, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey)
} else {
glog.Errorf("GetObjectTaggingHandler %s: %v", r.URL, err)
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
}
return
}
@ -52,29 +52,29 @@ func (s3a *S3ApiServer) PutObjectTaggingHandler(w http.ResponseWriter, r *http.R
input, err := io.ReadAll(io.LimitReader(r.Body, r.ContentLength))
if err != nil {
glog.Errorf("PutObjectTaggingHandler read input %s: %v", r.URL, err)
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
if err = xml.Unmarshal(input, tagging); err != nil {
glog.Errorf("PutObjectTaggingHandler Unmarshal %s: %v", r.URL, err)
s3err.WriteErrorResponse(w, s3err.ErrMalformedXML, r)
s3err.WriteErrorResponse(w, r, s3err.ErrMalformedXML)
return
}
tags := tagging.ToTags()
if len(tags) > 10 {
glog.Errorf("PutObjectTaggingHandler tags %s: %d tags more than 10", r.URL, len(tags))
s3err.WriteErrorResponse(w, s3err.ErrInvalidTag, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidTag)
return
}
for k, v := range tags {
if len(k) > 128 {
glog.Errorf("PutObjectTaggingHandler tags %s: tag key %s longer than 128", r.URL, k)
s3err.WriteErrorResponse(w, s3err.ErrInvalidTag, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidTag)
return
}
if len(v) > 256 {
glog.Errorf("PutObjectTaggingHandler tags %s: tag value %s longer than 256", r.URL, v)
s3err.WriteErrorResponse(w, s3err.ErrInvalidTag, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidTag)
return
}
}
@ -82,10 +82,10 @@ func (s3a *S3ApiServer) PutObjectTaggingHandler(w http.ResponseWriter, r *http.R
if err = s3a.setTags(dir, name, tagging.ToTags()); err != nil {
if err == filer_pb.ErrNotFound {
glog.Errorf("PutObjectTaggingHandler setTags %s: %v", r.URL, err)
s3err.WriteErrorResponse(w, s3err.ErrNoSuchKey, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey)
} else {
glog.Errorf("PutObjectTaggingHandler setTags %s: %v", r.URL, err)
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
}
return
}
@ -108,10 +108,10 @@ func (s3a *S3ApiServer) DeleteObjectTaggingHandler(w http.ResponseWriter, r *htt
if err != nil {
if err == filer_pb.ErrNotFound {
glog.Errorf("DeleteObjectTaggingHandler %s: %v", r.URL, err)
s3err.WriteErrorResponse(w, s3err.ErrNoSuchKey, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchKey)
} else {
glog.Errorf("DeleteObjectTaggingHandler %s: %v", r.URL, err)
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
}
return
}

View File

@ -45,11 +45,11 @@ func (s3a *S3ApiServer) ListObjectsV2Handler(w http.ResponseWriter, r *http.Requ
originalPrefix, continuationToken, startAfter, delimiter, _, maxKeys := getListObjectsV2Args(r.URL.Query())
if maxKeys < 0 {
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxKeys, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxKeys)
return
}
if delimiter != "" && delimiter != "/" {
s3err.WriteErrorResponse(w, s3err.ErrNotImplemented, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNotImplemented)
return
}
@ -61,13 +61,13 @@ func (s3a *S3ApiServer) ListObjectsV2Handler(w http.ResponseWriter, r *http.Requ
response, err := s3a.listFilerEntries(bucket, originalPrefix, maxKeys, marker, delimiter)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
if len(response.Contents) == 0 {
if exists, existErr := s3a.exists(s3a.option.BucketsPath, bucket, true); existErr == nil && !exists {
s3err.WriteErrorResponse(w, s3err.ErrNoSuchBucket, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchBucket)
return
}
}
@ -101,24 +101,24 @@ func (s3a *S3ApiServer) ListObjectsV1Handler(w http.ResponseWriter, r *http.Requ
originalPrefix, marker, delimiter, maxKeys := getListObjectsV1Args(r.URL.Query())
if maxKeys < 0 {
s3err.WriteErrorResponse(w, s3err.ErrInvalidMaxKeys, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidMaxKeys)
return
}
if delimiter != "" && delimiter != "/" {
s3err.WriteErrorResponse(w, s3err.ErrNotImplemented, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNotImplemented)
return
}
response, err := s3a.listFilerEntries(bucket, originalPrefix, maxKeys, marker, delimiter)
if err != nil {
s3err.WriteErrorResponse(w, s3err.ErrInternalError, r)
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
if len(response.Contents) == 0 {
if exists, existErr := s3a.exists(s3a.option.BucketsPath, bucket, true); existErr == nil && !exists {
s3err.WriteErrorResponse(w, s3err.ErrNoSuchBucket, r)
s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchBucket)
return
}
}

View File

@ -27,7 +27,7 @@ func WriteEmptyResponse(w http.ResponseWriter, r *http.Request, statusCode int)
WriteResponse(w, r, statusCode, []byte{}, mimeNone)
}
func WriteErrorResponse(w http.ResponseWriter, errorCode ErrorCode, r *http.Request) {
func WriteErrorResponse(w http.ResponseWriter, r *http.Request, errorCode ErrorCode) {
vars := mux.Vars(r)
bucket := vars["bucket"]
object := vars["object"]
@ -88,5 +88,5 @@ func WriteResponse(w http.ResponseWriter, r *http.Request, statusCode int, respo
// If none of the http routes match respond with MethodNotAllowed
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
glog.V(0).Infof("unsupported %s %s", r.Method, r.RequestURI)
WriteErrorResponse(w, ErrMethodNotAllowed, r)
WriteErrorResponse(w, r, ErrMethodNotAllowed)
}