2015-01-21 02:16:06 -05:00
|
|
|
/*
|
|
|
|
* Mini Object Storage, (C) 2014 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-11-29 17:42:22 -05:00
|
|
|
package storage
|
2015-01-18 16:31:22 -05:00
|
|
|
|
2015-01-18 19:10:48 -05:00
|
|
|
import (
|
|
|
|
"io"
|
2015-01-21 18:22:15 -05:00
|
|
|
"regexp"
|
2015-01-21 20:12:47 -05:00
|
|
|
"time"
|
2015-01-18 19:10:48 -05:00
|
|
|
)
|
2015-01-18 16:31:22 -05:00
|
|
|
|
2015-01-21 15:44:09 -05:00
|
|
|
type Storage interface {
|
|
|
|
// Bucket Operations
|
2015-01-25 18:35:08 -05:00
|
|
|
ListBuckets(prefix string) ([]BucketMetadata, error)
|
2015-01-21 15:44:09 -05:00
|
|
|
StoreBucket(bucket string) error
|
2015-01-20 21:39:30 -05:00
|
|
|
|
2015-01-21 15:44:09 -05:00
|
|
|
// Object Operations
|
|
|
|
CopyObjectToWriter(w io.Writer, bucket string, object string) (int64, error)
|
2015-01-25 18:35:08 -05:00
|
|
|
GetObjectMetadata(bucket string, object string) (ObjectMetadata, error)
|
|
|
|
ListObjects(bucket, prefix string, count int) ([]ObjectMetadata, bool, error)
|
2015-01-21 15:44:09 -05:00
|
|
|
StoreObject(bucket string, key string, data io.Reader) error
|
2015-01-21 03:50:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type BucketMetadata struct {
|
|
|
|
Name string
|
2015-01-21 20:12:47 -05:00
|
|
|
Created time.Time
|
2015-01-21 03:50:23 -05:00
|
|
|
}
|
|
|
|
|
2015-01-20 21:39:30 -05:00
|
|
|
type ObjectMetadata struct {
|
2015-01-24 18:35:01 -05:00
|
|
|
Bucket string
|
2015-01-21 20:12:47 -05:00
|
|
|
Key string
|
|
|
|
Created time.Time
|
|
|
|
Size int
|
|
|
|
ETag string
|
2015-01-20 21:39:30 -05:00
|
|
|
}
|
2015-01-21 18:22:15 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2015-01-21 18:28:39 -05:00
|
|
|
match, _ := regexp.MatchString("^[a-zA-Z][a-zA-Z0-9\\.\\-]+[a-zA-Z0-9]$", bucket)
|
2015-01-21 18:22:15 -05:00
|
|
|
return match
|
|
|
|
}
|