2016-03-27 15:37:21 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* 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"
|
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
|
2016-03-27 15:37:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// registerAPIRouter - registers S3 compatible APIs.
|
2019-01-05 17:16:43 -05:00
|
|
|
func registerAPIRouter(router *mux.Router, encryptionEnabled 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
|
|
|
|
},
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|
|
|
|
|
2016-03-27 15:37:21 -04:00
|
|
|
// API Router
|
2018-04-21 22:23:54 -04:00
|
|
|
apiRouter := router.PathPrefix("/").Subrouter()
|
|
|
|
var routers []*mux.Router
|
2019-02-22 22:18:01 -05:00
|
|
|
for _, domainName := range globalDomainNames {
|
|
|
|
routers = append(routers, apiRouter.Host("{bucket:.+}."+domainName).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
|
|
|
|
bucket.Methods("HEAD").Path("/{object:.+}").HandlerFunc(httpTraceAll(api.HeadObjectHandler))
|
|
|
|
// CopyObjectPart
|
|
|
|
bucket.Methods("PUT").Path("/{object:.+}").HeadersRegexp("X-Amz-Copy-Source", ".*?(\\/|%2F).*?").HandlerFunc(httpTraceAll(api.CopyObjectPartHandler)).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}")
|
|
|
|
// PutObjectPart
|
|
|
|
bucket.Methods("PUT").Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.PutObjectPartHandler)).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}")
|
|
|
|
// ListObjectPxarts
|
|
|
|
bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(httpTraceAll(api.ListObjectPartsHandler)).Queries("uploadId", "{uploadId:.*}")
|
|
|
|
// CompleteMultipartUpload
|
|
|
|
bucket.Methods("POST").Path("/{object:.+}").HandlerFunc(httpTraceAll(api.CompleteMultipartUploadHandler)).Queries("uploadId", "{uploadId:.*}")
|
|
|
|
// NewMultipartUpload
|
|
|
|
bucket.Methods("POST").Path("/{object:.+}").HandlerFunc(httpTraceAll(api.NewMultipartUploadHandler)).Queries("uploads", "")
|
|
|
|
// AbortMultipartUpload
|
|
|
|
bucket.Methods("DELETE").Path("/{object:.+}").HandlerFunc(httpTraceAll(api.AbortMultipartUploadHandler)).Queries("uploadId", "{uploadId:.*}")
|
2018-05-31 22:43:50 -04:00
|
|
|
// GetObjectACL - this is a dummy call.
|
|
|
|
bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.GetObjectACLHandler)).Queries("acl", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetObjectTagging - this is a dummy call.
|
|
|
|
bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.GetObjectTaggingHandler)).Queries("tagging", "")
|
2018-08-15 06:30:19 -04:00
|
|
|
// SelectObjectContent
|
|
|
|
bucket.Methods("POST").Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.SelectObjectContentHandler)).Queries("select", "").Queries("select-type", "2")
|
2017-11-14 19:56:24 -05:00
|
|
|
// GetObject
|
|
|
|
bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.GetObjectHandler))
|
|
|
|
// CopyObject
|
|
|
|
bucket.Methods("PUT").Path("/{object:.+}").HeadersRegexp("X-Amz-Copy-Source", ".*?(\\/|%2F).*?").HandlerFunc(httpTraceAll(api.CopyObjectHandler))
|
|
|
|
// PutObject
|
|
|
|
bucket.Methods("PUT").Path("/{object:.+}").HandlerFunc(httpTraceHdrs(api.PutObjectHandler))
|
|
|
|
// DeleteObject
|
|
|
|
bucket.Methods("DELETE").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
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketLocationHandler)).Queries("location", "")
|
|
|
|
// GetBucketPolicy
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketPolicyHandler)).Queries("policy", "")
|
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.
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketACLHandler)).Queries("acl", "")
|
2019-02-08 19:18:13 -05:00
|
|
|
// GetBucketCors - this is a dummy call.
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketCorsHandler)).Queries("cors", "")
|
|
|
|
// GetBucketWebsiteHandler - this is a dummy call.
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketWebsiteHandler)).Queries("website", "")
|
|
|
|
// GetBucketVersioningHandler - this is a dummy call.
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketVersioningHandler)).Queries("versioning", "")
|
|
|
|
// GetBucketAccelerateHandler - this is a dummy call.
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketAccelerateHandler)).Queries("accelerate", "")
|
|
|
|
// GetBucketRequestPaymentHandler - this is a dummy call.
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketRequestPaymentHandler)).Queries("requestPayment", "")
|
|
|
|
// GetBucketLoggingHandler - this is a dummy call.
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketLoggingHandler)).Queries("logging", "")
|
|
|
|
// GetBucketLifecycleHandler - this is a dummy call.
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketLifecycleHandler)).Queries("lifecycle", "")
|
|
|
|
// GetBucketReplicationHandler - this is a dummy call.
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketReplicationHandler)).Queries("replication", "")
|
|
|
|
// GetBucketTaggingHandler - this is a dummy call.
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketTaggingHandler)).Queries("tagging", "")
|
|
|
|
//DeleteBucketWebsiteHandler
|
|
|
|
bucket.Methods("DELETE").HandlerFunc(httpTraceAll(api.DeleteBucketWebsiteHandler)).Queries("website", "")
|
|
|
|
// DeleteBucketTaggingHandler
|
|
|
|
bucket.Methods("DELETE").HandlerFunc(httpTraceAll(api.DeleteBucketTaggingHandler)).Queries("tagging", "")
|
2018-05-10 00:02:26 -04:00
|
|
|
|
2017-11-14 19:56:24 -05:00
|
|
|
// GetBucketNotification
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.GetBucketNotificationHandler)).Queries("notification", "")
|
|
|
|
// ListenBucketNotification
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.ListenBucketNotificationHandler)).Queries("events", "{events:.*}")
|
|
|
|
// ListMultipartUploads
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.ListMultipartUploadsHandler)).Queries("uploads", "")
|
|
|
|
// ListObjectsV2
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.ListObjectsV2Handler)).Queries("list-type", "2")
|
|
|
|
// ListObjectsV1 (Legacy)
|
|
|
|
bucket.Methods("GET").HandlerFunc(httpTraceAll(api.ListObjectsV1Handler))
|
|
|
|
// PutBucketPolicy
|
|
|
|
bucket.Methods("PUT").HandlerFunc(httpTraceAll(api.PutBucketPolicyHandler)).Queries("policy", "")
|
|
|
|
// PutBucketNotification
|
|
|
|
bucket.Methods("PUT").HandlerFunc(httpTraceAll(api.PutBucketNotificationHandler)).Queries("notification", "")
|
|
|
|
// PutBucket
|
|
|
|
bucket.Methods("PUT").HandlerFunc(httpTraceAll(api.PutBucketHandler))
|
|
|
|
// HeadBucket
|
|
|
|
bucket.Methods("HEAD").HandlerFunc(httpTraceAll(api.HeadBucketHandler))
|
|
|
|
// PostPolicy
|
2018-07-20 10:37:46 -04:00
|
|
|
bucket.Methods("POST").HeadersRegexp("Content-Type", "multipart/form-data*").HandlerFunc(httpTraceHdrs(api.PostPolicyBucketHandler))
|
2017-11-14 19:56:24 -05:00
|
|
|
// DeleteMultipleObjects
|
|
|
|
bucket.Methods("POST").HandlerFunc(httpTraceAll(api.DeleteMultipleObjectsHandler)).Queries("delete", "")
|
|
|
|
// DeleteBucketPolicy
|
|
|
|
bucket.Methods("DELETE").HandlerFunc(httpTraceAll(api.DeleteBucketPolicyHandler)).Queries("policy", "")
|
|
|
|
// DeleteBucket
|
|
|
|
bucket.Methods("DELETE").HandlerFunc(httpTraceAll(api.DeleteBucketHandler))
|
|
|
|
}
|
2016-03-27 15:37:21 -04:00
|
|
|
|
|
|
|
/// Root operation
|
|
|
|
|
|
|
|
// ListBuckets
|
2017-11-14 19:56:24 -05:00
|
|
|
apiRouter.Methods("GET").Path("/").HandlerFunc(httpTraceAll(api.ListBucketsHandler))
|
|
|
|
|
|
|
|
// If none of the routes match.
|
|
|
|
apiRouter.NotFoundHandler = http.HandlerFunc(httpTraceAll(notFoundHandler))
|
2016-03-27 15:37:21 -04:00
|
|
|
}
|