From ae0b88f31957b67e13f078553dc6855f3d8a6b29 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Wed, 21 Jan 2015 15:20:35 -0800 Subject: [PATCH 1/3] Simplfying bucket naming convention --- pkg/storage/inmemory/inmemory.go | 35 +++++++------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/pkg/storage/inmemory/inmemory.go b/pkg/storage/inmemory/inmemory.go index 003a87d33..663870767 100644 --- a/pkg/storage/inmemory/inmemory.go +++ b/pkg/storage/inmemory/inmemory.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "log" + "regexp" "strings" "time" @@ -116,39 +117,17 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error) { } func isValidBucket(bucket string) bool { - l := len(bucket) - if l < 3 || l > 63 { + if len(bucket) < 3 || len(bucket) > 63 { return false } - - valid := false - prev := byte('.') - for i := 0; i < len(bucket); i++ { - c := bucket[i] - switch { - default: - return false - case 'a' <= c && c <= 'z': - valid = true - case '0' <= c && c <= '9': - // Is allowed, but bucketname can't be just numbers. - // Therefore, don't set valid to true - case c == '-': - if prev == '.' { - return false - } - case c == '.': - if prev == '.' || prev == '-' { - return false - } - } - prev = c + if bucket[0] == '.' || bucket[len(bucket)-1] == '.' { + return false } - - if prev == '-' || prev == '.' { + if match, _ := regexp.MatchString("\\.\\.", bucket); match == true { return false } - return valid + match, _ := regexp.MatchString("[a-zA-Z0-9\\.\\-]", bucket) + return match } func (storage *Storage) GetObjectMetadata(bucket, key string) mstorage.ObjectMetadata { From 856781b2a47dfb584ef6cfb5e55c6dee8428fe81 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Wed, 21 Jan 2015 15:22:15 -0800 Subject: [PATCH 2/3] Simplifying bucket name convention and making convention public --- pkg/storage/inmemory/inmemory.go | 17 +---------------- pkg/storage/storage.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/storage/inmemory/inmemory.go b/pkg/storage/inmemory/inmemory.go index 663870767..bdb146f8a 100644 --- a/pkg/storage/inmemory/inmemory.go +++ b/pkg/storage/inmemory/inmemory.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "log" - "regexp" "strings" "time" @@ -65,7 +64,7 @@ func (storage *Storage) StoreObject(bucket string, key string, data io.Reader) e } func (storage *Storage) StoreBucket(bucketName string) error { - if !isValidBucket(bucketName) { + if !mstorage.IsValidBucket(bucketName) { return mstorage.BucketNameInvalid{Bucket: bucketName} } @@ -116,20 +115,6 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error) { close(errorChannel) } -func isValidBucket(bucket string) bool { - if len(bucket) < 3 || len(bucket) > 63 { - return false - } - if bucket[0] == '.' || bucket[len(bucket)-1] == '.' { - return false - } - if match, _ := regexp.MatchString("\\.\\.", bucket); match == true { - return false - } - match, _ := regexp.MatchString("[a-zA-Z0-9\\.\\-]", bucket) - return match -} - func (storage *Storage) GetObjectMetadata(bucket, key string) mstorage.ObjectMetadata { objectKey := bucket + ":" + key diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index f02760789..0d4e7a719 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -18,6 +18,7 @@ package storage import ( "io" + "regexp" ) type Storage interface { @@ -43,3 +44,17 @@ type ObjectMetadata struct { Size int ETag string } + +func IsValidBucket(bucket string) bool { + if len(bucket) < 3 || len(bucket) > 63 { + return false + } + if bucket[0] == '.' || bucket[len(bucket)-1] == '.' { + return false + } + if match, _ := regexp.MatchString("\\.\\.", bucket); match == true { + return false + } + match, _ := regexp.MatchString("[a-zA-Z0-9\\.\\-]", bucket) + return match +} From 53a8536984709664594d653e89477bfcdc7ef6f5 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Wed, 21 Jan 2015 15:28:39 -0800 Subject: [PATCH 3/3] Fixing regex --- pkg/storage/storage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 0d4e7a719..9d56c2c19 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -55,6 +55,6 @@ func IsValidBucket(bucket string) bool { if match, _ := regexp.MatchString("\\.\\.", bucket); match == true { return false } - match, _ := regexp.MatchString("[a-zA-Z0-9\\.\\-]", bucket) + match, _ := regexp.MatchString("^[a-zA-Z][a-zA-Z0-9\\.\\-]+[a-zA-Z0-9]$", bucket) return match }