bucket-location: Implement bucket location response.

master
Harshavardhana 9 years ago
parent 155a4110b1
commit 0345c8fffb
  1. 22
      api-definitions.go
  2. 35
      bucket-handlers.go
  3. 1
      routers.go

@ -18,12 +18,18 @@ package main
import "encoding/xml"
// Limit number of objects in a given response
// Limit number of objects in a given response.
const (
maxObjectList = 1000
)
// AccessControlPolicyResponse - format for get bucket acl response
// LocationResponse - format for location response.
type LocationResponse struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ LocationConstraint" json:"-"`
Location string `xml:",chardata"`
}
// AccessControlPolicyResponse - format for get bucket acl response.
type AccessControlPolicyResponse struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ AccessControlPolicy" json:"-"`
@ -33,7 +39,7 @@ type AccessControlPolicyResponse struct {
Owner Owner
}
// Grant container for grantee and permission
// Grant container for grantee and permission.
type Grant struct {
Grantee struct {
ID string
@ -45,7 +51,7 @@ type Grant struct {
Permission string
}
// ListObjectsResponse - format for list objects response
// ListObjectsResponse - format for list objects response.
type ListObjectsResponse struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult" json:"-"`
@ -75,7 +81,7 @@ type ListObjectsResponse struct {
Prefix string
}
// Part container for part metadata
// Part container for part metadata.
type Part struct {
PartNumber int
ETag string
@ -83,7 +89,7 @@ type Part struct {
Size int64
}
// ListPartsResponse - format for list parts response
// ListPartsResponse - format for list parts response.
type ListPartsResponse struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListPartsResult" json:"-"`
@ -102,11 +108,11 @@ type ListPartsResponse struct {
MaxParts int
IsTruncated bool
// List of parts
// List of parts.
Part []*Part
}
// ListMultipartUploadsResponse - format for list multipart uploads response
// ListMultipartUploadsResponse - format for list multipart uploads response.
type ListMultipartUploadsResponse struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListMultipartUploadsResult" json:"-"`

@ -27,6 +27,41 @@ import (
"github.com/minio/minio/pkg/fs"
)
// GetBucketLocationHandler - GET Bucket location.
// -------------------------
// This operation returns bucket location.
func (api CloudStorageAPI) GetBucketLocationHandler(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
bucket := vars["bucket"]
if !api.Anonymous {
if isRequestRequiresACLCheck(req) {
writeErrorResponse(w, req, AccessDenied, req.URL.Path)
return
}
}
_, err := api.Filesystem.GetBucketMetadata(bucket)
if err != nil {
errorIf(err.Trace(), "GetBucketMetadata failed.", nil)
switch err.ToGoError().(type) {
case fs.BucketNotFound:
writeErrorResponse(w, req, NoSuchBucket, req.URL.Path)
case fs.BucketNameInvalid:
writeErrorResponse(w, req, InvalidBucketName, req.URL.Path)
default:
writeErrorResponse(w, req, InternalError, req.URL.Path)
}
}
// TODO: Location value for LocationResponse is deliberately not used, until
// we bring in a mechanism of configurable regions. For the time being
// default region is empty i.e 'us-east-1'.
encodedSuccessResponse := encodeSuccessResponse(LocationResponse{}) // generate response
setCommonHeaders(w, len(encodedSuccessResponse)) // write headers
w.Write(encodedSuccessResponse) // write body
}
// ListMultipartUploadsHandler - GET Bucket (List Multipart uploads)
// -------------------------
// This operation lists in-progress multipart uploads. An in-progress

@ -49,6 +49,7 @@ func registerCloudStorageAPI(mux *router.Router, a CloudStorageAPI) {
bucket.Methods("DELETE").Path("/{object:.+}").HandlerFunc(a.DeleteObjectHandler)
// Bucket operations
bucket.Methods("GET").HandlerFunc(a.GetBucketLocationHandler).Queries("location", "")
bucket.Methods("GET").HandlerFunc(a.GetBucketACLHandler).Queries("acl", "")
bucket.Methods("GET").HandlerFunc(a.ListMultipartUploadsHandler).Queries("uploads", "")
bucket.Methods("GET").HandlerFunc(a.ListObjectsHandler)

Loading…
Cancel
Save