Simplfying bucket naming convention

master
Frederick F. Kautz IV 10 years ago
parent 06d06b8251
commit ae0b88f319
  1. 35
      pkg/storage/inmemory/inmemory.go

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"io" "io"
"log" "log"
"regexp"
"strings" "strings"
"time" "time"
@ -116,39 +117,17 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error) {
} }
func isValidBucket(bucket string) bool { func isValidBucket(bucket string) bool {
l := len(bucket) if len(bucket) < 3 || len(bucket) > 63 {
if l < 3 || l > 63 {
return false return false
} }
if bucket[0] == '.' || bucket[len(bucket)-1] == '.' {
valid := false return 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 match, _ := regexp.MatchString("\\.\\.", bucket); match == true {
if prev == '-' || prev == '.' {
return false return false
} }
return valid 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 {

Loading…
Cancel
Save