You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
4.5 KiB
134 lines
4.5 KiB
10 years ago
|
/*
|
||
9 years ago
|
* Minio Cloud Storage, (C) 2014 Minio, Inc.
|
||
10 years ago
|
*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
9 years ago
|
package main
|
||
10 years ago
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
9 years ago
|
router "github.com/gorilla/mux"
|
||
9 years ago
|
jsonrpc "github.com/gorilla/rpc/v2"
|
||
|
"github.com/gorilla/rpc/v2/json"
|
||
9 years ago
|
"github.com/minio/minio/pkg/donut"
|
||
10 years ago
|
)
|
||
|
|
||
10 years ago
|
// registerAPI - register all the object API handlers to their respective paths
|
||
9 years ago
|
func registerAPI(mux *router.Router, a API) {
|
||
10 years ago
|
mux.HandleFunc("/", a.ListBucketsHandler).Methods("GET")
|
||
9 years ago
|
mux.HandleFunc("/{bucket}", a.GetBucketACLHandler).Queries("acl", "").Methods("GET")
|
||
10 years ago
|
mux.HandleFunc("/{bucket}", a.ListObjectsHandler).Methods("GET")
|
||
9 years ago
|
mux.HandleFunc("/{bucket}", a.PutBucketACLHandler).Queries("acl", "").Methods("PUT")
|
||
10 years ago
|
mux.HandleFunc("/{bucket}", a.PutBucketHandler).Methods("PUT")
|
||
|
mux.HandleFunc("/{bucket}", a.HeadBucketHandler).Methods("HEAD")
|
||
9 years ago
|
mux.HandleFunc("/{bucket}", a.PostPolicyBucketHandler).Methods("POST")
|
||
10 years ago
|
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")
|
||
10 years ago
|
|
||
|
// not implemented yet
|
||
10 years ago
|
mux.HandleFunc("/{bucket}", a.DeleteBucketHandler).Methods("DELETE")
|
||
10 years ago
|
|
||
|
// unsupported API
|
||
10 years ago
|
mux.HandleFunc("/{bucket}/{object:.*}", a.DeleteObjectHandler).Methods("DELETE")
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
// APIOperation container for individual operations read by Ticket Master
|
||
|
type APIOperation struct {
|
||
|
ProceedCh chan struct{}
|
||
|
}
|
||
|
|
||
9 years ago
|
// API container for API and also carries OP (operation) channel
|
||
|
type API struct {
|
||
9 years ago
|
OP chan APIOperation
|
||
|
Donut donut.Interface
|
||
|
Anonymous bool // do not checking for incoming signatures, allow all requests
|
||
9 years ago
|
}
|
||
|
|
||
|
// getNewAPI instantiate a new minio API
|
||
9 years ago
|
func getNewAPI(anonymous bool) API {
|
||
9 years ago
|
// ignore errors for now
|
||
|
d, err := donut.New()
|
||
|
fatalIf(err.Trace(), "Instantiating donut failed.", nil)
|
||
|
|
||
9 years ago
|
return API{
|
||
9 years ago
|
OP: make(chan APIOperation),
|
||
|
Donut: d,
|
||
|
Anonymous: anonymous,
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
func getAPIHandler(anonymous bool, api API) http.Handler {
|
||
9 years ago
|
var mwHandlers = []MiddlewareHandler{
|
||
|
TimeValidityHandler,
|
||
|
IgnoreResourcesHandler,
|
||
|
CorsHandler,
|
||
9 years ago
|
}
|
||
9 years ago
|
if !anonymous {
|
||
|
mwHandlers = append(mwHandlers, SignatureHandler)
|
||
|
}
|
||
10 years ago
|
mux := router.NewRouter()
|
||
9 years ago
|
registerAPI(mux, api)
|
||
9 years ago
|
apiHandler := registerCustomMiddleware(mux, mwHandlers...)
|
||
9 years ago
|
return apiHandler
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
func getServerRPCHandler(anonymous bool) http.Handler {
|
||
|
var mwHandlers = []MiddlewareHandler{
|
||
|
TimeValidityHandler,
|
||
|
}
|
||
|
if !anonymous {
|
||
|
mwHandlers = append(mwHandlers, RPCSignatureHandler)
|
||
|
}
|
||
|
|
||
9 years ago
|
s := jsonrpc.NewServer()
|
||
|
s.RegisterCodec(json.NewCodec(), "application/json")
|
||
9 years ago
|
s.RegisterService(new(serverRPCService), "Server")
|
||
9 years ago
|
s.RegisterService(new(donutRPCService), "Donut")
|
||
9 years ago
|
mux := router.NewRouter()
|
||
|
mux.Handle("/rpc", s)
|
||
9 years ago
|
|
||
|
rpcHandler := registerCustomMiddleware(mux, mwHandlers...)
|
||
|
return rpcHandler
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
// getControllerRPCHandler rpc handler for controller
|
||
|
func getControllerRPCHandler(anonymous bool) http.Handler {
|
||
|
var mwHandlers = []MiddlewareHandler{
|
||
|
TimeValidityHandler,
|
||
|
}
|
||
|
if !anonymous {
|
||
|
mwHandlers = append(mwHandlers, RPCSignatureHandler)
|
||
|
}
|
||
|
|
||
|
s := jsonrpc.NewServer()
|
||
|
codec := json.NewCodec()
|
||
|
s.RegisterCodec(codec, "application/json")
|
||
|
s.RegisterCodec(codec, "application/json; charset=UTF-8")
|
||
|
s.RegisterService(new(controllerRPCService), "Controller")
|
||
|
mux := router.NewRouter()
|
||
|
// Add new RPC services here
|
||
|
mux.Handle("/rpc", s)
|
||
|
mux.Handle("/{file:.*}", http.FileServer(assetFS()))
|
||
|
|
||
|
rpcHandler := registerCustomMiddleware(mux, mwHandlers...)
|
||
|
return rpcHandler
|
||
|
}
|