2016-03-27 15:37:21 -04:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2016 MinIO, Inc.
|
2016-03-27 15:37:21 -04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-03-27 15:37:21 -04:00
|
|
|
|
2018-03-28 17:14:06 -04:00
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-04-21 22:23:54 -04:00
|
|
|
"github.com/gorilla/mux"
|
2019-07-03 01:34:32 -04:00
|
|
|
xhttp "github.com/minio/minio/cmd/http"
|
2018-03-28 17:14:06 -04:00
|
|
|
)
|
2016-03-27 15:37:21 -04:00
|
|
|
|
2016-04-12 15:45:15 -04:00
|
|
|
// objectAPIHandler implements and provides http handlers for S3 API.
|
|
|
|
type objectAPIHandlers struct {
|
2016-07-31 17:11:14 -04:00
|
|
|
ObjectAPI func() ObjectLayer
|
2018-03-28 17:14:06 -04:00
|
|
|
CacheAPI func() CacheObjectLayer
|
2019-01-05 17:16:43 -05:00
|
|
|
// Returns true of handlers should interpret encryption.
|
|
|
|
EncryptionEnabled func() bool
|
2019-06-19 20:37:08 -04:00
|
|
|
// Returns true if handlers allow SSE-KMS encryption headers.
|
|
|
|
AllowSSEKMS func() bool
|
2016-03-27 15:37:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// registerAPIRouter - registers S3 compatible APIs.
|
2019-06-19 20:37:08 -04:00
|
|
|
func registerAPIRouter(router *mux.Router, encryptionEnabled, allowSSEKMS bool) {
|
2016-10-05 15:48:07 -04:00
|
|
|
// Initialize API.
|
|
|
|
api := objectAPIHandlers{
|
|
|
|
ObjectAPI: newObjectLayerFn,
|
2018-03-28 17:14:06 -04:00
|
|
|
CacheAPI: newCacheObjectsFn,
|
2019-01-05 17:16:43 -05:00
|
|
|
EncryptionEnabled: func() bool {
|
|
|
|
return encryptionEnabled
|
|
|
|
},
|
2019-06-19 20:37:08 -04:00
|
|
|
AllowSSEKMS: func() bool {
|
|
|
|
return allowSSEKMS
|
|
|
|
},
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|
|
|
|
|
2016-03-27 15:37:21 -04:00
|
|
|
// API Router
|
2019-08-06 15:08:58 -04:00
|
|
|
apiRouter := router.PathPrefix(SlashSeparator).Subrouter()
|
2018-04-21 22:23:54 -04:00
|
|
|
var routers []*mux.Router
|
2019-02-22 22:18:01 -05:00
|
|
|
for _, domainName := range globalDomainNames {
|
2019-05-07 13:36:00 -04:00
|
|
|
routers = append(routers, apiRouter.Host("{bucket:.+}."+domainName).Subrouter())
|
|
|
|
routers = append(routers, apiRouter.Host("{bucket:.+}."+domainName+":{port:.*}").Subrouter())
|
2017-11-14 19:56:24 -05:00
|
|
|
}
|
|
|
|
routers = append(routers, apiRouter.PathPrefix("/{bucket}").Subrouter())
|
2016-03-27 15:37:21 -04:00
|
|
|
|
2017-11-14 19:56:24 -05:00
|
|
|
for _, bucket := range routers {
|
|
|
|
// Object operations
|
|
|
|
// HeadObject
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodHead).Path("/{object:.+}").HandlerFunc(httpTraceAll(api.HeadObjectHandler))
|
2017-11-14 19:56:24 -05:00
|
|
|
// CopyObjectPart
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HeadersRegexp(xhttp.AmzCopySource, ".*?(\\/|%2F).*?").HandlerFunc(httpTraceAll(api.CopyObjectPartHandler)).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}")
|
2017-11-14 19:56:24 -05:00
|
|
|
// PutObjectPart
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.PutObjectPartHandler)).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}")
|
2017-11-14 19:56:24 -05:00
|
|
|
// ListObjectPxarts
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(httpTraceAll(api.ListObjectPartsHandler)).Queries("uploadId", "{uploadId:.*}")
|
2017-11-14 19:56:24 -05:00
|
|
|
// CompleteMultipartUpload
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc(httpTraceAll(api.CompleteMultipartUploadHandler)).Queries("uploadId", "{uploadId:.*}")
|
2017-11-14 19:56:24 -05:00
|
|
|
// NewMultipartUpload
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc(httpTraceAll(api.NewMultipartUploadHandler)).Queries("uploads", "")
|
2017-11-14 19:56:24 -05:00
|
|
|
// AbortMultipartUpload
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodDelete).Path("/{object:.+}").HandlerFunc(httpTraceAll(api.AbortMultipartUploadHandler)).Queries("uploadId", "{uploadId:.*}")
|
2018-05-31 22:43:50 -04:00
|
|
|
// GetObjectACL - this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.GetObjectACLHandler)).Queries("acl", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetObjectTagging - this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.GetObjectTaggingHandler)).Queries("tagging", "")
|
2018-08-15 06:30:19 -04:00
|
|
|
// SelectObjectContent
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.SelectObjectContentHandler)).Queries("select", "").Queries("select-type", "2")
|
2017-11-14 19:56:24 -05:00
|
|
|
// GetObject
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.GetObjectHandler))
|
2017-11-14 19:56:24 -05:00
|
|
|
// CopyObject
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HeadersRegexp(xhttp.AmzCopySource, ".*?(\\/|%2F).*?").HandlerFunc(httpTraceAll(api.CopyObjectHandler))
|
2017-11-14 19:56:24 -05:00
|
|
|
// PutObject
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.PutObjectHandler))
|
2017-11-14 19:56:24 -05:00
|
|
|
// DeleteObject
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodDelete).Path("/{object:.+}").HandlerFunc(httpTraceAll(api.DeleteObjectHandler))
|
2016-03-27 15:37:21 -04:00
|
|
|
|
2017-11-14 19:56:24 -05:00
|
|
|
/// Bucket operations
|
|
|
|
// GetBucketLocation
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketLocationHandler)).Queries("location", "")
|
2017-11-14 19:56:24 -05:00
|
|
|
// GetBucketPolicy
|
2019-07-19 16:20:33 -04:00
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketPolicyHandler)).Queries("policy", "")
|
|
|
|
// GetBucketLifecycle
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketLifecycleHandler)).Queries("lifecycle", "")
|
2018-05-10 00:02:26 -04:00
|
|
|
|
2019-02-08 19:18:13 -05:00
|
|
|
// Dummy Bucket Calls
|
2018-05-10 00:02:26 -04:00
|
|
|
// GetBucketACL -- this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketACLHandler)).Queries("acl", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetBucketCors - this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketCorsHandler)).Queries("cors", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetBucketWebsiteHandler - this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketWebsiteHandler)).Queries("website", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetBucketVersioningHandler - this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketVersioningHandler)).Queries("versioning", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetBucketAccelerateHandler - this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketAccelerateHandler)).Queries("accelerate", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetBucketRequestPaymentHandler - this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketRequestPaymentHandler)).Queries("requestPayment", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetBucketLoggingHandler - this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketLoggingHandler)).Queries("logging", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetBucketLifecycleHandler - this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketLifecycleHandler)).Queries("lifecycle", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetBucketReplicationHandler - this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketReplicationHandler)).Queries("replication", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetBucketTaggingHandler - this is a dummy call.
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketTaggingHandler)).Queries("tagging", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
//DeleteBucketWebsiteHandler
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodDelete).HandlerFunc(httpTraceAll(api.DeleteBucketWebsiteHandler)).Queries("website", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// DeleteBucketTaggingHandler
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodDelete).HandlerFunc(httpTraceAll(api.DeleteBucketTaggingHandler)).Queries("tagging", "")
|
2018-05-10 00:02:26 -04:00
|
|
|
|
2017-11-14 19:56:24 -05:00
|
|
|
// GetBucketNotification
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.GetBucketNotificationHandler)).Queries("notification", "")
|
2017-11-14 19:56:24 -05:00
|
|
|
// ListenBucketNotification
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.ListenBucketNotificationHandler)).Queries("events", "{events:.*}")
|
2017-11-14 19:56:24 -05:00
|
|
|
// ListMultipartUploads
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.ListMultipartUploadsHandler)).Queries("uploads", "")
|
2017-11-14 19:56:24 -05:00
|
|
|
// ListObjectsV2
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodGet).HandlerFunc(httpTraceAll(api.ListObjectsV2Handler)).Queries("list-type", "2")
|
2017-11-14 19:56:24 -05:00
|
|
|
// ListObjectsV1 (Legacy)
|
2019-07-19 16:20:33 -04:00
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.ListObjectsV1Handler))
|
|
|
|
// PutBucketLifecycle
|
|
|
|
bucket.Methods("PUT").HandlerFunc(httpTraceAll(api.PutBucketLifecycleHandler)).Queries("lifecycle", "")
|
2017-11-14 19:56:24 -05:00
|
|
|
// PutBucketPolicy
|
2019-07-19 16:20:33 -04:00
|
|
|
bucket.Methods("PUT").HandlerFunc(httpTraceAll(api.PutBucketPolicyHandler)).Queries("policy", "")
|
|
|
|
|
2017-11-14 19:56:24 -05:00
|
|
|
// PutBucketNotification
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodPut).HandlerFunc(httpTraceAll(api.PutBucketNotificationHandler)).Queries("notification", "")
|
2017-11-14 19:56:24 -05:00
|
|
|
// PutBucket
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodPut).HandlerFunc(httpTraceAll(api.PutBucketHandler))
|
2017-11-14 19:56:24 -05:00
|
|
|
// HeadBucket
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodHead).HandlerFunc(httpTraceAll(api.HeadBucketHandler))
|
2017-11-14 19:56:24 -05:00
|
|
|
// PostPolicy
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodPost).HeadersRegexp(xhttp.ContentType, "multipart/form-data*").HandlerFunc(httpTraceHdrs(api.PostPolicyBucketHandler))
|
2017-11-14 19:56:24 -05:00
|
|
|
// DeleteMultipleObjects
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodPost).HandlerFunc(httpTraceAll(api.DeleteMultipleObjectsHandler)).Queries("delete", "")
|
2017-11-14 19:56:24 -05:00
|
|
|
// DeleteBucketPolicy
|
2019-07-19 16:20:33 -04:00
|
|
|
bucket.Methods("DELETE").HandlerFunc(httpTraceAll(api.DeleteBucketPolicyHandler)).Queries("policy", "")
|
|
|
|
// DeleteBucketLifecycle
|
|
|
|
bucket.Methods("DELETE").HandlerFunc(httpTraceAll(api.DeleteBucketLifecycleHandler)).Queries("lifecycle", "")
|
2017-11-14 19:56:24 -05:00
|
|
|
// DeleteBucket
|
2019-07-03 01:34:32 -04:00
|
|
|
bucket.Methods(http.MethodDelete).HandlerFunc(httpTraceAll(api.DeleteBucketHandler))
|
2017-11-14 19:56:24 -05:00
|
|
|
}
|
2016-03-27 15:37:21 -04:00
|
|
|
|
|
|
|
/// Root operation
|
|
|
|
|
|
|
|
// ListBuckets
|
2019-08-06 15:08:58 -04:00
|
|
|
apiRouter.Methods(http.MethodGet).Path(SlashSeparator).HandlerFunc(httpTraceAll(api.ListBucketsHandler))
|
2017-11-14 19:56:24 -05:00
|
|
|
|
|
|
|
// If none of the routes match.
|
|
|
|
apiRouter.NotFoundHandler = http.HandlerFunc(httpTraceAll(notFoundHandler))
|
2016-03-27 15:37:21 -04:00
|
|
|
}
|