minio/pkg/storage/storage.go

96 lines
2.5 KiB
Go
Raw Normal View History

2015-01-21 02:16:06 -05:00
/*
2015-02-08 05:54:21 -05:00
* Mini Object Storage, (C) 2015 Minio, Inc.
2015-01-21 02:16:06 -05:00
*
* 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.
*/
package storage
import (
"io"
"regexp"
2015-01-21 20:12:47 -05:00
"time"
2015-02-27 22:42:04 -05:00
"unicode/utf8"
)
2015-01-21 15:44:09 -05:00
type Storage interface {
// Bucket Operations
ListBuckets() ([]BucketMetadata, error)
2015-01-21 15:44:09 -05:00
StoreBucket(bucket string) error
StoreBucketPolicy(bucket string, policy interface{}) error
GetBucketPolicy(bucket string) (interface{}, 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)
GetObjectMetadata(bucket string, object string) (ObjectMetadata, error)
2015-02-26 20:23:42 -05:00
ListObjects(bucket string, resources BucketResourcesMetadata) ([]ObjectMetadata, BucketResourcesMetadata, error)
StoreObject(bucket string, key string, contentType 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 {
Bucket string
Key string
ContentType string
Created time.Time
ETag string
Size int64
2015-01-20 21:39:30 -05:00
}
2015-02-26 20:23:42 -05:00
// Various types of bucket resources
type BucketResourcesMetadata struct {
Prefix string
Marker string
Maxkeys int
Delimiter string
IsTruncated bool
CommonPrefixes []string
Policy bool
// TODO
Logging string
Notification string
}
2015-03-03 05:36:12 -05:00
// Verify Bucket name in accordance with http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html
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
}
// We don't support buckets with '.' in them
match, _ := regexp.MatchString("^[a-zA-Z][a-zA-Z0-9\\-]+[a-zA-Z0-9]$", bucket)
return match
}
2015-03-03 05:36:12 -05:00
// Verify Object name in accordance with http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html
func IsValidObject(object string) bool {
2015-02-27 22:42:04 -05:00
if len(object) > 1024 || len(object) == 0 {
return false
}
2015-02-27 22:49:18 -05:00
if !utf8.ValidString(object) {
2015-02-27 22:42:04 -05:00
return false
}
return true
}