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.
|
|
|
|
*/
|
|
|
|
|
2015-09-19 03:52:01 -04:00
|
|
|
package main
|
2015-06-30 17:42:29 -04:00
|
|
|
|
|
|
|
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-10-02 02:51:17 -04:00
|
|
|
signv4 "github.com/minio/minio/pkg/signature"
|
2015-06-30 17:42:29 -04:00
|
|
|
)
|
|
|
|
|
2015-10-04 03:27:49 -04:00
|
|
|
func (api API) isValidOp(w http.ResponseWriter, req *http.Request) 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-10-04 15:06:14 -04:00
|
|
|
bucketMetadata, err := api.Donut.GetBucketMetadata(bucket)
|
2015-09-18 17:48:01 -04:00
|
|
|
if err != nil {
|
2015-09-19 06:20:07 -04:00
|
|
|
errorIf(err.Trace(), "GetBucketMetadata failed.", nil)
|
2015-09-18 17:48:01 -04:00
|
|
|
switch err.ToGoError().(type) {
|
|
|
|
case donut.BucketNotFound:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, NoSuchBucket, req.URL.Path)
|
2015-09-18 17:48:01 -04:00
|
|
|
return false
|
|
|
|
case donut.BucketNameInvalid:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InvalidBucketName, req.URL.Path)
|
2015-09-18 17:48:01 -04:00
|
|
|
return false
|
|
|
|
default:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, req.URL.Path)
|
2015-09-18 17:48:01 -04:00
|
|
|
return false
|
2015-07-02 23:31:22 -04:00
|
|
|
}
|
2015-08-03 19:17:21 -04:00
|
|
|
}
|
2015-09-18 17:48:01 -04:00
|
|
|
if _, err = stripAccessKeyID(req.Header.Get("Authorization")); err != nil {
|
|
|
|
if bucketMetadata.ACL.IsPrivate() {
|
|
|
|
return true
|
|
|
|
//uncomment this when we have webcli
|
2015-10-04 03:27:49 -04:00
|
|
|
//writeErrorResponse(w, req, AccessDenied, req.URL.Path)
|
2015-09-18 17:48:01 -04:00
|
|
|
//return false
|
|
|
|
}
|
|
|
|
if bucketMetadata.ACL.IsPublicRead() && req.Method == "PUT" {
|
|
|
|
return true
|
|
|
|
//uncomment this when we have webcli
|
2015-10-04 03:27:49 -04:00
|
|
|
//writeErrorResponse(w, req, AccessDenied, req.URL.Path)
|
2015-09-18 17:48:01 -04:00
|
|
|
//return false
|
|
|
|
}
|
2015-07-02 23:31:22 -04:00
|
|
|
}
|
2015-09-18 17:48:01 -04:00
|
|
|
return true
|
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-10-02 02:51:17 -04:00
|
|
|
func (api API) 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-09-19 03:52:01 -04:00
|
|
|
op := APIOperation{}
|
2015-07-02 23:31:22 -04:00
|
|
|
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-10-04 03:27:49 -04:00
|
|
|
if !api.isValidOp(w, req) {
|
2015-07-03 03:29:54 -04:00
|
|
|
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 {
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InvalidMaxUploads, req.URL.Path)
|
2015-07-16 20:22:45 -04:00
|
|
|
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-10-04 15:06:14 -04:00
|
|
|
resources, err := api.Donut.ListMultipartUploads(bucket, resources)
|
2015-09-19 06:20:07 -04:00
|
|
|
if err != nil {
|
|
|
|
errorIf(err.Trace(), "ListMultipartUploads failed.", nil)
|
|
|
|
switch err.ToGoError().(type) {
|
|
|
|
case donut.BucketNotFound:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, NoSuchBucket, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
default:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
}
|
2015-08-03 19:17:21 -04:00
|
|
|
return
|
|
|
|
}
|
2015-09-19 06:20:07 -04:00
|
|
|
// generate response
|
|
|
|
response := generateListMultipartUploadsResponse(bucket, resources)
|
2015-10-04 03:27:49 -04:00
|
|
|
encodedSuccessResponse := encodeSuccessResponse(response)
|
2015-09-19 06:20:07 -04:00
|
|
|
// write headers
|
2015-10-04 03:27:49 -04:00
|
|
|
setCommonHeaders(w, len(encodedSuccessResponse))
|
2015-09-19 06:20:07 -04:00
|
|
|
// write body
|
|
|
|
w.Write(encodedSuccessResponse)
|
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-10-02 02:51:17 -04:00
|
|
|
func (api API) 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-09-19 03:52:01 -04:00
|
|
|
op := APIOperation{}
|
2015-07-02 23:31:22 -04:00
|
|
|
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-10-04 03:27:49 -04:00
|
|
|
if !api.isValidOp(w, req) {
|
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 {
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InvalidMaxKeys, req.URL.Path)
|
2015-07-16 20:22:45 -04:00
|
|
|
return
|
|
|
|
}
|
2015-06-30 17:42:29 -04:00
|
|
|
if resources.Maxkeys == 0 {
|
|
|
|
resources.Maxkeys = maxObjectList
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
|
|
|
|
2015-10-04 15:06:14 -04:00
|
|
|
objects, resources, err := api.Donut.ListObjects(bucket, resources)
|
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)
|
2015-10-04 03:27:49 -04:00
|
|
|
encodedSuccessResponse := encodeSuccessResponse(response)
|
2015-07-02 23:31:22 -04:00
|
|
|
// write headers
|
2015-10-04 03:27:49 -04:00
|
|
|
setCommonHeaders(w, len(encodedSuccessResponse))
|
2015-07-02 23:31:22 -04:00
|
|
|
// 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-03 03:29:54 -04:00
|
|
|
case donut.BucketNameInvalid:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InvalidBucketName, req.URL.Path)
|
2015-07-03 03:29:54 -04:00
|
|
|
case donut.BucketNotFound:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, NoSuchBucket, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
case donut.ObjectNotFound:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, NoSuchKey, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
case donut.ObjectNameInvalid:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, NoSuchKey, req.URL.Path)
|
2015-07-02 23:31:22 -04:00
|
|
|
default:
|
2015-09-19 06:20:07 -04:00
|
|
|
errorIf(err.Trace(), "ListObjects failed.", nil)
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, 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
|
|
|
// 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-10-02 02:51:17 -04:00
|
|
|
func (api API) ListBucketsHandler(w http.ResponseWriter, req *http.Request) {
|
2015-07-02 23:31:22 -04:00
|
|
|
// Ticket master block
|
|
|
|
{
|
2015-09-19 03:52:01 -04:00
|
|
|
op := APIOperation{}
|
2015-07-02 23:31:22 -04:00
|
|
|
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
|
|
|
// 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-10-04 03:27:49 -04:00
|
|
|
// writeErrorResponse(w, req, AccessDenied, req.URL.Path)
|
2015-06-30 17:42:29 -04:00
|
|
|
// return
|
|
|
|
// }
|
2015-07-02 23:31:22 -04:00
|
|
|
|
2015-10-04 15:06:14 -04:00
|
|
|
buckets, err := api.Donut.ListBuckets()
|
2015-08-03 19:17:21 -04:00
|
|
|
if err == nil {
|
2015-07-02 23:31:22 -04:00
|
|
|
// generate response
|
|
|
|
response := generateListBucketsResponse(buckets)
|
2015-10-04 03:27:49 -04:00
|
|
|
encodedSuccessResponse := encodeSuccessResponse(response)
|
2015-07-02 23:31:22 -04:00
|
|
|
// write headers
|
2015-10-04 03:27:49 -04:00
|
|
|
setCommonHeaders(w, len(encodedSuccessResponse))
|
2015-07-02 23:31:22 -04:00
|
|
|
// write response
|
|
|
|
w.Write(encodedSuccessResponse)
|
2015-08-03 19:17:21 -04:00
|
|
|
return
|
|
|
|
}
|
2015-10-04 15:06:14 -04:00
|
|
|
errorIf(err.Trace(), "ListBuckets failed.", nil)
|
|
|
|
writeErrorResponse(w, req, InternalError, req.URL.Path)
|
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-10-02 02:51:17 -04:00
|
|
|
func (api API) PutBucketHandler(w http.ResponseWriter, req *http.Request) {
|
2015-07-02 23:31:22 -04:00
|
|
|
// Ticket master block
|
|
|
|
{
|
2015-09-19 03:52:01 -04:00
|
|
|
op := APIOperation{}
|
2015-07-02 23:31:22 -04:00
|
|
|
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
|
|
|
// 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-10-04 03:27:49 -04:00
|
|
|
// writeErrorResponse(w, req, AccessDenied, req.URL.Path)
|
2015-06-30 17:42:29 -04:00
|
|
|
// 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 {
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, NotImplemented, req.URL.Path)
|
2015-06-30 17:42:29 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
2015-07-02 23:31:22 -04:00
|
|
|
|
2015-10-02 02:51:17 -04:00
|
|
|
var signature *signv4.Signature
|
2015-07-09 22:34:07 -04:00
|
|
|
if _, ok := req.Header["Authorization"]; ok {
|
|
|
|
// Init signature V4 verification
|
2015-08-03 19:17:21 -04:00
|
|
|
var err *probe.Error
|
2015-09-18 17:48:01 -04:00
|
|
|
signature, err = initSignatureV4(req)
|
2015-07-09 22:34:07 -04:00
|
|
|
if err != nil {
|
2015-09-19 06:20:07 -04:00
|
|
|
errorIf(err.Trace(), "Initializing signature v4 failed.", nil)
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, req.URL.Path)
|
2015-07-09 22:34:07 -04:00
|
|
|
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 == "" {
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, MissingContentLength, req.URL.Path)
|
2015-07-14 12:17:30 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err := api.Donut.MakeBucket(bucket, getACLTypeString(aclType), req.Body, signature)
|
2015-09-19 06:20:07 -04:00
|
|
|
if err != nil {
|
|
|
|
errorIf(err.Trace(), "MakeBucket failed.", nil)
|
|
|
|
switch err.ToGoError().(type) {
|
2015-10-02 02:51:17 -04:00
|
|
|
case signv4.DoesNotMatch:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
case donut.TooManyBuckets:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, TooManyBuckets, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
case donut.BucketNameInvalid:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InvalidBucketName, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
case donut.BucketExists:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, BucketAlreadyExists, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
default:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
}
|
2015-08-03 19:17:21 -04:00
|
|
|
return
|
|
|
|
}
|
2015-09-19 06:20:07 -04:00
|
|
|
// Make sure to add Location information here only for bucket
|
|
|
|
w.Header().Set("Location", "/"+bucket)
|
2015-10-04 03:27:49 -04:00
|
|
|
writeSuccessResponse(w)
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|
|
|
|
|
2015-10-02 02:51:17 -04:00
|
|
|
// PostPolicyBucketHandler - POST policy
|
|
|
|
// ----------
|
|
|
|
// This implementation of the POST operation handles object creation with a specified
|
|
|
|
// signature policy in multipart/form-data
|
|
|
|
func (api API) PostPolicyBucketHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
|
// Ticket master block
|
|
|
|
{
|
|
|
|
op := APIOperation{}
|
|
|
|
op.ProceedCh = make(chan struct{})
|
|
|
|
api.OP <- op
|
|
|
|
// block until Ticket master gives us a go
|
|
|
|
<-op.ProceedCh
|
|
|
|
}
|
|
|
|
|
|
|
|
// Here the parameter is the size of the form data that should
|
|
|
|
// be loaded in memory, the remaining being put in temporary
|
|
|
|
// files
|
|
|
|
reader, err := req.MultipartReader()
|
|
|
|
if err != nil {
|
|
|
|
errorIf(probe.NewError(err), "Unable to initialize multipart reader.", nil)
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, MalformedPOSTRequest, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fileBody, formValues, perr := extractHTTPFormValues(reader)
|
|
|
|
if perr != nil {
|
|
|
|
errorIf(perr.Trace(), "Unable to parse form values.", nil)
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, MalformedPOSTRequest, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
bucket := mux.Vars(req)["bucket"]
|
|
|
|
formValues["Bucket"] = bucket
|
|
|
|
object := formValues["key"]
|
|
|
|
signature, perr := initPostPresignedPolicyV4(formValues)
|
|
|
|
if perr != nil {
|
|
|
|
errorIf(perr.Trace(), "Unable to initialize post policy presigned.", nil)
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, MalformedPOSTRequest, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if perr = applyPolicy(formValues, signature.PresignedPolicy); perr != nil {
|
|
|
|
errorIf(perr.Trace(), "Invalid request, policy doesn't match with the endpoint.", nil)
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, MalformedPOSTRequest, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
var ok bool
|
|
|
|
if ok, perr = signature.DoesPolicySignatureMatch(formValues["X-Amz-Date"]); perr != nil {
|
|
|
|
errorIf(perr.Trace(), "Unable to verify signature.", nil)
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if ok == false {
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
metadata, perr := api.Donut.CreateObject(bucket, object, "", 0, fileBody, nil, nil)
|
|
|
|
if perr != nil {
|
|
|
|
errorIf(perr.Trace(), "CreateObject failed.", nil)
|
|
|
|
switch perr.ToGoError().(type) {
|
|
|
|
case donut.BucketNotFound:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, NoSuchBucket, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
case donut.BucketNameInvalid:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InvalidBucketName, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
case donut.ObjectExists:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, MethodNotAllowed, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
case donut.BadDigest:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, BadDigest, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
case signv4.DoesNotMatch:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
case donut.IncompleteBody:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, IncompleteBody, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
case donut.EntityTooLarge:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, EntityTooLarge, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
case donut.InvalidDigest:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InvalidDigest, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
default:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, req.URL.Path)
|
2015-10-02 02:51:17 -04:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.Header().Set("ETag", metadata.MD5Sum)
|
2015-10-04 03:27:49 -04:00
|
|
|
writeSuccessResponse(w)
|
2015-10-02 02:51:17 -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-10-02 02:51:17 -04:00
|
|
|
func (api API) 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-09-19 03:52:01 -04:00
|
|
|
op := APIOperation{}
|
2015-07-02 23:31:22 -04:00
|
|
|
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
|
|
|
|
2015-06-30 17:42:29 -04:00
|
|
|
// read from 'x-amz-acl'
|
|
|
|
aclType := getACLType(req)
|
|
|
|
if aclType == unsupportedACLType {
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, NotImplemented, req.URL.Path)
|
2015-06-30 17:42:29 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
2015-07-02 23:31:22 -04:00
|
|
|
|
2015-10-04 15:06:14 -04:00
|
|
|
err := api.Donut.SetBucketMetadata(bucket, map[string]string{"acl": getACLTypeString(aclType)})
|
2015-09-19 06:20:07 -04:00
|
|
|
if err != nil {
|
|
|
|
errorIf(err.Trace(), "PutBucketACL failed.", nil)
|
|
|
|
switch err.ToGoError().(type) {
|
2015-10-02 02:51:17 -04:00
|
|
|
case signv4.DoesNotMatch:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
case donut.BucketNameInvalid:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InvalidBucketName, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
case donut.BucketNotFound:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, NoSuchBucket, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
default:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
}
|
2015-08-03 19:17:21 -04:00
|
|
|
return
|
|
|
|
}
|
2015-10-04 03:27:49 -04:00
|
|
|
writeSuccessResponse(w)
|
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-10-02 02:51:17 -04:00
|
|
|
func (api API) 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-09-19 03:52:01 -04:00
|
|
|
op := APIOperation{}
|
2015-07-02 23:31:22 -04:00
|
|
|
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
|
|
|
|
2015-06-30 17:42:29 -04:00
|
|
|
vars := mux.Vars(req)
|
|
|
|
bucket := vars["bucket"]
|
2015-07-02 23:31:22 -04:00
|
|
|
|
2015-10-04 15:06:14 -04:00
|
|
|
_, err := api.Donut.GetBucketMetadata(bucket)
|
2015-09-19 06:20:07 -04:00
|
|
|
if err != nil {
|
|
|
|
errorIf(err.Trace(), "GetBucketMetadata failed.", nil)
|
|
|
|
switch err.ToGoError().(type) {
|
2015-10-02 02:51:17 -04:00
|
|
|
case signv4.DoesNotMatch:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, SignatureDoesNotMatch, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
case donut.BucketNotFound:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, NoSuchBucket, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
case donut.BucketNameInvalid:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InvalidBucketName, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
default:
|
2015-10-04 03:27:49 -04:00
|
|
|
writeErrorResponse(w, req, InternalError, req.URL.Path)
|
2015-09-19 06:20:07 -04:00
|
|
|
}
|
2015-08-03 19:17:21 -04:00
|
|
|
return
|
|
|
|
}
|
2015-10-04 03:27:49 -04:00
|
|
|
writeSuccessResponse(w)
|
2015-06-30 17:42:29 -04:00
|
|
|
}
|