s3: Open() creates bucket if it does not exist

This commit is contained in:
Alexander Neumann 2015-12-19 13:26:42 +01:00
parent 248f991ad4
commit 5736742c3e
2 changed files with 2 additions and 15 deletions

View file

@ -57,7 +57,7 @@ func getConfig(region, bucket string) minio.Config {
return config return config
} }
// Open opens the S3 backend at bucket and region. // Open opens the S3 backend at bucket and region. The bucket is created if it does not exist yet.
func Open(regionname, bucketname string) (backend.Backend, error) { func Open(regionname, bucketname string) (backend.Backend, error) {
s3api, err := minio.New(getConfig(regionname, bucketname)) s3api, err := minio.New(getConfig(regionname, bucketname))
if err != nil { if err != nil {
@ -67,19 +67,6 @@ func Open(regionname, bucketname string) (backend.Backend, error) {
be := &S3Backend{s3api: s3api, bucketname: bucketname} be := &S3Backend{s3api: s3api, bucketname: bucketname}
be.createConnections() be.createConnections()
return be, nil
}
// Create creates a new bucket in the given region and opens the backend.
func Create(regionname, bucketname string) (backend.Backend, error) {
s3api, err := minio.New(getConfig(regionname, bucketname))
if err != nil {
return nil, err
}
be := &S3Backend{s3api: s3api, bucketname: bucketname}
be.createConnections()
err = s3api.MakeBucket(bucketname, "") err = s3api.MakeBucket(bucketname, "")
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -12,7 +12,7 @@ type deleter interface {
} }
func TestS3Backend(t *testing.T) { func TestS3Backend(t *testing.T) {
be, err := s3.Create("127.0.0.1:9000", "restictestbucket") be, err := s3.Open("127.0.0.1:9000", "restictestbucket")
OK(t, err) OK(t, err)
testBackend(be, t) testBackend(be, t)