2019-07-08 23:32:18 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2021-11-12 20:47:41 +00:00
|
|
|
package buckets
|
2019-07-08 23:32:18 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-10-18 09:54:59 +01:00
|
|
|
"time"
|
2019-07-08 23:32:18 +01:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/macaroon"
|
|
|
|
"storj.io/common/storj"
|
2020-03-30 10:08:50 +01:00
|
|
|
"storj.io/common/uuid"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2019-07-08 23:32:18 +01:00
|
|
|
)
|
|
|
|
|
2021-10-18 09:54:59 +01:00
|
|
|
// Bucket contains minimal bucket fields for metainfo protocol.
|
|
|
|
type Bucket struct {
|
|
|
|
Name []byte
|
|
|
|
CreatedAt time.Time
|
|
|
|
}
|
|
|
|
|
2021-11-12 20:47:41 +00:00
|
|
|
// DB is the interface for the database to interact with buckets.
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Database
|
2021-11-12 20:47:41 +00:00
|
|
|
type DB interface {
|
|
|
|
// CreateBucket creates a new bucket
|
2019-07-08 23:32:18 +01:00
|
|
|
CreateBucket(ctx context.Context, bucket storj.Bucket) (_ storj.Bucket, err error)
|
2021-11-12 20:47:41 +00:00
|
|
|
// GetBucket returns an existing bucket
|
2019-07-08 23:32:18 +01:00
|
|
|
GetBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (bucket storj.Bucket, err error)
|
2021-10-27 09:50:27 +01:00
|
|
|
// GetBucketPlacement returns with the placement constraint identifier.
|
|
|
|
GetBucketPlacement(ctx context.Context, bucketName []byte, projectID uuid.UUID) (placement storj.PlacementConstraint, err error)
|
2021-10-18 09:54:59 +01:00
|
|
|
// GetMinimalBucket returns existing bucket with minimal number of fields.
|
|
|
|
GetMinimalBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (bucket Bucket, err error)
|
2021-04-02 17:19:17 +01:00
|
|
|
// HasBucket returns if a bucket exists.
|
|
|
|
HasBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (exists bool, err error)
|
2020-06-25 15:47:44 +01:00
|
|
|
// GetBucketID returns an existing bucket id.
|
2020-07-24 18:13:15 +01:00
|
|
|
GetBucketID(ctx context.Context, bucket metabase.BucketLocation) (id uuid.UUID, err error)
|
2019-07-19 16:17:34 +01:00
|
|
|
// UpdateBucket updates an existing bucket
|
|
|
|
UpdateBucket(ctx context.Context, bucket storj.Bucket) (_ storj.Bucket, err error)
|
2021-11-12 20:47:41 +00:00
|
|
|
// DeleteBucket deletes a bucket
|
2019-07-08 23:32:18 +01:00
|
|
|
DeleteBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (err error)
|
2021-11-12 20:47:41 +00:00
|
|
|
// ListBuckets returns all buckets for a project
|
2019-07-12 13:57:02 +01:00
|
|
|
ListBuckets(ctx context.Context, projectID uuid.UUID, listOpts storj.BucketListOptions, allowedBuckets macaroon.AllowedBuckets) (bucketList storj.BucketList, err error)
|
2020-06-30 22:49:29 +01:00
|
|
|
// CountBuckets returns the number of buckets a project currently has
|
|
|
|
CountBuckets(ctx context.Context, projectID uuid.UUID) (int, error)
|
2022-10-05 11:53:02 +01:00
|
|
|
// IterateBucketLocations iterates through all buckets from some point with limit.
|
|
|
|
IterateBucketLocations(ctx context.Context, projectID uuid.UUID, bucketName string, limit int, fn func([]metabase.BucketLocation) error) (err error)
|
2019-07-08 23:32:18 +01:00
|
|
|
}
|