2015-06-30 17:42:29 -04:00
|
|
|
/*
|
2015-07-24 20:51:40 -04:00
|
|
|
* Minio Cloud Storage, (C) 2015 Minio, Inc.
|
2015-06-30 17:42:29 -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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2015-08-22 21:34:00 -04:00
|
|
|
"github.com/gorilla/mux"
|
2015-07-03 03:29:54 -04:00
|
|
|
"github.com/minio/minio/pkg/donut"
|
2015-08-03 19:17:21 -04:00
|
|
|
"github.com/minio/minio/pkg/probe"
|
2015-07-02 23:31:22 -04:00
|
|
|
"github.com/minio/minio/pkg/utils/log"
|
2015-06-30 17:42:29 -04:00
|
|
|
)
|
|
|
|
|
2015-07-02 18:40:16 -04:00
|
|
|
func (api Minio) 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"]
|
2015-07-02 23:31:22 -04:00
|
|
|
|
2015-07-09 22:34:07 -04:00
|
|
|
bucketMetadata, err := api.Donut.GetBucketMetadata(bucket, nil)
|
2015-08-03 19:17:21 -04:00
|
|
|
if err == nil {
|
2015-07-09 17:42:04 -04:00
|
|
|
if _, err := StripAccessKeyID(req.Header.Get("Authorization")); err != nil {
|
2015-07-02 23:31:22 -04:00
|
|
|
if bucketMetadata.ACL.IsPrivate() {
|
|
|
|
return true
|
|
|
|
//uncomment this when we have webcli
|
|
|
|
//writeErrorResponse(w, req, AccessDenied, acceptsContentType, req.URL.Path)
|
|
|
|
//return false
|
|
|
|
}
|
|
|
|
if bucketMetadata.ACL.IsPublicRead() && req.Method == "PUT" {
|
|
|
|
return true
|
|
|
|
//uncomment this when we have webcli
|
|
|
|
//writeErrorResponse(w, req, AccessDenied, acceptsContentType, req.URL.Path)
|
|
|
|
//return false
|
|
|
|
}
|
|
|
|
}
|
2015-08-03 19:17:21 -04:00
|
|
|
return true
|
|
|
|
}
|
2015-08-18 22:30:17 -04:00
|
|
|
switch err.ToGoError().(type) {
|
2015-08-03 19:17:21 -04:00
|
|
|
case donut.BucketNotFound:
|
|
|
|
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
|
|
|
|
return false
|
|
|
|
case donut.BucketNameInvalid:
|
|
|
|
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
|
|
|
return false
|
2015-07-02 23:31:22 -04:00
|
|
|
default:
|
2015-08-03 19:17:21 -04:00
|
|
|
log.Error.Println(err.Trace())
|
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
|
|
|
return false
|
2015-07-02 23:31:22 -04:00
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|
|
|
|
|
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-07-02 18:40:16 -04:00
|
|
|
func (api Minio) ListMultipartUploadsHandler(w http.ResponseWriter, req *http.Request) {
|
2015-07-02 23:31:22 -04:00
|
|
|
// Ticket master block
|
2015-07-02 18:40:16 -04:00
|
|
|
{
|
2015-07-02 23:31:22 -04:00
|
|
|
op := Operation{}
|
|
|
|
op.ProceedCh = make(chan struct{})
|
|
|
|
api.OP <- op
|
|
|
|
// block until ticket master gives us a go
|
|
|
|
<-op.ProceedCh
|
2015-07-02 18:40:16 -04:00
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
|
2015-07-02 23:31:22 -04:00
|
|
|
acceptsContentType := getContentType(req)
|
2015-07-03 03:29:54 -04:00
|
|
|
if !api.isValidOp(w, req, acceptsContentType) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-06-30 17:42:29 -04:00
|
|
|
resources := getBucketMultipartResources(req.URL.Query())
|
2015-07-16 20:22:45 -04:00
|
|
|
if resources.MaxUploads < 0 {
|
|
|
|
writeErrorResponse(w, req, InvalidMaxUploads, acceptsContentType, req.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
if resources.MaxUploads == 0 {
|
|
|
|
resources.MaxUploads = maxObjectList
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
2015-07-02 23:31:22 -04:00
|
|
|
|
2015-07-09 22:34:07 -04:00
|
|
|
var signature *donut.Signature
|
|
|
|
if _, ok := req.Header["Authorization"]; ok {
|
|
|
|
// Init signature V4 verification
|
2015-08-03 19:17:21 -04:00
|
|
|
var err *probe.Error
|
2015-07-09 22:34:07 -04:00
|
|
|
signature, err = InitSignatureV4(req)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resources, err := api.Donut.ListMultipartUploads(bucket, resources, signature)
|
2015-08-03 19:17:21 -04:00
|
|
|
if err == nil {
|
|
|
|
// generate response
|
|
|
|
response := generateListMultipartUploadsResponse(bucket, resources)
|
|
|
|
encodedSuccessResponse := encodeSuccessResponse(response, acceptsContentType)
|
|
|
|
// write headers
|
|
|
|
setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedSuccessResponse))
|
|
|
|
// write body
|
|
|
|
w.Write(encodedSuccessResponse)
|
|
|
|
return
|
|
|
|
}
|
2015-08-18 22:30:17 -04:00
|
|
|
switch err.ToGoError().(type) {
|
2015-07-10 00:44:24 -04:00
|
|
|
case donut.SignatureDoesNotMatch:
|
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
case donut.BucketNotFound:
|
2015-07-10 00:44:24 -04:00
|
|
|
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
default:
|
2015-08-03 19:17:21 -04:00
|
|
|
log.Error.Println(err.Trace())
|
2015-07-10 00:44:24 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|
|
|
|
|
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-07-02 18:40:16 -04:00
|
|
|
func (api Minio) ListObjectsHandler(w http.ResponseWriter, req *http.Request) {
|
2015-07-02 23:31:22 -04:00
|
|
|
// Ticket master block
|
2015-07-02 18:40:16 -04:00
|
|
|
{
|
2015-07-02 23:31:22 -04:00
|
|
|
op := Operation{}
|
|
|
|
op.ProceedCh = make(chan struct{})
|
|
|
|
api.OP <- op
|
|
|
|
// block until Ticket master gives us a go
|
|
|
|
<-op.ProceedCh
|
2015-07-02 18:40:16 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 23:31:22 -04:00
|
|
|
acceptsContentType := getContentType(req)
|
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())
|
2015-07-16 20:22:45 -04:00
|
|
|
if resources.Maxkeys < 0 {
|
|
|
|
writeErrorResponse(w, req, InvalidMaxKeys, acceptsContentType, req.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
if resources.Maxkeys == 0 {
|
|
|
|
resources.Maxkeys = maxObjectList
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
|
2015-07-09 22:34:07 -04:00
|
|
|
var signature *donut.Signature
|
|
|
|
if _, ok := req.Header["Authorization"]; ok {
|
|
|
|
// Init signature V4 verification
|
2015-08-03 19:17:21 -04:00
|
|
|
var err *probe.Error
|
2015-07-09 22:34:07 -04:00
|
|
|
signature, err = InitSignatureV4(req)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
objects, resources, err := api.Donut.ListObjects(bucket, resources, signature)
|
2015-08-03 19:17:21 -04:00
|
|
|
if err == nil {
|
2015-07-02 23:31:22 -04:00
|
|
|
// generate response
|
|
|
|
response := generateListObjectsResponse(bucket, objects, resources)
|
|
|
|
encodedSuccessResponse := encodeSuccessResponse(response, acceptsContentType)
|
|
|
|
// write headers
|
|
|
|
setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedSuccessResponse))
|
|
|
|
// write body
|
|
|
|
w.Write(encodedSuccessResponse)
|
2015-08-03 19:17:21 -04:00
|
|
|
return
|
|
|
|
}
|
2015-08-18 22:30:17 -04:00
|
|
|
switch err.ToGoError().(type) {
|
2015-07-10 00:44:24 -04:00
|
|
|
case donut.SignatureDoesNotMatch:
|
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
|
2015-07-03 03:29:54 -04:00
|
|
|
case donut.BucketNameInvalid:
|
|
|
|
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
|
|
|
case donut.BucketNotFound:
|
|
|
|
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
case donut.ObjectNotFound:
|
|
|
|
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
|
|
|
case donut.ObjectNameInvalid:
|
|
|
|
writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
|
|
|
|
default:
|
2015-08-03 19:17:21 -04:00
|
|
|
log.Error.Println(err.Trace())
|
2015-07-02 23:31:22 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|
|
|
|
|
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-07-02 18:40:16 -04:00
|
|
|
func (api Minio) ListBucketsHandler(w http.ResponseWriter, req *http.Request) {
|
2015-07-02 23:31:22 -04:00
|
|
|
// Ticket master block
|
|
|
|
{
|
|
|
|
op := Operation{}
|
|
|
|
op.ProceedCh = make(chan struct{})
|
|
|
|
api.OP <- op
|
|
|
|
// block until Ticket master gives us a go
|
|
|
|
<-op.ProceedCh
|
|
|
|
}
|
|
|
|
|
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
|
2015-07-09 17:42:04 -04:00
|
|
|
// if _, err := StripAccessKeyID(req); err != nil {
|
2015-06-30 17:42:29 -04:00
|
|
|
// writeErrorResponse(w, req, AccessDenied, acceptsContentType, req.URL.Path)
|
|
|
|
// return
|
|
|
|
// }
|
2015-07-02 23:31:22 -04:00
|
|
|
|
2015-07-09 22:34:07 -04:00
|
|
|
var signature *donut.Signature
|
|
|
|
if _, ok := req.Header["Authorization"]; ok {
|
|
|
|
// Init signature V4 verification
|
2015-08-03 19:17:21 -04:00
|
|
|
var err *probe.Error
|
2015-07-09 22:34:07 -04:00
|
|
|
signature, err = InitSignatureV4(req)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buckets, err := api.Donut.ListBuckets(signature)
|
2015-08-03 19:17:21 -04:00
|
|
|
if err == nil {
|
2015-07-02 23:31:22 -04:00
|
|
|
// generate response
|
|
|
|
response := generateListBucketsResponse(buckets)
|
|
|
|
encodedSuccessResponse := encodeSuccessResponse(response, acceptsContentType)
|
|
|
|
// write headers
|
|
|
|
setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedSuccessResponse))
|
|
|
|
// write response
|
|
|
|
w.Write(encodedSuccessResponse)
|
2015-08-03 19:17:21 -04:00
|
|
|
return
|
|
|
|
}
|
2015-08-18 22:30:17 -04:00
|
|
|
switch err.ToGoError().(type) {
|
2015-07-10 00:44:24 -04:00
|
|
|
case donut.SignatureDoesNotMatch:
|
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
default:
|
2015-08-03 19:17:21 -04:00
|
|
|
log.Error.Println(err.Trace())
|
2015-07-02 23:31:22 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
2015-07-02 18:40:16 -04:00
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|
|
|
|
|
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-07-02 18:40:16 -04:00
|
|
|
func (api Minio) PutBucketHandler(w http.ResponseWriter, req *http.Request) {
|
2015-07-02 23:31:22 -04:00
|
|
|
// Ticket master block
|
|
|
|
{
|
|
|
|
op := Operation{}
|
|
|
|
op.ProceedCh = make(chan struct{})
|
|
|
|
api.OP <- op
|
|
|
|
// block until Ticket master gives us a go
|
|
|
|
<-op.ProceedCh
|
|
|
|
}
|
|
|
|
|
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
|
2015-07-09 17:42:04 -04:00
|
|
|
// if _, err := StripAccessKeyID(req); err != nil {
|
2015-06-30 17:42:29 -04:00
|
|
|
// writeErrorResponse(w, req, AccessDenied, acceptsContentType, req.URL.Path)
|
|
|
|
// return
|
|
|
|
// }
|
2015-07-02 18:40:16 -04:00
|
|
|
|
2015-06-30 17:42:29 -04:00
|
|
|
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"]
|
2015-07-02 23:31:22 -04:00
|
|
|
|
2015-07-09 22:34:07 -04:00
|
|
|
var signature *donut.Signature
|
|
|
|
if _, ok := req.Header["Authorization"]; ok {
|
|
|
|
// Init signature V4 verification
|
2015-08-03 19:17:21 -04:00
|
|
|
var err *probe.Error
|
2015-07-09 22:34:07 -04:00
|
|
|
signature, err = InitSignatureV4(req)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-14 12:17:30 -04:00
|
|
|
// if body of request is non-nil then check for validity of Content-Length
|
|
|
|
if req.Body != nil {
|
|
|
|
/// if Content-Length missing, deny the request
|
|
|
|
size := req.Header.Get("Content-Length")
|
|
|
|
if size == "" {
|
|
|
|
writeErrorResponse(w, req, MissingContentLength, acceptsContentType, req.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err := api.Donut.MakeBucket(bucket, getACLTypeString(aclType), req.Body, signature)
|
2015-08-03 19:17:21 -04:00
|
|
|
if err == nil {
|
2015-07-02 23:31:22 -04:00
|
|
|
// Make sure to add Location information here only for bucket
|
|
|
|
w.Header().Set("Location", "/"+bucket)
|
|
|
|
writeSuccessResponse(w, acceptsContentType)
|
2015-08-03 19:17:21 -04:00
|
|
|
return
|
|
|
|
}
|
2015-08-18 22:30:17 -04:00
|
|
|
switch err.ToGoError().(type) {
|
2015-07-10 00:44:24 -04:00
|
|
|
case donut.SignatureDoesNotMatch:
|
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
case donut.TooManyBuckets:
|
|
|
|
writeErrorResponse(w, req, TooManyBuckets, acceptsContentType, req.URL.Path)
|
|
|
|
case donut.BucketNameInvalid:
|
|
|
|
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
|
|
|
case donut.BucketExists:
|
|
|
|
writeErrorResponse(w, req, BucketAlreadyExists, acceptsContentType, req.URL.Path)
|
|
|
|
default:
|
2015-08-03 19:17:21 -04:00
|
|
|
log.Error.Println(err.Trace())
|
2015-07-02 23:31:22 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|
|
|
|
|
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-07-02 18:40:16 -04:00
|
|
|
func (api Minio) PutBucketACLHandler(w http.ResponseWriter, req *http.Request) {
|
2015-07-02 23:31:22 -04:00
|
|
|
// Ticket master block
|
2015-07-02 18:40:16 -04:00
|
|
|
{
|
2015-07-02 23:31:22 -04:00
|
|
|
op := Operation{}
|
|
|
|
op.ProceedCh = make(chan struct{})
|
|
|
|
api.OP <- op
|
|
|
|
// block until Ticket master gives us a go
|
|
|
|
<-op.ProceedCh
|
2015-07-02 18:40:16 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
|
|
|
|
acceptsContentType := getContentType(req)
|
2015-07-02 18:40:16 -04:00
|
|
|
|
2015-06-30 17:42:29 -04:00
|
|
|
// 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"]
|
2015-07-02 23:31:22 -04:00
|
|
|
|
2015-07-09 22:34:07 -04:00
|
|
|
var signature *donut.Signature
|
|
|
|
if _, ok := req.Header["Authorization"]; ok {
|
|
|
|
// Init signature V4 verification
|
2015-08-03 19:17:21 -04:00
|
|
|
var err *probe.Error
|
2015-07-09 22:34:07 -04:00
|
|
|
signature, err = InitSignatureV4(req)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err := api.Donut.SetBucketMetadata(bucket, map[string]string{"acl": getACLTypeString(aclType)}, signature)
|
2015-08-03 19:17:21 -04:00
|
|
|
if err == nil {
|
2015-07-02 23:31:22 -04:00
|
|
|
writeSuccessResponse(w, acceptsContentType)
|
2015-08-03 19:17:21 -04:00
|
|
|
return
|
|
|
|
}
|
2015-08-18 22:30:17 -04:00
|
|
|
switch err.ToGoError().(type) {
|
2015-07-10 00:44:24 -04:00
|
|
|
case donut.SignatureDoesNotMatch:
|
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
case donut.BucketNameInvalid:
|
|
|
|
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
|
|
|
case donut.BucketNotFound:
|
|
|
|
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
|
|
|
|
default:
|
2015-08-03 19:17:21 -04:00
|
|
|
log.Error.Println(err.Trace())
|
2015-07-02 23:31:22 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|
|
|
|
|
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-07-02 18:40:16 -04:00
|
|
|
func (api Minio) HeadBucketHandler(w http.ResponseWriter, req *http.Request) {
|
2015-07-02 23:31:22 -04:00
|
|
|
// Ticket master block
|
2015-07-02 18:40:16 -04:00
|
|
|
{
|
2015-07-02 23:31:22 -04:00
|
|
|
op := Operation{}
|
|
|
|
op.ProceedCh = make(chan struct{})
|
|
|
|
api.OP <- op
|
|
|
|
// block until Ticket master gives us a go
|
|
|
|
<-op.ProceedCh
|
2015-07-02 18:40:16 -04:00
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
|
|
|
|
acceptsContentType := getContentType(req)
|
2015-06-30 17:42:29 -04:00
|
|
|
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
2015-07-02 23:31:22 -04:00
|
|
|
|
2015-07-09 22:34:07 -04:00
|
|
|
var signature *donut.Signature
|
|
|
|
if _, ok := req.Header["Authorization"]; ok {
|
|
|
|
// Init signature V4 verification
|
2015-08-03 19:17:21 -04:00
|
|
|
var err *probe.Error
|
2015-07-09 22:34:07 -04:00
|
|
|
signature, err = InitSignatureV4(req)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := api.Donut.GetBucketMetadata(bucket, signature)
|
2015-08-03 19:17:21 -04:00
|
|
|
if err == nil {
|
2015-07-02 23:31:22 -04:00
|
|
|
writeSuccessResponse(w, acceptsContentType)
|
2015-08-03 19:17:21 -04:00
|
|
|
return
|
|
|
|
}
|
2015-08-18 22:30:17 -04:00
|
|
|
switch err.ToGoError().(type) {
|
2015-07-10 00:44:24 -04:00
|
|
|
case donut.SignatureDoesNotMatch:
|
2015-07-11 00:06:43 -04:00
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
case donut.BucketNotFound:
|
2015-07-11 00:06:43 -04:00
|
|
|
writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
case donut.BucketNameInvalid:
|
2015-07-11 00:06:43 -04:00
|
|
|
writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
default:
|
2015-08-03 19:17:21 -04:00
|
|
|
log.Error.Println(err.Trace())
|
2015-07-11 00:06:43 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|