minio/routers.go

89 lines
3.6 KiB
Go
Raw Normal View History

/*
* Minio Cloud Storage, (C) 2015 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.
*/
package main
import (
"net/http"
router "github.com/gorilla/mux"
"github.com/minio/minio/pkg/fs"
)
2015-10-19 21:15:19 +02: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-18 04:17:33 +02:00
// registerCloudStorageAPI - register all the handlers to their respective paths
func registerCloudStorageAPI(mux *router.Router, a CloudStorageAPI) {
mux.HandleFunc("/", a.ListBucketsHandler).Methods("GET")
2015-10-08 20:12:02 +02:00
mux.HandleFunc("/{bucket}", a.GetBucketACLHandler).Queries("acl", "").Methods("GET")
2015-10-17 04:09:35 +02:00
mux.HandleFunc("/{bucket}", a.ListMultipartUploadsHandler).Queries("uploads", "").Methods("GET")
mux.HandleFunc("/{bucket}", a.ListObjectsHandler).Methods("GET")
mux.HandleFunc("/{bucket}", a.PutBucketACLHandler).Queries("acl", "").Methods("PUT")
mux.HandleFunc("/{bucket}", a.PutBucketHandler).Methods("PUT")
mux.HandleFunc("/{bucket}", a.HeadBucketHandler).Methods("HEAD")
2015-10-02 08:51:17 +02:00
mux.HandleFunc("/{bucket}", a.PostPolicyBucketHandler).Methods("POST")
mux.HandleFunc("/{bucket}/{object:.*}", a.HeadObjectHandler).Methods("HEAD")
mux.HandleFunc("/{bucket}/{object:.*}", a.PutObjectPartHandler).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}").Methods("PUT")
mux.HandleFunc("/{bucket}/{object:.*}", a.ListObjectPartsHandler).Queries("uploadId", "{uploadId:.*}").Methods("GET")
mux.HandleFunc("/{bucket}/{object:.*}", a.CompleteMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}").Methods("POST")
2015-10-17 04:09:35 +02:00
mux.HandleFunc("/{bucket}/{object:.*}", a.NewMultipartUploadHandler).Queries("uploads", "").Methods("POST")
mux.HandleFunc("/{bucket}/{object:.*}", a.AbortMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}").Methods("DELETE")
mux.HandleFunc("/{bucket}/{object:.*}", a.GetObjectHandler).Methods("GET")
mux.HandleFunc("/{bucket}/{object:.*}", a.PutObjectHandler).Methods("PUT")
mux.HandleFunc("/{bucket}", a.DeleteBucketHandler).Methods("DELETE")
mux.HandleFunc("/{bucket}/{object:.*}", a.DeleteObjectHandler).Methods("DELETE")
}
2015-10-18 04:17:33 +02:00
// getNewCloudStorageAPI instantiate a new CloudStorageAPI
func getNewCloudStorageAPI(conf serverConfig) CloudStorageAPI {
fs, err := fs.New()
fatalIf(err.Trace(), "Instantiating filesystem failed.", nil)
2015-10-18 04:17:33 +02:00
fs.SetRootPath(conf.Path)
fs.SetMinFreeDisk(conf.MinFreeDisk)
if conf.Expiry > 0 {
go fs.AutoExpiryThread(conf.Expiry)
}
2015-10-18 04:17:33 +02:00
return CloudStorageAPI{
Filesystem: fs,
2015-10-18 04:17:33 +02:00
Anonymous: conf.Anonymous,
2015-10-19 21:15:19 +02:00
AccessLog: conf.AccessLog,
}
}
2015-10-18 04:17:33 +02:00
func getCloudStorageAPIHandler(api CloudStorageAPI) http.Handler {
var mwHandlers = []MiddlewareHandler{
TimeValidityHandler,
IgnoreResourcesHandler,
CorsHandler,
}
2015-10-18 04:17:33 +02:00
if !api.Anonymous {
mwHandlers = append(mwHandlers, SignatureHandler)
}
2015-10-19 21:15:19 +02:00
if api.AccessLog {
mwHandlers = append(mwHandlers, AccessLogHandler)
}
mux := router.NewRouter()
2015-10-18 04:17:33 +02:00
registerCloudStorageAPI(mux, api)
return registerCustomMiddleware(mux, mwHandlers...)
}