2015-02-15 20:03:27 -05:00
|
|
|
/*
|
2015-03-19 17:35:50 -04:00
|
|
|
* Minimalist Object Storage, (C) 2014 Minio, Inc.
|
2015-02-15 20:03:27 -05: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-03-18 20:49:33 -04:00
|
|
|
package api
|
2015-02-15 20:03:27 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2015-03-19 01:49:02 -04:00
|
|
|
router "github.com/gorilla/mux"
|
2015-05-11 19:23:10 -04:00
|
|
|
"github.com/minio/minio/pkg/api/logging"
|
|
|
|
"github.com/minio/minio/pkg/api/quota"
|
|
|
|
"github.com/minio/minio/pkg/storage/drivers"
|
2015-02-15 20:03:27 -05:00
|
|
|
)
|
|
|
|
|
2015-03-06 00:07:19 -05:00
|
|
|
type minioAPI struct {
|
2015-03-23 23:40:21 -04:00
|
|
|
driver drivers.Driver
|
2015-02-15 20:03:27 -05:00
|
|
|
}
|
|
|
|
|
2015-06-06 17:22:51 -04:00
|
|
|
// Config api configurable parameters
|
|
|
|
type Config struct {
|
2015-06-06 20:01:39 -04:00
|
|
|
RateLimit int
|
|
|
|
driver drivers.Driver
|
2015-06-06 17:22:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetDriver - get a an existing set driver
|
|
|
|
func (c Config) GetDriver() drivers.Driver {
|
|
|
|
return c.driver
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetDriver - set a new driver
|
|
|
|
func (c *Config) SetDriver(driver drivers.Driver) {
|
|
|
|
c.driver = driver
|
|
|
|
}
|
|
|
|
|
2015-05-07 03:14:58 -04:00
|
|
|
// HTTPHandler - http wrapper handler
|
2015-06-06 17:22:51 -04:00
|
|
|
func HTTPHandler(config Config) http.Handler {
|
2015-05-07 03:14:58 -04:00
|
|
|
var mux *router.Router
|
|
|
|
var api = minioAPI{}
|
2015-06-06 17:22:51 -04:00
|
|
|
api.driver = config.GetDriver()
|
2015-05-07 03:14:58 -04:00
|
|
|
|
|
|
|
mux = router.NewRouter()
|
2015-02-23 05:11:27 -05:00
|
|
|
mux.HandleFunc("/", api.listBucketsHandler).Methods("GET")
|
|
|
|
mux.HandleFunc("/{bucket}", api.listObjectsHandler).Methods("GET")
|
|
|
|
mux.HandleFunc("/{bucket}", api.putBucketHandler).Methods("PUT")
|
2015-04-07 03:44:01 -04:00
|
|
|
mux.HandleFunc("/{bucket}", api.headBucketHandler).Methods("HEAD")
|
2015-02-23 05:11:27 -05:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD")
|
2015-06-03 21:27:13 -04:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectPartHandler).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}").Methods("PUT")
|
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.listObjectPartsHandler).Queries("uploadId", "{uploadId:.*}").Methods("GET")
|
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.completeMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}").Methods("POST")
|
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.newMultipartUploadHandler).Methods("POST")
|
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.abortMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}").Methods("DELETE")
|
2015-05-09 14:41:26 -04:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET")
|
2015-02-23 05:11:27 -05:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
|
|
|
|
|
2015-06-08 14:06:06 -04:00
|
|
|
// not implemented yet
|
|
|
|
mux.HandleFunc("/{bucket}", api.deleteBucketHandler).Methods("DELETE")
|
|
|
|
|
|
|
|
// unsupported API
|
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.deleteObjectHandler).Methods("DELETE")
|
|
|
|
|
2015-06-06 17:22:51 -04:00
|
|
|
handler := validContentTypeHandler(mux)
|
|
|
|
handler = timeValidityHandler(handler)
|
|
|
|
handler = ignoreResourcesHandler(handler)
|
|
|
|
handler = validateAuthHeaderHandler(handler)
|
2015-06-06 20:01:39 -04:00
|
|
|
// handler = quota.BandwidthCap(h, 25*1024*1024, time.Duration(30*time.Minute))
|
|
|
|
// handler = quota.BandwidthCap(h, 100*1024*1024, time.Duration(24*time.Hour))
|
|
|
|
// handler = quota.RequestLimit(h, 100, time.Duration(30*time.Minute))
|
|
|
|
// handler = quota.RequestLimit(h, 1000, time.Duration(24*time.Hour))
|
|
|
|
// handler = quota.ConnectionLimit(handler, config.ConnectionLimit)
|
|
|
|
handler = quota.RateLimit(handler, config.RateLimit)
|
2015-06-06 17:22:51 -04:00
|
|
|
handler = logging.LogHandler(handler)
|
|
|
|
return handler
|
2015-02-15 20:03:27 -05:00
|
|
|
}
|