2015-06-30 17:42:29 -04:00
|
|
|
/*
|
|
|
|
* Minimalist Object 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 api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
// MinioAPI -
|
|
|
|
type MinioAPI struct{}
|
|
|
|
|
|
|
|
func (api MinioAPI) isValidOp(w http.ResponseWriter, req *http.Request, acceptsContentType contentType) bool {
|
2015-06-30 17:42:29 -04:00
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
log.Println(bucket)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
// ListMultipartUploadsHandler - GET Bucket (List Multipart uploads)
|
2015-06-30 17:42:29 -04:00
|
|
|
// -------------------------
|
|
|
|
// This operation lists in-progress multipart uploads. An in-progress
|
|
|
|
// multipart upload is a multipart upload that has been initiated,
|
|
|
|
// using the Initiate Multipart Upload request, but has not yet been completed or aborted.
|
|
|
|
// This operation returns at most 1,000 multipart uploads in the response.
|
|
|
|
//
|
2015-06-30 23:15:48 -04:00
|
|
|
func (api MinioAPI) ListMultipartUploadsHandler(w http.ResponseWriter, req *http.Request) {
|
2015-06-30 17:42:29 -04:00
|
|
|
acceptsContentType := getContentType(req)
|
|
|
|
log.Println(acceptsContentType)
|
|
|
|
|
|
|
|
resources := getBucketMultipartResources(req.URL.Query())
|
|
|
|
if resources.MaxUploads == 0 {
|
|
|
|
resources.MaxUploads = maxObjectList
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
log.Println(bucket)
|
|
|
|
}
|
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
// ListObjectsHandler - GET Bucket (List Objects)
|
2015-06-30 17:42:29 -04:00
|
|
|
// -------------------------
|
|
|
|
// This implementation of the GET operation returns some or all (up to 1000)
|
|
|
|
// of the objects in a bucket. You can use the request parameters as selection
|
|
|
|
// criteria to return a subset of the objects in a bucket.
|
|
|
|
//
|
2015-06-30 23:15:48 -04:00
|
|
|
func (api MinioAPI) ListObjectsHandler(w http.ResponseWriter, req *http.Request) {
|
2015-06-30 17:42:29 -04:00
|
|
|
acceptsContentType := getContentType(req)
|
|
|
|
// verify if bucket allows this operation
|
2015-06-30 23:15:48 -04:00
|
|
|
if !api.isValidOp(w, req, acceptsContentType) {
|
2015-06-30 17:42:29 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if isRequestUploads(req.URL.Query()) {
|
2015-06-30 23:15:48 -04:00
|
|
|
api.ListMultipartUploadsHandler(w, req)
|
2015-06-30 17:42:29 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resources := getBucketResources(req.URL.Query())
|
|
|
|
if resources.Maxkeys == 0 {
|
|
|
|
resources.Maxkeys = maxObjectList
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
log.Println(bucket)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
// ListBucketsHandler - GET Service
|
2015-06-30 17:42:29 -04:00
|
|
|
// -----------
|
|
|
|
// This implementation of the GET operation returns a list of all buckets
|
|
|
|
// owned by the authenticated sender of the request.
|
2015-06-30 23:15:48 -04:00
|
|
|
func (api MinioAPI) ListBucketsHandler(w http.ResponseWriter, req *http.Request) {
|
2015-06-30 17:42:29 -04:00
|
|
|
acceptsContentType := getContentType(req)
|
|
|
|
// uncomment this when we have webcli
|
|
|
|
// without access key credentials one cannot list buckets
|
|
|
|
// if _, err := stripAuth(req); err != nil {
|
|
|
|
// writeErrorResponse(w, req, AccessDenied, acceptsContentType, req.URL.Path)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
log.Println(acceptsContentType)
|
|
|
|
}
|
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
// PutBucketHandler - PUT Bucket
|
2015-06-30 17:42:29 -04:00
|
|
|
// ----------
|
|
|
|
// This implementation of the PUT operation creates a new bucket for authenticated request
|
2015-06-30 23:15:48 -04:00
|
|
|
func (api MinioAPI) PutBucketHandler(w http.ResponseWriter, req *http.Request) {
|
2015-06-30 17:42:29 -04:00
|
|
|
acceptsContentType := getContentType(req)
|
|
|
|
// uncomment this when we have webcli
|
|
|
|
// without access key credentials one cannot create a bucket
|
|
|
|
// if _, err := stripAuth(req); err != nil {
|
|
|
|
// writeErrorResponse(w, req, AccessDenied, acceptsContentType, req.URL.Path)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
if isRequestBucketACL(req.URL.Query()) {
|
2015-06-30 23:15:48 -04:00
|
|
|
api.PutBucketACLHandler(w, req)
|
2015-06-30 17:42:29 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
// read from 'x-amz-acl'
|
|
|
|
aclType := getACLType(req)
|
|
|
|
if aclType == unsupportedACLType {
|
|
|
|
writeErrorResponse(w, req, NotImplemented, acceptsContentType, req.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
log.Println(bucket)
|
|
|
|
}
|
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
// PutBucketACLHandler - PUT Bucket ACL
|
2015-06-30 17:42:29 -04:00
|
|
|
// ----------
|
|
|
|
// This implementation of the PUT operation modifies the bucketACL for authenticated request
|
2015-06-30 23:15:48 -04:00
|
|
|
func (api MinioAPI) PutBucketACLHandler(w http.ResponseWriter, req *http.Request) {
|
2015-06-30 17:42:29 -04:00
|
|
|
acceptsContentType := getContentType(req)
|
|
|
|
// read from 'x-amz-acl'
|
|
|
|
aclType := getACLType(req)
|
|
|
|
if aclType == unsupportedACLType {
|
|
|
|
writeErrorResponse(w, req, NotImplemented, acceptsContentType, req.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
log.Println(bucket)
|
|
|
|
}
|
|
|
|
|
2015-06-30 23:15:48 -04:00
|
|
|
// HeadBucketHandler - HEAD Bucket
|
2015-06-30 17:42:29 -04:00
|
|
|
// ----------
|
|
|
|
// This operation is useful to determine if a bucket exists.
|
|
|
|
// The operation returns a 200 OK if the bucket exists and you
|
|
|
|
// have permission to access it. Otherwise, the operation might
|
|
|
|
// return responses such as 404 Not Found and 403 Forbidden.
|
2015-06-30 23:15:48 -04:00
|
|
|
func (api MinioAPI) HeadBucketHandler(w http.ResponseWriter, req *http.Request) {
|
2015-06-30 17:42:29 -04:00
|
|
|
acceptsContentType := getContentType(req)
|
|
|
|
log.Println(acceptsContentType)
|
|
|
|
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
log.Println(bucket)
|
|
|
|
}
|