2015-06-30 23:15:48 -04:00
|
|
|
/*
|
2015-07-24 20:51:40 -04:00
|
|
|
* Minio Cloud Storage, (C) 2014 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-09-19 04:30:09 -04:00
|
|
|
jsonrpc "github.com/gorilla/rpc/v2"
|
|
|
|
"github.com/gorilla/rpc/v2/json"
|
2015-06-30 23:15:48 -04:00
|
|
|
)
|
|
|
|
|
2015-07-01 03:37:43 -04:00
|
|
|
// registerAPI - register all the object API handlers to their respective paths
|
2015-09-19 03:52:01 -04:00
|
|
|
func registerAPI(mux *router.Router, a MinioAPI) {
|
2015-07-02 18:40:16 -04:00
|
|
|
mux.HandleFunc("/", a.ListBucketsHandler).Methods("GET")
|
|
|
|
mux.HandleFunc("/{bucket}", a.ListObjectsHandler).Methods("GET")
|
|
|
|
mux.HandleFunc("/{bucket}", a.PutBucketHandler).Methods("PUT")
|
|
|
|
mux.HandleFunc("/{bucket}", a.HeadBucketHandler).Methods("HEAD")
|
|
|
|
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")
|
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", a.NewMultipartUploadHandler).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")
|
2015-06-30 23:15:48 -04:00
|
|
|
|
|
|
|
// not implemented yet
|
2015-07-02 18:40:16 -04:00
|
|
|
mux.HandleFunc("/{bucket}", a.DeleteBucketHandler).Methods("DELETE")
|
2015-06-30 23:15:48 -04:00
|
|
|
|
|
|
|
// unsupported API
|
2015-07-02 18:40:16 -04:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", a.DeleteObjectHandler).Methods("DELETE")
|
2015-07-01 03:37:43 -04:00
|
|
|
}
|
|
|
|
|
2015-09-19 03:52:01 -04:00
|
|
|
func registerCustomMiddleware(mux *router.Router, mwHandlers ...MiddlewareHandler) http.Handler {
|
2015-07-01 03:37:43 -04:00
|
|
|
var f http.Handler
|
2015-09-15 19:59:43 -04:00
|
|
|
f = mux
|
|
|
|
for _, mw := range mwHandlers {
|
|
|
|
f = mw(f)
|
2015-07-01 03:37:43 -04:00
|
|
|
}
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
2015-09-15 19:59:43 -04:00
|
|
|
// getAPIHandler api handler
|
2015-09-19 03:52:01 -04:00
|
|
|
func getAPIHandler(conf APIConfig) (http.Handler, MinioAPI) {
|
|
|
|
var mwHandlers = []MiddlewareHandler{
|
|
|
|
ValidContentTypeHandler,
|
|
|
|
TimeValidityHandler,
|
|
|
|
IgnoreResourcesHandler,
|
|
|
|
ValidateAuthHeaderHandler,
|
2015-09-06 00:26:34 -04:00
|
|
|
// api.LoggingHandler, // Disabled logging until we bring in external logging support
|
2015-09-19 03:52:01 -04:00
|
|
|
CorsHandler,
|
2015-09-15 19:59:43 -04:00
|
|
|
}
|
2015-06-30 23:15:48 -04:00
|
|
|
|
|
|
|
mux := router.NewRouter()
|
2015-09-19 03:52:01 -04:00
|
|
|
minioAPI := NewAPI()
|
2015-09-15 19:59:43 -04:00
|
|
|
registerAPI(mux, minioAPI)
|
|
|
|
apiHandler := registerCustomMiddleware(mux, mwHandlers...)
|
2015-07-02 18:40:16 -04:00
|
|
|
return apiHandler, minioAPI
|
2015-06-30 23:15:48 -04:00
|
|
|
}
|
2015-09-19 04:30:09 -04:00
|
|
|
|
|
|
|
func getRPCServerHandler() http.Handler {
|
|
|
|
s := jsonrpc.NewServer()
|
|
|
|
s.RegisterCodec(json.NewCodec(), "application/json")
|
|
|
|
s.RegisterService(new(serverServerService), "Server")
|
|
|
|
mux := router.NewRouter()
|
|
|
|
mux.Handle("/rpc", s)
|
|
|
|
return mux
|
|
|
|
}
|