mirror of
https://github.com/minio/minio.git
synced 2024-12-25 14:45:54 -05:00
Merge pull request #1013 from harshavardhana/bucket-location
bucket-location: Implement bucket location response.
This commit is contained in:
commit
7aab7ba946
@ -18,12 +18,18 @@ package main
|
|||||||
|
|
||||||
import "encoding/xml"
|
import "encoding/xml"
|
||||||
|
|
||||||
// Limit number of objects in a given response
|
// Limit number of objects in a given response.
|
||||||
const (
|
const (
|
||||||
maxObjectList = 1000
|
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 {
|
type AccessControlPolicyResponse struct {
|
||||||
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ AccessControlPolicy" json:"-"`
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ AccessControlPolicy" json:"-"`
|
||||||
|
|
||||||
@ -33,7 +39,7 @@ type AccessControlPolicyResponse struct {
|
|||||||
Owner Owner
|
Owner Owner
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grant container for grantee and permission
|
// Grant container for grantee and permission.
|
||||||
type Grant struct {
|
type Grant struct {
|
||||||
Grantee struct {
|
Grantee struct {
|
||||||
ID string
|
ID string
|
||||||
@ -45,7 +51,7 @@ type Grant struct {
|
|||||||
Permission string
|
Permission string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListObjectsResponse - format for list objects response
|
// ListObjectsResponse - format for list objects response.
|
||||||
type ListObjectsResponse struct {
|
type ListObjectsResponse struct {
|
||||||
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult" json:"-"`
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListBucketResult" json:"-"`
|
||||||
|
|
||||||
@ -75,7 +81,7 @@ type ListObjectsResponse struct {
|
|||||||
Prefix string
|
Prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Part container for part metadata
|
// Part container for part metadata.
|
||||||
type Part struct {
|
type Part struct {
|
||||||
PartNumber int
|
PartNumber int
|
||||||
ETag string
|
ETag string
|
||||||
@ -83,7 +89,7 @@ type Part struct {
|
|||||||
Size int64
|
Size int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPartsResponse - format for list parts response
|
// ListPartsResponse - format for list parts response.
|
||||||
type ListPartsResponse struct {
|
type ListPartsResponse struct {
|
||||||
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListPartsResult" json:"-"`
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListPartsResult" json:"-"`
|
||||||
|
|
||||||
@ -102,11 +108,11 @@ type ListPartsResponse struct {
|
|||||||
MaxParts int
|
MaxParts int
|
||||||
IsTruncated bool
|
IsTruncated bool
|
||||||
|
|
||||||
// List of parts
|
// List of parts.
|
||||||
Part []*Part
|
Part []*Part
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListMultipartUploadsResponse - format for list multipart uploads response
|
// ListMultipartUploadsResponse - format for list multipart uploads response.
|
||||||
type ListMultipartUploadsResponse struct {
|
type ListMultipartUploadsResponse struct {
|
||||||
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ ListMultipartUploadsResult" json:"-"`
|
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"
|
"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)
|
// ListMultipartUploadsHandler - GET Bucket (List Multipart uploads)
|
||||||
// -------------------------
|
// -------------------------
|
||||||
// This operation lists in-progress multipart uploads. An in-progress
|
// 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.Methods("DELETE").Path("/{object:.+}").HandlerFunc(a.DeleteObjectHandler)
|
||||||
|
|
||||||
// Bucket operations
|
// Bucket operations
|
||||||
|
bucket.Methods("GET").HandlerFunc(a.GetBucketLocationHandler).Queries("location", "")
|
||||||
bucket.Methods("GET").HandlerFunc(a.GetBucketACLHandler).Queries("acl", "")
|
bucket.Methods("GET").HandlerFunc(a.GetBucketACLHandler).Queries("acl", "")
|
||||||
bucket.Methods("GET").HandlerFunc(a.ListMultipartUploadsHandler).Queries("uploads", "")
|
bucket.Methods("GET").HandlerFunc(a.ListMultipartUploadsHandler).Queries("uploads", "")
|
||||||
bucket.Methods("GET").HandlerFunc(a.ListObjectsHandler)
|
bucket.Methods("GET").HandlerFunc(a.ListObjectsHandler)
|
||||||
|
Loading…
Reference in New Issue
Block a user