2020-07-22 13:02:32 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-08-11 11:30:02 +00:00
|
|
|
"context"
|
2023-07-05 14:05:45 +00:00
|
|
|
"fmt"
|
2020-07-22 13:02:32 +00:00
|
|
|
"net/http"
|
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/auth"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
2023-07-05 14:05:45 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
|
|
|
s3middleware "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
|
2023-04-07 14:28:21 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/metrics"
|
2023-07-05 14:05:45 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/go-chi/chi/v5/middleware"
|
2020-07-22 19:48:34 +00:00
|
|
|
"go.uber.org/zap"
|
2020-07-22 13:02:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2021-05-13 20:25:31 +00:00
|
|
|
// Handler is an S3 API handler interface.
|
2020-07-22 13:02:32 +00:00
|
|
|
Handler interface {
|
|
|
|
HeadObjectHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetObjectACLHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutObjectACLHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetObjectTaggingHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutObjectTaggingHandler(http.ResponseWriter, *http.Request)
|
|
|
|
DeleteObjectTaggingHandler(http.ResponseWriter, *http.Request)
|
|
|
|
SelectObjectContentHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetObjectRetentionHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetObjectLegalHoldHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetObjectHandler(http.ResponseWriter, *http.Request)
|
2022-05-12 21:15:08 +00:00
|
|
|
GetObjectAttributesHandler(http.ResponseWriter, *http.Request)
|
2020-07-22 13:02:32 +00:00
|
|
|
CopyObjectHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutObjectRetentionHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutObjectLegalHoldHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutObjectHandler(http.ResponseWriter, *http.Request)
|
|
|
|
DeleteObjectHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketLocationHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketPolicyHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketLifecycleHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketEncryptionHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketACLHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutBucketACLHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketCorsHandler(http.ResponseWriter, *http.Request)
|
2021-10-04 14:32:35 +00:00
|
|
|
PutBucketCorsHandler(http.ResponseWriter, *http.Request)
|
|
|
|
DeleteBucketCorsHandler(http.ResponseWriter, *http.Request)
|
2020-07-22 13:02:32 +00:00
|
|
|
GetBucketWebsiteHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketAccelerateHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketRequestPaymentHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketLoggingHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketReplicationHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketTaggingHandler(http.ResponseWriter, *http.Request)
|
|
|
|
DeleteBucketWebsiteHandler(http.ResponseWriter, *http.Request)
|
|
|
|
DeleteBucketTaggingHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketObjectLockConfigHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketVersioningHandler(http.ResponseWriter, *http.Request)
|
|
|
|
GetBucketNotificationHandler(http.ResponseWriter, *http.Request)
|
|
|
|
ListenBucketNotificationHandler(http.ResponseWriter, *http.Request)
|
|
|
|
ListObjectsV2MHandler(http.ResponseWriter, *http.Request)
|
|
|
|
ListObjectsV2Handler(http.ResponseWriter, *http.Request)
|
|
|
|
ListBucketObjectVersionsHandler(http.ResponseWriter, *http.Request)
|
|
|
|
ListObjectsV1Handler(http.ResponseWriter, *http.Request)
|
|
|
|
PutBucketLifecycleHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutBucketEncryptionHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutBucketPolicyHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutBucketObjectLockConfigHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutBucketTaggingHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutBucketVersioningHandler(http.ResponseWriter, *http.Request)
|
|
|
|
PutBucketNotificationHandler(http.ResponseWriter, *http.Request)
|
2021-06-23 20:21:15 +00:00
|
|
|
CreateBucketHandler(http.ResponseWriter, *http.Request)
|
2020-07-22 13:02:32 +00:00
|
|
|
HeadBucketHandler(http.ResponseWriter, *http.Request)
|
2021-08-30 19:44:53 +00:00
|
|
|
PostObject(http.ResponseWriter, *http.Request)
|
2020-07-22 13:02:32 +00:00
|
|
|
DeleteMultipleObjectsHandler(http.ResponseWriter, *http.Request)
|
|
|
|
DeleteBucketPolicyHandler(http.ResponseWriter, *http.Request)
|
|
|
|
DeleteBucketLifecycleHandler(http.ResponseWriter, *http.Request)
|
|
|
|
DeleteBucketEncryptionHandler(http.ResponseWriter, *http.Request)
|
|
|
|
DeleteBucketHandler(http.ResponseWriter, *http.Request)
|
|
|
|
ListBucketsHandler(http.ResponseWriter, *http.Request)
|
2021-10-04 14:32:35 +00:00
|
|
|
Preflight(w http.ResponseWriter, r *http.Request)
|
|
|
|
AppendCORSHeaders(w http.ResponseWriter, r *http.Request)
|
2021-11-25 15:05:58 +00:00
|
|
|
CreateMultipartUploadHandler(http.ResponseWriter, *http.Request)
|
|
|
|
UploadPartHandler(http.ResponseWriter, *http.Request)
|
|
|
|
UploadPartCopy(w http.ResponseWriter, r *http.Request)
|
|
|
|
CompleteMultipartUploadHandler(http.ResponseWriter, *http.Request)
|
|
|
|
AbortMultipartUploadHandler(http.ResponseWriter, *http.Request)
|
|
|
|
ListPartsHandler(w http.ResponseWriter, r *http.Request)
|
|
|
|
ListMultipartUploadsHandler(http.ResponseWriter, *http.Request)
|
2022-12-23 12:28:30 +00:00
|
|
|
|
|
|
|
ResolveBucket(ctx context.Context, bucket string) (*data.BucketInfo, error)
|
2020-07-22 13:02:32 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
func AttachChi(api *chi.Mux, domains []string, throttle middleware.ThrottleOpts, h Handler, center auth.Center, log *zap.Logger, appMetrics *metrics.AppMetrics) {
|
|
|
|
api.Use(
|
|
|
|
s3middleware.Request(log),
|
|
|
|
middleware.ThrottleWithOpts(throttle),
|
|
|
|
middleware.Recoverer,
|
|
|
|
s3middleware.Tracing(),
|
|
|
|
s3middleware.Metrics(log, h.ResolveBucket, appMetrics),
|
|
|
|
s3middleware.LogSuccessResponse(log),
|
|
|
|
s3middleware.Auth(center, log),
|
|
|
|
)
|
2021-10-04 14:32:35 +00:00
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
defaultRouter := chi.NewRouter()
|
|
|
|
defaultRouter.Mount(fmt.Sprintf("/{%s}", s3middleware.BucketURLPrm), bucketRouter(h, log))
|
|
|
|
defaultRouter.Get("/", named("ListBuckets", h.ListBucketsHandler))
|
2022-12-23 12:28:30 +00:00
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
hr := NewHostBucketRouter("bucket")
|
|
|
|
hr.Default(defaultRouter)
|
|
|
|
for _, domain := range domains {
|
|
|
|
hr.Map(domain, bucketRouter(h, log))
|
2022-12-27 12:30:11 +00:00
|
|
|
}
|
2023-07-05 14:05:45 +00:00
|
|
|
api.Mount("/", hr)
|
2022-12-23 12:28:30 +00:00
|
|
|
|
2023-07-19 14:55:00 +00:00
|
|
|
attachErrorHandler(api)
|
2022-12-23 12:28:30 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
func named(name string, handlerFunc http.HandlerFunc) http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
reqInfo := s3middleware.GetReqInfo(r.Context())
|
|
|
|
reqInfo.API = name
|
|
|
|
handlerFunc.ServeHTTP(w, r)
|
2020-08-19 23:28:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
// If none of the http routes match respond with appropriate errors.
|
|
|
|
func errorResponseHandler(w http.ResponseWriter, r *http.Request) {
|
2023-07-19 14:55:00 +00:00
|
|
|
ctx := r.Context()
|
|
|
|
reqInfo := s3middleware.GetReqInfo(ctx)
|
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
desc := fmt.Sprintf("Unknown API request at %s", r.URL.Path)
|
2023-07-19 14:55:00 +00:00
|
|
|
s3middleware.WriteErrorResponse(w, reqInfo, errors.Error{
|
2023-07-05 14:05:45 +00:00
|
|
|
Code: "UnknownAPIRequest",
|
|
|
|
Description: desc,
|
|
|
|
HTTPStatusCode: http.StatusBadRequest,
|
2022-12-27 12:30:11 +00:00
|
|
|
})
|
|
|
|
|
2023-07-19 14:55:00 +00:00
|
|
|
if log := s3middleware.GetReqLog(ctx); log != nil {
|
|
|
|
log.Error("request unmatched", zap.String("method", reqInfo.API))
|
2022-12-27 12:30:11 +00:00
|
|
|
}
|
2023-07-19 14:55:00 +00:00
|
|
|
}
|
2022-12-27 12:30:11 +00:00
|
|
|
|
2023-07-19 14:55:00 +00:00
|
|
|
// attachErrorHandler set NotFoundHandler and MethodNotAllowedHandler for chi.Router.
|
|
|
|
func attachErrorHandler(api *chi.Mux) {
|
|
|
|
errorHandler := http.HandlerFunc(errorResponseHandler)
|
2022-12-27 12:30:11 +00:00
|
|
|
|
|
|
|
// If none of the routes match, add default error handler routes
|
2023-07-19 14:55:00 +00:00
|
|
|
api.NotFound(named("NotFound", errorHandler))
|
|
|
|
api.MethodNotAllowed(named("MethodNotAllowed", errorHandler))
|
2022-12-27 12:30:11 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
func bucketRouter(h Handler, log *zap.Logger) chi.Router {
|
|
|
|
bktRouter := chi.NewRouter()
|
|
|
|
bktRouter.Use(
|
|
|
|
s3middleware.AddBucketName(log),
|
|
|
|
s3middleware.WrapHandler(h.AppendCORSHeaders),
|
2020-08-19 23:28:16 +00:00
|
|
|
)
|
2020-08-11 11:30:02 +00:00
|
|
|
|
2023-07-19 12:25:11 +00:00
|
|
|
bktRouter.Mount("/", objectRouter(h, log))
|
2023-07-05 14:05:45 +00:00
|
|
|
|
|
|
|
bktRouter.Options("/", h.Preflight)
|
|
|
|
|
|
|
|
bktRouter.Head("/", named("HeadBucket", h.HeadBucketHandler))
|
|
|
|
|
|
|
|
// GET method handlers
|
|
|
|
bktRouter.Group(func(r chi.Router) {
|
|
|
|
r.Method(http.MethodGet, "/", NewHandlerFilter().
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("upload").
|
|
|
|
Handler(named("ListMultipartUploads", h.ListMultipartUploadsHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("location").
|
|
|
|
Handler(named("GetBucketLocation", h.GetBucketLocationHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("policy").
|
|
|
|
Handler(named("GetBucketPolicy", h.GetBucketPolicyHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("lifecycle").
|
|
|
|
Handler(named("GetBucketLifecycle", h.GetBucketLifecycleHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("encryption").
|
|
|
|
Handler(named("GetBucketEncryption", h.GetBucketEncryptionHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("cors").
|
|
|
|
Handler(named("GetBucketCors", h.GetBucketCorsHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("acl").
|
|
|
|
Handler(named("GetBucketACL", h.GetBucketACLHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("website").
|
|
|
|
Handler(named("GetBucketWebsite", h.GetBucketWebsiteHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("accelerate").
|
|
|
|
Handler(named("GetBucketAccelerate", h.GetBucketAccelerateHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("requestPayment").
|
|
|
|
Handler(named("GetBucketRequestPayment", h.GetBucketRequestPaymentHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("logging").
|
|
|
|
Handler(named("GetBucketLogging", h.GetBucketLoggingHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("replication").
|
|
|
|
Handler(named("GetBucketReplication", h.GetBucketReplicationHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("tagging").
|
|
|
|
Handler(named("GetBucketTagging", h.GetBucketTaggingHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("object-lock").
|
|
|
|
Handler(named("GetBucketObjectLockConfig", h.GetBucketObjectLockConfigHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("versioning").
|
|
|
|
Handler(named("GetBucketVersioning", h.GetBucketVersioningHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("notification").
|
|
|
|
Handler(named("GetBucketNotification", h.GetBucketNotificationHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("events").
|
|
|
|
Handler(named("ListenBucketNotification", h.ListenBucketNotificationHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
QueriesMatch("list-type", "2", "metadata", "true").
|
|
|
|
Handler(named("ListObjectsV2M", h.ListObjectsV2MHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
QueriesMatch("list-type", "2").
|
|
|
|
Handler(named("ListObjectsV2", h.ListObjectsV2Handler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("versions").
|
|
|
|
Handler(named("ListBucketObjectVersions", h.ListBucketObjectVersionsHandler))).
|
|
|
|
DefaultHandler(named("ListObjectsV1", h.ListObjectsV1Handler)))
|
|
|
|
})
|
2020-07-22 13:02:32 +00:00
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
// PUT method handlers
|
|
|
|
bktRouter.Group(func(r chi.Router) {
|
|
|
|
r.Method(http.MethodPut, "/", NewHandlerFilter().
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("cors").
|
|
|
|
Handler(named("PutBucketCors", h.PutBucketCorsHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("acl").
|
|
|
|
Handler(named("PutBucketACL", h.PutBucketACLHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("lifecycle").
|
|
|
|
Handler(named("PutBucketLifecycle", h.PutBucketLifecycleHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("encryption").
|
|
|
|
Handler(named("PutBucketEncryption", h.PutBucketEncryptionHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("policy").
|
|
|
|
Handler(named("PutBucketPolicy", h.PutBucketPolicyHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("object-lock").
|
|
|
|
Handler(named("PutBucketObjectLockConfig", h.PutBucketObjectLockConfigHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("tagging").
|
|
|
|
Handler(named("PutBucketTagging", h.PutBucketTaggingHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("versioning").
|
|
|
|
Handler(named("PutBucketVersioning", h.PutBucketVersioningHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("notification").
|
|
|
|
Handler(named("PutBucketNotification", h.PutBucketNotificationHandler))).
|
|
|
|
DefaultHandler(named("CreateBucket", h.CreateBucketHandler)))
|
|
|
|
})
|
2020-12-10 15:13:28 +00:00
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
// POST method handlers
|
|
|
|
bktRouter.Group(func(r chi.Router) {
|
|
|
|
r.Method(http.MethodPost, "/", NewHandlerFilter().
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("delete").
|
|
|
|
Handler(named("DeleteMultipleObjects", h.DeleteMultipleObjectsHandler))).
|
|
|
|
// todo consider add filter to match header for defaultHandler: hdrContentType, "multipart/form-data*"
|
|
|
|
DefaultHandler(named("PostObject", h.PostObject)))
|
|
|
|
})
|
2020-12-10 15:13:28 +00:00
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
// DELETE method handlers
|
|
|
|
bktRouter.Group(func(r chi.Router) {
|
|
|
|
r.Method(http.MethodDelete, "/", NewHandlerFilter().
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("cors").
|
|
|
|
Handler(named("DeleteBucketCors", h.DeleteBucketCorsHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("website").
|
|
|
|
Handler(named("DeleteBucketWebsite", h.DeleteBucketWebsiteHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("tagging").
|
|
|
|
Handler(named("DeleteBucketTagging", h.DeleteBucketTaggingHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("policy").
|
|
|
|
Handler(named("PutBucketPolicy", h.PutBucketPolicyHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("lifecycle").
|
|
|
|
Handler(named("PutBucketLifecycle", h.PutBucketLifecycleHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("encryption").
|
|
|
|
Handler(named("DeleteBucketEncryption", h.DeleteBucketEncryptionHandler))).
|
|
|
|
DefaultHandler(named("DeleteBucket", h.DeleteBucketHandler)))
|
|
|
|
})
|
2020-12-10 15:13:28 +00:00
|
|
|
|
2023-07-19 14:55:00 +00:00
|
|
|
attachErrorHandler(bktRouter)
|
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
return bktRouter
|
|
|
|
}
|
2020-12-10 15:13:28 +00:00
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
func objectRouter(h Handler, l *zap.Logger) chi.Router {
|
|
|
|
objRouter := chi.NewRouter()
|
|
|
|
objRouter.Use(s3middleware.AddObjectName(l))
|
|
|
|
|
2023-07-19 12:25:11 +00:00
|
|
|
objRouter.Head("/*", named("HeadObject", h.HeadObjectHandler))
|
2023-07-05 14:05:45 +00:00
|
|
|
|
|
|
|
// GET method handlers
|
|
|
|
objRouter.Group(func(r chi.Router) {
|
2023-07-19 12:25:11 +00:00
|
|
|
r.Method(http.MethodGet, "/*", NewHandlerFilter().
|
2023-07-05 14:05:45 +00:00
|
|
|
Add(NewFilter().
|
|
|
|
Queries("uploadId").
|
|
|
|
Handler(named("ListParts", h.ListPartsHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("acl").
|
|
|
|
Handler(named("GetObjectACL", h.GetObjectACLHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("tagging").
|
|
|
|
Handler(named("GetObjectTagging", h.GetObjectTaggingHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("retention").
|
|
|
|
Handler(named("GetObjectRetention", h.GetObjectRetentionHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("legal-hold").
|
|
|
|
Handler(named("GetObjectLegalHold", h.GetObjectLegalHoldHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("attributes").
|
|
|
|
Handler(named("GetObjectAttributes", h.GetObjectAttributesHandler))).
|
|
|
|
DefaultHandler(named("GetObject", h.GetObjectHandler)))
|
|
|
|
})
|
2020-12-10 15:13:28 +00:00
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
// PUT method handlers
|
|
|
|
objRouter.Group(func(r chi.Router) {
|
2023-07-19 12:25:11 +00:00
|
|
|
r.Method(http.MethodPut, "/*", NewHandlerFilter().
|
2023-07-05 14:05:45 +00:00
|
|
|
Add(NewFilter().
|
|
|
|
Headers(AmzCopySource).
|
|
|
|
Queries("partNumber", "uploadId").
|
|
|
|
Handler(named("UploadPartCopy", h.UploadPartCopy))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("partNumber", "uploadId").
|
|
|
|
Handler(named("UploadPart", h.UploadPartHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("acl").
|
|
|
|
Handler(named("PutObjectACL", h.PutObjectACLHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("tagging").
|
|
|
|
Handler(named("PutObjectTagging", h.PutObjectTaggingHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Headers(AmzCopySource).
|
|
|
|
Handler(named("CopyObject", h.CopyObjectHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("retention").
|
|
|
|
Handler(named("PutObjectRetention", h.PutObjectRetentionHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("legal-hold").
|
|
|
|
Handler(named("PutObjectLegalHold", h.PutObjectLegalHoldHandler))).
|
|
|
|
DefaultHandler(named("PutObject", h.PutObjectHandler)))
|
|
|
|
})
|
2020-12-10 15:13:28 +00:00
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
// POST method handlers
|
|
|
|
objRouter.Group(func(r chi.Router) {
|
2023-07-19 12:25:11 +00:00
|
|
|
r.Method(http.MethodPost, "/*", NewHandlerFilter().
|
2023-07-05 14:05:45 +00:00
|
|
|
Add(NewFilter().
|
|
|
|
Queries("uploadId").
|
|
|
|
Handler(named("CompleteMultipartUpload", h.CompleteMultipartUploadHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("uploads").
|
|
|
|
Handler(named("CreateMultipartUpload", h.CreateMultipartUploadHandler))).
|
|
|
|
DefaultHandler(named("SelectObjectContent", h.SelectObjectContentHandler)))
|
|
|
|
})
|
2020-07-22 13:02:32 +00:00
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
// DELETE method handlers
|
|
|
|
objRouter.Group(func(r chi.Router) {
|
2023-07-19 12:25:11 +00:00
|
|
|
r.Method(http.MethodDelete, "/*", NewHandlerFilter().
|
2023-07-05 14:05:45 +00:00
|
|
|
Add(NewFilter().
|
|
|
|
Queries("uploadId").
|
|
|
|
Handler(named("AbortMultipartUpload", h.AbortMultipartUploadHandler))).
|
|
|
|
Add(NewFilter().
|
|
|
|
Queries("tagging").
|
|
|
|
Handler(named("DeleteObjectTagging", h.DeleteObjectTaggingHandler))).
|
|
|
|
DefaultHandler(named("DeleteObject", h.DeleteObjectHandler)))
|
|
|
|
})
|
2020-07-22 13:02:32 +00:00
|
|
|
|
2023-07-19 14:55:00 +00:00
|
|
|
attachErrorHandler(objRouter)
|
|
|
|
|
2023-07-05 14:05:45 +00:00
|
|
|
return objRouter
|
2020-07-22 13:02:32 +00:00
|
|
|
}
|