Simplifying bucket name convention and making convention public

master
Frederick F. Kautz IV 10 years ago
parent ae0b88f319
commit 856781b2a4
  1. 17
      pkg/storage/inmemory/inmemory.go
  2. 15
      pkg/storage/storage.go

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"io" "io"
"log" "log"
"regexp"
"strings" "strings"
"time" "time"
@ -65,7 +64,7 @@ func (storage *Storage) StoreObject(bucket string, key string, data io.Reader) e
} }
func (storage *Storage) StoreBucket(bucketName string) error { func (storage *Storage) StoreBucket(bucketName string) error {
if !isValidBucket(bucketName) { if !mstorage.IsValidBucket(bucketName) {
return mstorage.BucketNameInvalid{Bucket: bucketName} return mstorage.BucketNameInvalid{Bucket: bucketName}
} }
@ -116,20 +115,6 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error) {
close(errorChannel) 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 { func (storage *Storage) GetObjectMetadata(bucket, key string) mstorage.ObjectMetadata {
objectKey := bucket + ":" + key objectKey := bucket + ":" + key

@ -18,6 +18,7 @@ package storage
import ( import (
"io" "io"
"regexp"
) )
type Storage interface { type Storage interface {
@ -43,3 +44,17 @@ type ObjectMetadata struct {
Size int Size int
ETag string 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
}

Loading…
Cancel
Save