2015-06-30 23:15:48 -04:00
|
|
|
/*
|
2015-10-16 14:26:01 -04:00
|
|
|
* Minio Cloud Storage, (C) 2015 Minio, Inc.
|
2015-06-30 23:15:48 -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.
|
|
|
|
*/
|
|
|
|
|
2015-09-19 03:52:01 -04:00
|
|
|
package main
|
2015-06-30 23:15:48 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2015-08-22 21:34:00 -04:00
|
|
|
router "github.com/gorilla/mux"
|
2015-10-16 14:26:01 -04:00
|
|
|
"github.com/minio/minio/pkg/fs"
|
2015-06-30 23:15:48 -04:00
|
|
|
)
|
|
|
|
|
2015-10-19 15:15:19 -04:00
|
|
|
// CloudStorageAPI container for API and also carries OP (operation) channel
|
|
|
|
type CloudStorageAPI struct {
|
|
|
|
Filesystem fs.Filesystem
|
|
|
|
Anonymous bool // do not checking for incoming signatures, allow all requests
|
|
|
|
AccessLog bool // if true log all incoming request
|
|
|
|
}
|
|
|
|
|
2015-10-17 22:17:33 -04:00
|
|
|
// registerCloudStorageAPI - register all the handlers to their respective paths
|
|
|
|
func registerCloudStorageAPI(mux *router.Router, a CloudStorageAPI) {
|
2015-11-07 17:15:22 -05:00
|
|
|
// root Router
|
2015-10-25 11:00:39 -04:00
|
|
|
root := mux.NewRoute().PathPrefix("/").Subrouter()
|
2015-11-07 17:15:22 -05:00
|
|
|
// Bucket router
|
2015-10-25 11:00:39 -04:00
|
|
|
bucket := root.PathPrefix("/{bucket}").Subrouter()
|
2015-06-30 23:15:48 -04:00
|
|
|
|
2015-11-07 17:15:22 -05:00
|
|
|
// Object operations
|
2015-10-25 11:00:39 -04:00
|
|
|
bucket.Methods("HEAD").Path("/{object:.+}").HandlerFunc(a.HeadObjectHandler)
|
|
|
|
bucket.Methods("PUT").Path("/{object:.+}").HandlerFunc(a.PutObjectPartHandler).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}")
|
|
|
|
bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(a.ListObjectPartsHandler).Queries("uploadId", "{uploadId:.*}")
|
|
|
|
bucket.Methods("POST").Path("/{object:.+}").HandlerFunc(a.CompleteMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}")
|
|
|
|
bucket.Methods("POST").Path("/{object:.+}").HandlerFunc(a.NewMultipartUploadHandler).Queries("uploads", "")
|
|
|
|
bucket.Methods("DELETE").Path("/{object:.+}").HandlerFunc(a.AbortMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}")
|
|
|
|
bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(a.GetObjectHandler)
|
|
|
|
bucket.Methods("PUT").Path("/{object:.+}").HandlerFunc(a.PutObjectHandler)
|
|
|
|
bucket.Methods("DELETE").Path("/{object:.+}").HandlerFunc(a.DeleteObjectHandler)
|
|
|
|
|
2015-11-07 17:15:22 -05:00
|
|
|
// Bucket operations
|
2015-10-25 11:00:39 -04:00
|
|
|
bucket.Methods("GET").HandlerFunc(a.GetBucketACLHandler).Queries("acl", "")
|
|
|
|
bucket.Methods("GET").HandlerFunc(a.ListMultipartUploadsHandler).Queries("uploads", "")
|
|
|
|
bucket.Methods("GET").HandlerFunc(a.ListObjectsHandler)
|
|
|
|
bucket.Methods("PUT").HandlerFunc(a.PutBucketACLHandler).Queries("acl", "")
|
|
|
|
bucket.Methods("PUT").HandlerFunc(a.PutBucketHandler)
|
|
|
|
bucket.Methods("HEAD").HandlerFunc(a.HeadBucketHandler)
|
|
|
|
bucket.Methods("POST").HandlerFunc(a.PostPolicyBucketHandler)
|
|
|
|
bucket.Methods("DELETE").HandlerFunc(a.DeleteBucketHandler)
|
|
|
|
|
2015-11-07 17:15:22 -05:00
|
|
|
// Root operation
|
2015-10-25 11:00:39 -04:00
|
|
|
root.Methods("GET").HandlerFunc(a.ListBucketsHandler)
|
2015-07-01 03:37:43 -04:00
|
|
|
}
|
|
|
|
|
2015-10-17 22:17:33 -04:00
|
|
|
// getNewCloudStorageAPI instantiate a new CloudStorageAPI
|
2015-10-20 03:33:53 -04:00
|
|
|
func getNewCloudStorageAPI(conf cloudServerConfig) CloudStorageAPI {
|
2015-10-17 22:17:33 -04:00
|
|
|
fs, err := fs.New()
|
2015-11-07 17:15:22 -05:00
|
|
|
fatalIf(err.Trace(), "Initializing filesystem failed.", nil)
|
2015-09-19 05:36:50 -04:00
|
|
|
|
2015-10-17 22:17:33 -04:00
|
|
|
fs.SetRootPath(conf.Path)
|
|
|
|
fs.SetMinFreeDisk(conf.MinFreeDisk)
|
2015-10-18 17:47:56 -04:00
|
|
|
if conf.Expiry > 0 {
|
|
|
|
go fs.AutoExpiryThread(conf.Expiry)
|
|
|
|
}
|
2015-10-17 22:17:33 -04:00
|
|
|
return CloudStorageAPI{
|
2015-10-16 14:26:01 -04:00
|
|
|
Filesystem: fs,
|
2015-10-17 22:17:33 -04:00
|
|
|
Anonymous: conf.Anonymous,
|
2015-10-19 15:15:19 -04:00
|
|
|
AccessLog: conf.AccessLog,
|
2015-09-19 05:36:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-17 22:17:33 -04:00
|
|
|
func getCloudStorageAPIHandler(api CloudStorageAPI) http.Handler {
|
2015-09-19 03:52:01 -04:00
|
|
|
var mwHandlers = []MiddlewareHandler{
|
|
|
|
TimeValidityHandler,
|
|
|
|
IgnoreResourcesHandler,
|
|
|
|
CorsHandler,
|
2015-09-15 19:59:43 -04:00
|
|
|
}
|
2015-10-17 22:17:33 -04:00
|
|
|
if !api.Anonymous {
|
2015-10-07 02:32:20 -04:00
|
|
|
mwHandlers = append(mwHandlers, SignatureHandler)
|
|
|
|
}
|
2015-10-19 15:15:19 -04:00
|
|
|
if api.AccessLog {
|
|
|
|
mwHandlers = append(mwHandlers, AccessLogHandler)
|
|
|
|
}
|
2015-06-30 23:15:48 -04:00
|
|
|
mux := router.NewRouter()
|
2015-10-17 22:17:33 -04:00
|
|
|
registerCloudStorageAPI(mux, api)
|
|
|
|
return registerCustomMiddleware(mux, mwHandlers...)
|
2015-06-30 23:15:48 -04:00
|
|
|
}
|