storj/pkg/storage/buckets/store.go
Jess G f11bf46a11
Jg/1967 mv bucket metadata uplink (#2505)
* add bucketstore, add init uplink bucket

* update uplink to use bucket rpc

* fix tests

* wrap metainfo client errors

* add allowedBucket struct, fix tests

* update comment

* add paging

* updates per CR

* add test for pagination

* fix lint

* fix uplink test so its easier tyo understand

* fix gateway pagination bug

* changes per cr

* fix bug w/allowedBuckets, add test to catch
2019-07-12 08:57:02 -04:00

61 lines
1.7 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package buckets
import (
"context"
"gopkg.in/spacemonkeygo/monkit.v2"
"storj.io/storj/pkg/storj"
"storj.io/storj/uplink/metainfo"
)
var mon = monkit.Package()
// Store for buckets
type Store interface {
Create(ctx context.Context, bucket storj.Bucket) (_ storj.Bucket, err error)
Get(ctx context.Context, bucketName string) (_ storj.Bucket, err error)
Delete(ctx context.Context, bucketName string) (err error)
List(ctx context.Context, listOpts storj.BucketListOptions) (_ storj.BucketList, err error)
}
// BucketStore is an object to interact with buckets
// via the metainfo client
type BucketStore struct {
metainfoClient metainfo.Client
}
// NewStore creates a new bucket store
func NewStore(metainfoClient metainfo.Client) *BucketStore {
return &BucketStore{
metainfoClient: metainfoClient,
}
}
// Create creates a bucket
func (store *BucketStore) Create(ctx context.Context, bucket storj.Bucket) (_ storj.Bucket, err error) {
defer mon.Task()(&ctx)(&err)
return store.metainfoClient.CreateBucket(ctx, bucket)
}
// Get returns a bucket
func (store *BucketStore) Get(ctx context.Context, bucketName string) (_ storj.Bucket, err error) {
defer mon.Task()(&ctx)(&err)
return store.metainfoClient.GetBucket(ctx, bucketName)
}
// Delete deletes a bucket
func (store *BucketStore) Delete(ctx context.Context, bucketName string) (err error) {
defer mon.Task()(&ctx)(&err)
return store.metainfoClient.DeleteBucket(ctx, bucketName)
}
// List returns a list of buckets
func (store *BucketStore) List(ctx context.Context, listOpts storj.BucketListOptions) (_ storj.BucketList, err error) {
defer mon.Task()(&ctx)(&err)
return store.metainfoClient.ListBuckets(ctx, listOpts)
}