From 4fc161ddb157d00d225e7c92269d1592dfa2591b Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 7 Dec 2015 13:39:18 -0800 Subject: [PATCH] bucketName: relax bucket names, now allow numbers as starting characters. --- object-handlers.go | 2 ++ pkg/fs/definitions.go | 9 ++++++--- pkg/fs/fs-bucket-listobjects.go | 2 +- pkg/fs/fs-bucket.go | 10 +++++----- pkg/fs/fs-multipart.go | 12 ++++++------ pkg/fs/fs-object.go | 8 ++++---- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/object-handlers.go b/object-handlers.go index 1bec39ad1..f285d57c9 100644 --- a/object-handlers.go +++ b/object-handlers.go @@ -156,6 +156,7 @@ func (api CloudStorageAPI) PutObjectHandler(w http.ResponseWriter, req *http.Req var err error sizeInt64, err = strconv.ParseInt(size, 10, 64) if err != nil { + errorIf(probe.NewError(err), "Parsing Content-Length failed.", nil) writeErrorResponse(w, req, InvalidRequest, req.URL.Path) return } @@ -289,6 +290,7 @@ func (api CloudStorageAPI) PutObjectPartHandler(w http.ResponseWriter, req *http var err error sizeInt64, err = strconv.ParseInt(size, 10, 64) if err != nil { + errorIf(probe.NewError(err), "Parsing Content-Length failed.", nil) writeErrorResponse(w, req, InvalidRequest, req.URL.Path) return } diff --git a/pkg/fs/definitions.go b/pkg/fs/definitions.go index e9eb34b3b..6abb7b077 100644 --- a/pkg/fs/definitions.go +++ b/pkg/fs/definitions.go @@ -165,9 +165,12 @@ func IsValidBucketACL(acl string) bool { } } -// IsValidBucket - verify bucket name in accordance with +// IsValidBucketName - verify bucket name in accordance with // - http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html -func IsValidBucket(bucket string) bool { +func IsValidBucketName(bucket string) bool { + if strings.TrimSpace(bucket) == "" { + return false + } if len(bucket) < 3 || len(bucket) > 63 { return false } @@ -178,7 +181,7 @@ func IsValidBucket(bucket string) bool { return false } // We don't support buckets with '.' in them - match, _ := regexp.MatchString("^[a-zA-Z][a-zA-Z0-9\\-]+[a-zA-Z0-9]$", bucket) + match, _ := regexp.MatchString("^[a-zA-Z0-9][a-zA-Z0-9\\-]+[a-zA-Z0-9]$", bucket) return match } diff --git a/pkg/fs/fs-bucket-listobjects.go b/pkg/fs/fs-bucket-listobjects.go index d3d3079ef..323aba12c 100644 --- a/pkg/fs/fs-bucket-listobjects.go +++ b/pkg/fs/fs-bucket-listobjects.go @@ -31,7 +31,7 @@ import ( func (fs Filesystem) ListObjects(bucket string, resources BucketResourcesMetadata) ([]ObjectMetadata, BucketResourcesMetadata, *probe.Error) { fs.lock.Lock() defer fs.lock.Unlock() - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return nil, resources, probe.NewError(BucketNameInvalid{Bucket: bucket}) } if resources.Prefix != "" && IsValidObjectName(resources.Prefix) == false { diff --git a/pkg/fs/fs-bucket.go b/pkg/fs/fs-bucket.go index f0e6e50bb..1fd2b8f43 100644 --- a/pkg/fs/fs-bucket.go +++ b/pkg/fs/fs-bucket.go @@ -33,7 +33,7 @@ func (fs Filesystem) DeleteBucket(bucket string) *probe.Error { fs.lock.Lock() defer fs.lock.Unlock() // verify bucket path legal - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return probe.NewError(BucketNameInvalid{Bucket: bucket}) } bucketDir := filepath.Join(fs.path, bucket) @@ -78,7 +78,7 @@ func (fs Filesystem) ListBuckets() ([]BucketMetadata, *probe.Error) { } if file.IsDir() { // if directories found with odd names, skip them too - if !IsValidBucket(file.Name()) { + if !IsValidBucketName(file.Name()) { continue } } @@ -108,7 +108,7 @@ func (fs Filesystem) MakeBucket(bucket, acl string) *probe.Error { } // verify bucket path legal - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return probe.NewError(BucketNameInvalid{Bucket: bucket}) } @@ -157,7 +157,7 @@ func (fs Filesystem) MakeBucket(bucket, acl string) *probe.Error { func (fs Filesystem) GetBucketMetadata(bucket string) (BucketMetadata, *probe.Error) { fs.lock.Lock() defer fs.lock.Unlock() - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return BucketMetadata{}, probe.NewError(BucketNameInvalid{Bucket: bucket}) } // get bucket path @@ -184,7 +184,7 @@ func (fs Filesystem) GetBucketMetadata(bucket string) (BucketMetadata, *probe.Er func (fs Filesystem) SetBucketMetadata(bucket string, metadata map[string]string) *probe.Error { fs.lock.Lock() defer fs.lock.Unlock() - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return probe.NewError(BucketNameInvalid{Bucket: bucket}) } acl := metadata["acl"] diff --git a/pkg/fs/fs-multipart.go b/pkg/fs/fs-multipart.go index 00fc18632..024d43948 100644 --- a/pkg/fs/fs-multipart.go +++ b/pkg/fs/fs-multipart.go @@ -56,7 +56,7 @@ func (fs Filesystem) isValidUploadID(object, uploadID string) bool { func (fs Filesystem) ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error) { fs.lock.Lock() defer fs.lock.Unlock() - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return BucketMultipartResourcesMetadata{}, probe.NewError(BucketNameInvalid{Bucket: bucket}) } bucketPath := filepath.Join(fs.path, bucket) @@ -153,7 +153,7 @@ func (fs Filesystem) NewMultipartUpload(bucket, object string) (string, *probe.E return "", probe.NewError(RootPathFull{Path: fs.path}) } - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return "", probe.NewError(BucketNameInvalid{Bucket: bucket}) } if !IsValidObjectName(object) { @@ -234,7 +234,7 @@ func (fs Filesystem) CreateObjectPart(bucket, object, uploadID, expectedMD5Sum s return "", probe.NewError(errors.New("invalid part id, cannot be zero or less than zero")) } // check bucket name valid - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return "", probe.NewError(BucketNameInvalid{Bucket: bucket}) } @@ -344,7 +344,7 @@ func (fs Filesystem) CompleteMultipartUpload(bucket, object, uploadID string, da defer fs.lock.Unlock() // check bucket name valid - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return ObjectMetadata{}, probe.NewError(BucketNameInvalid{Bucket: bucket}) } @@ -446,7 +446,7 @@ func (fs Filesystem) ListObjectParts(bucket, object string, resources ObjectReso defer fs.lock.Unlock() // check bucket name valid - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return ObjectResourcesMetadata{}, probe.NewError(BucketNameInvalid{Bucket: bucket}) } @@ -515,7 +515,7 @@ func (fs Filesystem) AbortMultipartUpload(bucket, object, uploadID string) *prob defer fs.lock.Unlock() // check bucket name valid - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return probe.NewError(BucketNameInvalid{Bucket: bucket}) } diff --git a/pkg/fs/fs-object.go b/pkg/fs/fs-object.go index 1369db05b..7ed4cc430 100644 --- a/pkg/fs/fs-object.go +++ b/pkg/fs/fs-object.go @@ -43,7 +43,7 @@ func (fs Filesystem) GetObject(w io.Writer, bucket, object string, start, length defer fs.lock.Unlock() // validate bucket - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return 0, probe.NewError(BucketNameInvalid{Bucket: bucket}) } @@ -96,7 +96,7 @@ func (fs Filesystem) GetObjectMetadata(bucket, object string) (ObjectMetadata, * fs.lock.Lock() defer fs.lock.Unlock() - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return ObjectMetadata{}, probe.NewError(BucketNameInvalid{Bucket: bucket}) } @@ -182,7 +182,7 @@ func (fs Filesystem) CreateObject(bucket, object, expectedMD5Sum string, size in } // check bucket name valid - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return ObjectMetadata{}, probe.NewError(BucketNameInvalid{Bucket: bucket}) } // check bucket exists @@ -304,7 +304,7 @@ func (fs Filesystem) DeleteObject(bucket, object string) *probe.Error { defer fs.lock.Unlock() // check bucket name valid - if !IsValidBucket(bucket) { + if !IsValidBucketName(bucket) { return probe.NewError(BucketNameInvalid{Bucket: bucket}) }