Merge pull request #1000 from harshavardhana/fs-bucket

bucketName: relax bucket names, now allow numbers as starting charact…
master
Harshavardhana 9 years ago
commit 06879b3b44
  1. 2
      object-handlers.go
  2. 9
      pkg/fs/definitions.go
  3. 2
      pkg/fs/fs-bucket-listobjects.go
  4. 10
      pkg/fs/fs-bucket.go
  5. 12
      pkg/fs/fs-multipart.go
  6. 8
      pkg/fs/fs-object.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
}

@ -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
}

@ -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 {

@ -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"]

@ -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})
}

@ -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})
}

Loading…
Cancel
Save