satellite/buckets: move Bucket definition
Move Bucket struct definition. Updates https://github.com/storj/storj/issues/5291 Change-Id: I6bfc5ce287793ea479f2cb8b17878ba3cf6b63e0
This commit is contained in:
parent
54ef1c8ca2
commit
eecb055dfd
@ -64,7 +64,7 @@ func (server *Server) updateBucket(w http.ResponseWriter, r *http.Request, place
|
||||
|
||||
b, err := server.buckets.GetBucket(ctx, bucket, project.UUID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
sendJSONError(w, "bucket does not exist", "", http.StatusBadRequest)
|
||||
} else {
|
||||
sendJSONError(w, "unable to create geofence for bucket", err.Error(), http.StatusInternalServerError)
|
||||
@ -77,7 +77,7 @@ func (server *Server) updateBucket(w http.ResponseWriter, r *http.Request, place
|
||||
_, err = server.buckets.UpdateBucket(ctx, b)
|
||||
if err != nil {
|
||||
switch {
|
||||
case storj.ErrBucketNotFound.Has(err):
|
||||
case buckets.ErrBucketNotFound.Has(err):
|
||||
sendJSONError(w, "bucket does not exist", "", http.StatusBadRequest)
|
||||
case buckets.ErrBucketNotEmpty.Has(err):
|
||||
sendJSONError(w, "bucket must be empty", "", http.StatusBadRequest)
|
||||
@ -115,7 +115,7 @@ func (server *Server) getBucketInfo(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
b, err := server.buckets.GetBucket(ctx, bucket, project.UUID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
sendJSONError(w, "bucket does not exist", "", http.StatusNotFound)
|
||||
} else {
|
||||
sendJSONError(w, "unable to check bucket", err.Error(), http.StatusInternalServerError)
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
)
|
||||
|
||||
func TestAdminBucketGeofenceAPI(t *testing.T) {
|
||||
@ -39,7 +40,7 @@ func TestAdminBucketGeofenceAPI(t *testing.T) {
|
||||
err = uplink.CreateBucket(ctx, sat, "filled")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = sat.DB.Buckets().UpdateBucket(ctx, storj.Bucket{
|
||||
_, err = sat.DB.Buckets().UpdateBucket(ctx, buckets.Bucket{
|
||||
Name: "filled",
|
||||
ProjectID: project.ID,
|
||||
Placement: storj.EEA,
|
||||
@ -96,7 +97,7 @@ func TestAdminBucketGeofenceAPI(t *testing.T) {
|
||||
b, err := sat.DB.Buckets().GetBucket(ctx, testCase.bucket, testCase.project)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected, err := json.Marshal(storj.Bucket{
|
||||
expected, err := json.Marshal(buckets.Bucket{
|
||||
ID: b.ID,
|
||||
Name: b.Name,
|
||||
ProjectID: testCase.project,
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"storj.io/common/memory"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/payments/stripe"
|
||||
)
|
||||
@ -464,7 +465,7 @@ func (server *Server) deleteProject(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
options := storj.BucketListOptions{Limit: 1, Direction: storj.Forward}
|
||||
options := buckets.ListOptions{Limit: 1, Direction: storj.Forward}
|
||||
buckets, err := server.buckets.ListBuckets(ctx, projectUUID, options, macaroon.AllowedBuckets{All: true})
|
||||
if err != nil {
|
||||
sendJSONError(w, "unable to list buckets",
|
||||
@ -580,7 +581,7 @@ func (server *Server) checkUsage(ctx context.Context, w http.ResponseWriter, pro
|
||||
return server.checkInvoicing(ctx, w, projectID)
|
||||
}
|
||||
|
||||
func bucketNames(buckets []storj.Bucket) []string {
|
||||
func bucketNames(buckets []buckets.Bucket) []string {
|
||||
var xs []string
|
||||
for _, b := range buckets {
|
||||
xs = append(xs, b.Name)
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite"
|
||||
"storj.io/storj/satellite/accounting"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/payments/stripe"
|
||||
)
|
||||
@ -307,7 +308,7 @@ func TestProjectDelete(t *testing.T) {
|
||||
projectID := planet.Uplinks[0].Projects[0].ID
|
||||
|
||||
// Ensure there are no buckets left
|
||||
buckets, err := planet.Satellites[0].API.Buckets.Service.ListBuckets(ctx, projectID, storj.BucketListOptions{Limit: 1, Direction: storj.Forward}, macaroon.AllowedBuckets{All: true})
|
||||
buckets, err := planet.Satellites[0].API.Buckets.Service.ListBuckets(ctx, projectID, buckets.ListOptions{Limit: 1, Direction: storj.Forward}, macaroon.AllowedBuckets{All: true})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, buckets.Items, 0)
|
||||
|
||||
|
@ -7,40 +7,94 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/common/macaroon"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/storj/satellite/metabase"
|
||||
)
|
||||
|
||||
// Bucket contains minimal bucket fields for metainfo protocol.
|
||||
var (
|
||||
// ErrBucket is an error class for general bucket errors.
|
||||
ErrBucket = errs.Class("bucket")
|
||||
|
||||
// ErrNoBucket is an error class for using empty bucket name.
|
||||
ErrNoBucket = errs.Class("no bucket specified")
|
||||
|
||||
// ErrBucketNotFound is an error class for non-existing bucket.
|
||||
ErrBucketNotFound = errs.Class("bucket not found")
|
||||
)
|
||||
|
||||
// Bucket contains information about a specific bucket.
|
||||
type Bucket struct {
|
||||
ID uuid.UUID
|
||||
Name string
|
||||
ProjectID uuid.UUID
|
||||
PartnerID uuid.UUID
|
||||
UserAgent []byte
|
||||
Created time.Time
|
||||
PathCipher storj.CipherSuite
|
||||
DefaultSegmentsSize int64
|
||||
DefaultRedundancyScheme storj.RedundancyScheme
|
||||
DefaultEncryptionParameters storj.EncryptionParameters
|
||||
Placement storj.PlacementConstraint
|
||||
}
|
||||
|
||||
// MinimalBucket contains minimal bucket fields for metainfo protocol.
|
||||
type MinimalBucket struct {
|
||||
Name []byte
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// ListOptions lists objects.
|
||||
type ListOptions struct {
|
||||
Cursor string
|
||||
Direction storj.ListDirection
|
||||
Limit int
|
||||
}
|
||||
|
||||
// NextPage returns options for listing the next page.
|
||||
func (opts ListOptions) NextPage(list List) ListOptions {
|
||||
if !list.More || len(list.Items) == 0 {
|
||||
return ListOptions{}
|
||||
}
|
||||
|
||||
return ListOptions{
|
||||
Cursor: list.Items[len(list.Items)-1].Name,
|
||||
Direction: storj.After,
|
||||
Limit: opts.Limit,
|
||||
}
|
||||
}
|
||||
|
||||
// List is a list of buckets.
|
||||
type List struct {
|
||||
More bool
|
||||
Items []Bucket
|
||||
}
|
||||
|
||||
// DB is the interface for the database to interact with buckets.
|
||||
//
|
||||
// architecture: Database
|
||||
type DB interface {
|
||||
// CreateBucket creates a new bucket
|
||||
CreateBucket(ctx context.Context, bucket storj.Bucket) (_ storj.Bucket, err error)
|
||||
CreateBucket(ctx context.Context, bucket Bucket) (_ Bucket, err error)
|
||||
// GetBucket returns an existing bucket
|
||||
GetBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (bucket storj.Bucket, err error)
|
||||
GetBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (bucket Bucket, err error)
|
||||
// GetBucketPlacement returns with the placement constraint identifier.
|
||||
GetBucketPlacement(ctx context.Context, bucketName []byte, projectID uuid.UUID) (placement storj.PlacementConstraint, err error)
|
||||
// GetMinimalBucket returns existing bucket with minimal number of fields.
|
||||
GetMinimalBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (bucket Bucket, err error)
|
||||
GetMinimalBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (bucket MinimalBucket, err error)
|
||||
// HasBucket returns if a bucket exists.
|
||||
HasBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (exists bool, err error)
|
||||
// GetBucketID returns an existing bucket id.
|
||||
GetBucketID(ctx context.Context, bucket metabase.BucketLocation) (id uuid.UUID, err error)
|
||||
// UpdateBucket updates an existing bucket
|
||||
UpdateBucket(ctx context.Context, bucket storj.Bucket) (_ storj.Bucket, err error)
|
||||
UpdateBucket(ctx context.Context, bucket Bucket) (_ Bucket, err error)
|
||||
// DeleteBucket deletes a bucket
|
||||
DeleteBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (err error)
|
||||
// ListBuckets returns all buckets for a project
|
||||
ListBuckets(ctx context.Context, projectID uuid.UUID, listOpts storj.BucketListOptions, allowedBuckets macaroon.AllowedBuckets) (bucketList storj.BucketList, err error)
|
||||
ListBuckets(ctx context.Context, projectID uuid.UUID, listOpts ListOptions, allowedBuckets macaroon.AllowedBuckets) (bucketList List, err error)
|
||||
// CountBuckets returns the number of buckets a project currently has
|
||||
CountBuckets(ctx context.Context, projectID uuid.UUID) (int, error)
|
||||
// IterateBucketLocations iterates through all buckets from some point with limit.
|
||||
|
@ -16,12 +16,13 @@ import (
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/metabase"
|
||||
)
|
||||
|
||||
func newTestBucket(name string, projectID uuid.UUID) storj.Bucket {
|
||||
return storj.Bucket{
|
||||
func newTestBucket(name string, projectID uuid.UUID) buckets.Bucket {
|
||||
return buckets.Bucket{
|
||||
ID: testrand.UUID(),
|
||||
Name: name,
|
||||
ProjectID: projectID,
|
||||
@ -82,7 +83,7 @@ func TestBasicBucketOperations(t *testing.T) {
|
||||
require.False(t, minimalBucket.CreatedAt.IsZero())
|
||||
|
||||
_, err = bucketsDB.GetMinimalBucket(ctx, []byte("not-existing-bucket"), project.ID)
|
||||
require.True(t, storj.ErrBucketNotFound.Has(err), err)
|
||||
require.True(t, buckets.ErrBucketNotFound.Has(err), err)
|
||||
|
||||
// GetBucketPlacement
|
||||
placement, err := bucketsDB.GetBucketPlacement(ctx, []byte("testbucket"), project.ID)
|
||||
@ -90,7 +91,7 @@ func TestBasicBucketOperations(t *testing.T) {
|
||||
require.Equal(t, expectedBucket.Placement, placement)
|
||||
|
||||
_, err = bucketsDB.GetBucketPlacement(ctx, []byte("not-existing-bucket"), project.ID)
|
||||
require.True(t, storj.ErrBucketNotFound.Has(err), err)
|
||||
require.True(t, buckets.ErrBucketNotFound.Has(err), err)
|
||||
|
||||
// CountBuckets
|
||||
count, err = bucketsDB.CountBuckets(ctx, project.ID)
|
||||
@ -155,7 +156,7 @@ func TestListBucketsAllAllowed(t *testing.T) {
|
||||
tt := tt // avoid scopelint error
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
listOpts := storj.BucketListOptions{
|
||||
listOpts := buckets.ListOptions{
|
||||
Cursor: tt.cursor,
|
||||
Direction: storj.Forward,
|
||||
Limit: tt.limit,
|
||||
@ -212,7 +213,7 @@ func TestListBucketsNotAllowed(t *testing.T) {
|
||||
|
||||
for _, tt := range testCases {
|
||||
tt := tt // avoid scopelint error
|
||||
listOpts := storj.BucketListOptions{
|
||||
listOpts := buckets.ListOptions{
|
||||
Cursor: tt.cursor,
|
||||
Direction: storj.Forward,
|
||||
Limit: tt.limit,
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/common/storj"
|
||||
"storj.io/storj/satellite/metabase"
|
||||
)
|
||||
|
||||
@ -34,10 +33,10 @@ type Service struct {
|
||||
// UpdateBucket overrides the default UpdateBucket behaviour by adding a check against MetabaseDB to ensure the bucket
|
||||
// is empty before attempting to change the placement constraint of a bucket. If the placement constraint is not being
|
||||
// changed, then this additional check is skipped.
|
||||
func (buckets *Service) UpdateBucket(ctx context.Context, bucket storj.Bucket) (storj.Bucket, error) {
|
||||
func (buckets *Service) UpdateBucket(ctx context.Context, bucket Bucket) (Bucket, error) {
|
||||
current, err := buckets.GetBucket(ctx, []byte(bucket.Name), bucket.ProjectID)
|
||||
if err != nil {
|
||||
return storj.Bucket{}, err
|
||||
return Bucket{}, err
|
||||
}
|
||||
|
||||
if current.Placement != bucket.Placement {
|
||||
@ -48,9 +47,9 @@ func (buckets *Service) UpdateBucket(ctx context.Context, bucket storj.Bucket) (
|
||||
|
||||
switch {
|
||||
case err != nil:
|
||||
return storj.Bucket{}, err
|
||||
return Bucket{}, err
|
||||
case !ok:
|
||||
return storj.Bucket{}, ErrBucketNotEmpty.New("cannot modify placement constraint for non-empty bucket")
|
||||
return Bucket{}, ErrBucketNotEmpty.New("cannot modify placement constraint for non-empty bucket")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,13 +13,14 @@ import (
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
func TestUsers(t *testing.T) {
|
||||
testplanet.Run(t, testplanet.Config{SatelliteCount: 1}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||
sat := planet.Satellites[0]
|
||||
buckets := sat.API.Buckets.Service
|
||||
bucketService := sat.API.Buckets.Service
|
||||
db := sat.DB
|
||||
consoleDB := db.Console()
|
||||
|
||||
@ -65,7 +66,7 @@ func TestUsers(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// create a bucket with no partnerID
|
||||
_, err = buckets.CreateBucket(ctx, storj.Bucket{
|
||||
_, err = bucketService.CreateBucket(ctx, buckets.Bucket{
|
||||
ID: testrand.UUID(),
|
||||
Name: "testbucket",
|
||||
ProjectID: proj.ID,
|
||||
@ -76,7 +77,7 @@ func TestUsers(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// update a bucket with partnerID
|
||||
bucket, err := buckets.UpdateBucket(ctx, storj.Bucket{
|
||||
bucket, err := bucketService.UpdateBucket(ctx, buckets.Bucket{
|
||||
ID: testrand.UUID(),
|
||||
Name: "testbucket",
|
||||
ProjectID: proj.ID,
|
||||
@ -88,7 +89,7 @@ func TestUsers(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, proj.ID, bucket.PartnerID)
|
||||
|
||||
bucket, err = buckets.GetBucket(ctx, []byte("testbucket"), proj.ID)
|
||||
bucket, err = bucketService.GetBucket(ctx, []byte("testbucket"), proj.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, proj.ID, bucket.PartnerID)
|
||||
})
|
||||
|
@ -13,11 +13,11 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
@ -45,13 +45,13 @@ func Test_AllBucketNames(t *testing.T) {
|
||||
project, err := sat.AddProject(ctx, user.ID, "buckettest")
|
||||
require.NoError(t, err)
|
||||
|
||||
bucket1 := storj.Bucket{
|
||||
bucket1 := buckets.Bucket{
|
||||
ID: testrand.UUID(),
|
||||
Name: "testBucket1",
|
||||
ProjectID: project.ID,
|
||||
}
|
||||
|
||||
bucket2 := storj.Bucket{
|
||||
bucket2 := buckets.Bucket{
|
||||
ID: testrand.UUID(),
|
||||
Name: "testBucket2",
|
||||
ProjectID: project.ID,
|
||||
|
@ -2485,7 +2485,7 @@ func (s *Service) GetAllBucketNames(ctx context.Context, projectID uuid.UUID) (_
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
|
||||
listOptions := storj.BucketListOptions{
|
||||
listOptions := buckets.ListOptions{
|
||||
Direction: storj.Forward,
|
||||
}
|
||||
|
||||
|
@ -21,13 +21,13 @@ import (
|
||||
"storj.io/common/currency"
|
||||
"storj.io/common/macaroon"
|
||||
"storj.io/common/memory"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/storj/private/blockchain"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/payments"
|
||||
"storj.io/storj/satellite/payments/coinpayments"
|
||||
@ -380,13 +380,13 @@ func TestService(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("GetAllBucketNames", func(t *testing.T) {
|
||||
bucket1 := storj.Bucket{
|
||||
bucket1 := buckets.Bucket{
|
||||
ID: testrand.UUID(),
|
||||
Name: "testBucket1",
|
||||
ProjectID: up2Pro1.ID,
|
||||
}
|
||||
|
||||
bucket2 := storj.Bucket{
|
||||
bucket2 := buckets.Bucket{
|
||||
ID: testrand.UUID(),
|
||||
Name: "testBucket2",
|
||||
ProjectID: up2Pro1.ID,
|
||||
|
@ -12,11 +12,11 @@ import (
|
||||
"storj.io/common/errs2"
|
||||
"storj.io/common/pb"
|
||||
"storj.io/common/rpc/rpcstatus"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/useragent"
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/drpc/drpccache"
|
||||
"storj.io/storj/satellite/attribution"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
@ -142,7 +142,7 @@ func (endpoint *Endpoint) tryUpdateBucketAttribution(ctx context.Context, header
|
||||
// checks if bucket exists before updates it or makes a new entry
|
||||
bucket, err := endpoint.buckets.GetBucket(ctx, bucketName, projectID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return rpcstatus.Errorf(rpcstatus.NotFound, "bucket %q does not exist", bucketName)
|
||||
}
|
||||
endpoint.log.Error("error while getting bucket", zap.ByteString("bucketName", bucketName), zap.Error(err))
|
||||
|
@ -38,7 +38,7 @@ func (endpoint *Endpoint) GetBucket(ctx context.Context, req *pb.BucketGetReques
|
||||
|
||||
bucket, err := endpoint.buckets.GetMinimalBucket(ctx, req.GetName(), keyInfo.ProjectID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return nil, rpcstatus.Error(rpcstatus.NotFound, err.Error())
|
||||
}
|
||||
endpoint.log.Error("internal", zap.Error(err))
|
||||
@ -46,7 +46,7 @@ func (endpoint *Endpoint) GetBucket(ctx context.Context, req *pb.BucketGetReques
|
||||
}
|
||||
|
||||
// override RS to fit satellite settings
|
||||
convBucket, err := convertBucketToProto(bucket, endpoint.defaultRS, endpoint.config.MaxSegmentSize)
|
||||
convBucket, err := convertMinimalBucketToProto(bucket, endpoint.defaultRS, endpoint.config.MaxSegmentSize)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@ -123,7 +123,7 @@ func (endpoint *Endpoint) CreateBucket(ctx context.Context, req *pb.BucketCreate
|
||||
}
|
||||
|
||||
// override RS to fit satellite settings
|
||||
convBucket, err := convertBucketToProto(buckets.Bucket{
|
||||
convBucket, err := convertMinimalBucketToProto(buckets.MinimalBucket{
|
||||
Name: []byte(bucket.Name),
|
||||
CreatedAt: bucket.Created,
|
||||
}, endpoint.defaultRS, endpoint.config.MaxSegmentSize)
|
||||
@ -184,20 +184,20 @@ func (endpoint *Endpoint) DeleteBucket(ctx context.Context, req *pb.BucketDelete
|
||||
}
|
||||
|
||||
var (
|
||||
bucket buckets.Bucket
|
||||
bucket buckets.MinimalBucket
|
||||
convBucket *pb.Bucket
|
||||
)
|
||||
if canRead || canList {
|
||||
// Info about deleted bucket is returned only if either Read, or List permission is granted.
|
||||
bucket, err = endpoint.buckets.GetMinimalBucket(ctx, req.Name, keyInfo.ProjectID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return nil, rpcstatus.Error(rpcstatus.NotFound, err.Error())
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
convBucket, err = convertBucketToProto(bucket, endpoint.defaultRS, endpoint.config.MaxSegmentSize)
|
||||
convBucket, err = convertMinimalBucketToProto(bucket, endpoint.defaultRS, endpoint.config.MaxSegmentSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -222,7 +222,7 @@ func (endpoint *Endpoint) DeleteBucket(ctx context.Context, req *pb.BucketDelete
|
||||
|
||||
return &pb.BucketDeleteResponse{Bucket: convBucket, DeletedObjectsCount: deletedObjCount}, nil
|
||||
}
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return &pb.BucketDeleteResponse{Bucket: convBucket}, nil
|
||||
}
|
||||
endpoint.log.Error("internal", zap.Error(err))
|
||||
@ -270,7 +270,7 @@ func (endpoint *Endpoint) deleteBucketNotEmpty(ctx context.Context, projectID uu
|
||||
if ErrBucketNotEmpty.Has(err) {
|
||||
return nil, deletedCount, rpcstatus.Error(rpcstatus.FailedPrecondition, "cannot delete the bucket because it's being used by another process")
|
||||
}
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return bucketName, 0, nil
|
||||
}
|
||||
endpoint.log.Error("internal", zap.Error(err))
|
||||
@ -318,7 +318,7 @@ func (endpoint *Endpoint) ListBuckets(ctx context.Context, req *pb.BucketListReq
|
||||
return nil, err
|
||||
}
|
||||
|
||||
listOpts := storj.BucketListOptions{
|
||||
listOpts := buckets.ListOptions{
|
||||
Cursor: string(req.Cursor),
|
||||
Limit: int(req.Limit),
|
||||
Direction: storj.ListDirection(req.Direction),
|
||||
@ -365,10 +365,10 @@ func getAllowedBuckets(ctx context.Context, header *pb.RequestHeader, action mac
|
||||
return allowedBuckets, err
|
||||
}
|
||||
|
||||
func convertProtoToBucket(req *pb.BucketCreateRequest, projectID uuid.UUID) (bucket storj.Bucket, err error) {
|
||||
func convertProtoToBucket(req *pb.BucketCreateRequest, projectID uuid.UUID) (bucket buckets.Bucket, err error) {
|
||||
bucketID, err := uuid.New()
|
||||
if err != nil {
|
||||
return storj.Bucket{}, err
|
||||
return buckets.Bucket{}, err
|
||||
}
|
||||
|
||||
// TODO: resolve partner id
|
||||
@ -381,7 +381,7 @@ func convertProtoToBucket(req *pb.BucketCreateRequest, projectID uuid.UUID) (buc
|
||||
return bucket, errs.New("Invalid uuid")
|
||||
}
|
||||
|
||||
return storj.Bucket{
|
||||
return buckets.Bucket{
|
||||
ID: bucketID,
|
||||
Name: string(req.GetName()),
|
||||
ProjectID: projectID,
|
||||
@ -389,7 +389,7 @@ func convertProtoToBucket(req *pb.BucketCreateRequest, projectID uuid.UUID) (buc
|
||||
}, nil
|
||||
}
|
||||
|
||||
func convertBucketToProto(bucket buckets.Bucket, rs *pb.RedundancyScheme, maxSegmentSize memory.Size) (pbBucket *pb.Bucket, err error) {
|
||||
func convertMinimalBucketToProto(bucket buckets.MinimalBucket, rs *pb.RedundancyScheme, maxSegmentSize memory.Size) (pbBucket *pb.Bucket, err error) {
|
||||
if len(bucket.Name) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/uplink"
|
||||
"storj.io/uplink/private/metaclient"
|
||||
)
|
||||
@ -42,14 +43,14 @@ func TestBucketExistenceCheck(t *testing.T) {
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.True(t, errs2.IsRPC(err, rpcstatus.NotFound))
|
||||
require.Equal(t, storj.ErrBucketNotFound.New("%s", "non-existing-bucket").Error(), errs.Unwrap(err).Error())
|
||||
require.Equal(t, buckets.ErrBucketNotFound.New("%s", "non-existing-bucket").Error(), errs.Unwrap(err).Error())
|
||||
|
||||
_, _, err = metainfoClient.ListObjects(ctx, metaclient.ListObjectsParams{
|
||||
Bucket: []byte("non-existing-bucket"),
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.True(t, errs2.IsRPC(err, rpcstatus.NotFound))
|
||||
require.Equal(t, storj.ErrBucketNotFound.New("%s", "non-existing-bucket").Error(), errs.Unwrap(err).Error())
|
||||
require.Equal(t, buckets.ErrBucketNotFound.New("%s", "non-existing-bucket").Error(), errs.Unwrap(err).Error())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"storj.io/common/rpc/rpcstatus"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/internalpb"
|
||||
"storj.io/storj/satellite/metabase"
|
||||
"storj.io/storj/satellite/metainfo/piecedeletion"
|
||||
@ -86,7 +87,7 @@ func (endpoint *Endpoint) BeginObject(ctx context.Context, req *pb.ObjectBeginRe
|
||||
// TODO this needs to be optimized to avoid DB call on each request
|
||||
placement, err := endpoint.buckets.GetBucketPlacement(ctx, req.Bucket, keyInfo.ProjectID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return nil, rpcstatus.Errorf(rpcstatus.NotFound, "bucket not found: %s", req.Bucket)
|
||||
}
|
||||
endpoint.log.Error("unable to check bucket", zap.Error(err))
|
||||
@ -767,7 +768,7 @@ func (endpoint *Endpoint) ListObjects(ctx context.Context, req *pb.ObjectListReq
|
||||
// TODO this needs to be optimized to avoid DB call on each request
|
||||
placement, err := endpoint.buckets.GetBucketPlacement(ctx, req.Bucket, keyInfo.ProjectID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return nil, rpcstatus.Errorf(rpcstatus.NotFound, "bucket not found: %s", req.Bucket)
|
||||
}
|
||||
endpoint.log.Error("unable to check bucket", zap.Error(err))
|
||||
@ -905,7 +906,7 @@ func (endpoint *Endpoint) ListPendingObjectStreams(ctx context.Context, req *pb.
|
||||
|
||||
placement, err := endpoint.buckets.GetBucketPlacement(ctx, req.Bucket, keyInfo.ProjectID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return nil, rpcstatus.Errorf(rpcstatus.NotFound, "bucket not found: %s", req.Bucket)
|
||||
}
|
||||
endpoint.log.Error("unable to check bucket", zap.Error(err))
|
||||
@ -1598,7 +1599,7 @@ func (endpoint *Endpoint) BeginMoveObject(ctx context.Context, req *pb.ObjectBeg
|
||||
// TODO we may try to combine those two DB calls into single one
|
||||
oldBucketPlacement, err := endpoint.buckets.GetBucketPlacement(ctx, req.Bucket, keyInfo.ProjectID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return nil, rpcstatus.Errorf(rpcstatus.NotFound, "bucket not found: %s", req.Bucket)
|
||||
}
|
||||
endpoint.log.Error("unable to check bucket", zap.Error(err))
|
||||
@ -1606,7 +1607,7 @@ func (endpoint *Endpoint) BeginMoveObject(ctx context.Context, req *pb.ObjectBeg
|
||||
}
|
||||
newBucketPlacement, err := endpoint.buckets.GetBucketPlacement(ctx, req.NewBucket, keyInfo.ProjectID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return nil, rpcstatus.Errorf(rpcstatus.NotFound, "bucket not found: %s", req.NewBucket)
|
||||
}
|
||||
endpoint.log.Error("unable to check bucket", zap.Error(err))
|
||||
@ -1821,7 +1822,7 @@ func (endpoint *Endpoint) BeginCopyObject(ctx context.Context, req *pb.ObjectBeg
|
||||
// TODO we may try to combine those two DB calls into single one
|
||||
oldBucketPlacement, err := endpoint.buckets.GetBucketPlacement(ctx, req.Bucket, keyInfo.ProjectID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return nil, rpcstatus.Errorf(rpcstatus.NotFound, "bucket not found: %s", req.Bucket)
|
||||
}
|
||||
endpoint.log.Error("unable to check bucket", zap.Error(err))
|
||||
@ -1829,7 +1830,7 @@ func (endpoint *Endpoint) BeginCopyObject(ctx context.Context, req *pb.ObjectBeg
|
||||
}
|
||||
newBucketPlacement, err := endpoint.buckets.GetBucketPlacement(ctx, req.NewBucket, keyInfo.ProjectID)
|
||||
if err != nil {
|
||||
if storj.ErrBucketNotFound.Has(err) {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return nil, rpcstatus.Errorf(rpcstatus.NotFound, "bucket not found: %s", req.NewBucket)
|
||||
}
|
||||
endpoint.log.Error("unable to check bucket", zap.Error(err))
|
||||
|
@ -856,15 +856,15 @@ func TestEndpoint_Object_With_StorageNodes(t *testing.T) {
|
||||
t.Run("begin commit", func(t *testing.T) {
|
||||
defer ctx.Check(deleteBucket(bucketName))
|
||||
|
||||
buckets := planet.Satellites[0].API.Buckets.Service
|
||||
bucketsService := planet.Satellites[0].API.Buckets.Service
|
||||
|
||||
bucket := storj.Bucket{
|
||||
bucket := buckets.Bucket{
|
||||
Name: bucketName,
|
||||
ProjectID: planet.Uplinks[0].Projects[0].ID,
|
||||
Placement: storj.EU,
|
||||
}
|
||||
|
||||
_, err := buckets.CreateBucket(ctx, bucket)
|
||||
_, err := bucketsService.CreateBucket(ctx, bucket)
|
||||
require.NoError(t, err)
|
||||
|
||||
params := metaclient.BeginObjectParams{
|
||||
@ -1264,14 +1264,14 @@ func TestEndpoint_Object_With_StorageNodes(t *testing.T) {
|
||||
|
||||
apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()]
|
||||
fmt.Println(apiKey)
|
||||
buckets := planet.Satellites[0].API.Buckets.Service
|
||||
bucketsService := planet.Satellites[0].API.Buckets.Service
|
||||
|
||||
bucket := storj.Bucket{
|
||||
bucket := buckets.Bucket{
|
||||
Name: bucketName,
|
||||
ProjectID: planet.Uplinks[0].Projects[0].ID,
|
||||
Placement: storj.EU,
|
||||
}
|
||||
_, err := buckets.CreateBucket(ctx, bucket)
|
||||
_, err := bucketsService.CreateBucket(ctx, bucket)
|
||||
require.NoError(t, err)
|
||||
|
||||
// this should be bigger than the max inline segment
|
||||
@ -1518,13 +1518,13 @@ func TestMoveObject_Geofencing(t *testing.T) {
|
||||
)
|
||||
}
|
||||
|
||||
func createGeofencedBucket(t *testing.T, ctx *testcontext.Context, buckets *buckets.Service, projectID uuid.UUID, bucketName string, placement storj.PlacementConstraint) {
|
||||
func createGeofencedBucket(t *testing.T, ctx *testcontext.Context, service *buckets.Service, projectID uuid.UUID, bucketName string, placement storj.PlacementConstraint) {
|
||||
// generate the bucket id
|
||||
bucketID, err := uuid.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
// create the bucket
|
||||
_, err = buckets.CreateBucket(ctx, storj.Bucket{
|
||||
_, err = service.CreateBucket(ctx, buckets.Bucket{
|
||||
ID: bucketID,
|
||||
Name: bucketName,
|
||||
ProjectID: projectID,
|
||||
@ -1533,7 +1533,7 @@ func createGeofencedBucket(t *testing.T, ctx *testcontext.Context, buckets *buck
|
||||
require.NoError(t, err)
|
||||
|
||||
// check that the bucket placement is correct
|
||||
bucket, err := buckets.GetBucket(ctx, []byte(bucketName), projectID)
|
||||
bucket, err := service.GetBucket(ctx, []byte(bucketName), projectID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, placement, bucket.Placement)
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/metabase"
|
||||
"storj.io/uplink/private/metaclient"
|
||||
)
|
||||
@ -835,8 +836,8 @@ func TestCommitSegment_RejectRetryDuplicate(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func createTestBucket(ctx context.Context, tb testing.TB, planet *testplanet.Planet) storj.Bucket {
|
||||
bucket, err := planet.Satellites[0].API.Buckets.Service.CreateBucket(ctx, storj.Bucket{
|
||||
func createTestBucket(ctx context.Context, tb testing.TB, planet *testplanet.Planet) buckets.Bucket {
|
||||
bucket, err := planet.Satellites[0].API.Buckets.Service.CreateBucket(ctx, buckets.Bucket{
|
||||
Name: "test",
|
||||
ProjectID: planet.Uplinks[0].Projects[0].ID,
|
||||
})
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/storj/satellite/accounting"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/console/consoleauth"
|
||||
"storj.io/storj/satellite/metabase"
|
||||
@ -250,7 +251,7 @@ func (endpoint *Endpoint) validateBucket(ctx context.Context, bucket []byte) (er
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if len(bucket) == 0 {
|
||||
return Error.Wrap(storj.ErrNoBucket.New(""))
|
||||
return Error.Wrap(buckets.ErrNoBucket.New(""))
|
||||
}
|
||||
|
||||
if len(bucket) < 3 || len(bucket) > 63 {
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/oidc"
|
||||
"storj.io/uplink"
|
||||
@ -138,7 +139,7 @@ func TestOIDC(t *testing.T) {
|
||||
bucketID, err := uuid.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
bucket, err := sat.API.Buckets.Service.CreateBucket(authed, storj.Bucket{
|
||||
bucket, err := sat.API.Buckets.Service.CreateBucket(authed, buckets.Bucket{
|
||||
ID: bucketID,
|
||||
Name: "test",
|
||||
ProjectID: project.ID,
|
||||
|
@ -19,7 +19,6 @@ import (
|
||||
"storj.io/common/currency"
|
||||
"storj.io/common/memory"
|
||||
"storj.io/common/pb"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/common/uuid"
|
||||
@ -27,6 +26,7 @@ import (
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite"
|
||||
"storj.io/storj/satellite/accounting"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/metabase"
|
||||
"storj.io/storj/satellite/payments"
|
||||
@ -609,7 +609,7 @@ func TestProjectUsagePrice(t *testing.T) {
|
||||
project, err := sat.AddProject(ctx, user.ID, "testproject")
|
||||
require.NoError(t, err)
|
||||
|
||||
bucket, err := sat.DB.Buckets().CreateBucket(ctx, storj.Bucket{
|
||||
bucket, err := sat.DB.Buckets().CreateBucket(ctx, buckets.Bucket{
|
||||
ID: testrand.UUID(),
|
||||
Name: testrand.BucketName(),
|
||||
ProjectID: project.ID,
|
||||
|
@ -23,7 +23,7 @@ type bucketsDB struct {
|
||||
}
|
||||
|
||||
// CreateBucket creates a new bucket.
|
||||
func (db *bucketsDB) CreateBucket(ctx context.Context, bucket storj.Bucket) (_ storj.Bucket, err error) {
|
||||
func (db *bucketsDB) CreateBucket(ctx context.Context, bucket buckets.Bucket) (_ buckets.Bucket, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
optionalFields := dbx.BucketMetainfo_Create_Fields{}
|
||||
@ -52,18 +52,18 @@ func (db *bucketsDB) CreateBucket(ctx context.Context, bucket storj.Bucket) (_ s
|
||||
optionalFields,
|
||||
)
|
||||
if err != nil {
|
||||
return storj.Bucket{}, storj.ErrBucket.Wrap(err)
|
||||
return buckets.Bucket{}, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
|
||||
bucket, err = convertDBXtoBucket(row)
|
||||
if err != nil {
|
||||
return storj.Bucket{}, storj.ErrBucket.Wrap(err)
|
||||
return buckets.Bucket{}, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
return bucket, nil
|
||||
}
|
||||
|
||||
// GetBucket returns a bucket.
|
||||
func (db *bucketsDB) GetBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (_ storj.Bucket, err error) {
|
||||
func (db *bucketsDB) GetBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (_ buckets.Bucket, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
dbxBucket, err := db.db.Get_BucketMetainfo_By_ProjectId_And_Name(ctx,
|
||||
dbx.BucketMetainfo_ProjectId(projectID[:]),
|
||||
@ -71,9 +71,9 @@ func (db *bucketsDB) GetBucket(ctx context.Context, bucketName []byte, projectID
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return storj.Bucket{}, storj.ErrBucketNotFound.New("%s", bucketName)
|
||||
return buckets.Bucket{}, buckets.ErrBucketNotFound.New("%s", bucketName)
|
||||
}
|
||||
return storj.Bucket{}, storj.ErrBucket.Wrap(err)
|
||||
return buckets.Bucket{}, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
return convertDBXtoBucket(dbxBucket)
|
||||
}
|
||||
@ -87,9 +87,9 @@ func (db *bucketsDB) GetBucketPlacement(ctx context.Context, bucketName []byte,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return storj.EveryCountry, storj.ErrBucketNotFound.New("%s", bucketName)
|
||||
return storj.EveryCountry, buckets.ErrBucketNotFound.New("%s", bucketName)
|
||||
}
|
||||
return storj.EveryCountry, storj.ErrBucket.Wrap(err)
|
||||
return storj.EveryCountry, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
placement = storj.EveryCountry
|
||||
if dbxPlacement.Placement != nil {
|
||||
@ -100,7 +100,7 @@ func (db *bucketsDB) GetBucketPlacement(ctx context.Context, bucketName []byte,
|
||||
}
|
||||
|
||||
// GetMinimalBucket returns existing bucket with minimal number of fields.
|
||||
func (db *bucketsDB) GetMinimalBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (_ buckets.Bucket, err error) {
|
||||
func (db *bucketsDB) GetMinimalBucket(ctx context.Context, bucketName []byte, projectID uuid.UUID) (_ buckets.MinimalBucket, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
row, err := db.db.Get_BucketMetainfo_CreatedAt_By_ProjectId_And_Name(ctx,
|
||||
dbx.BucketMetainfo_ProjectId(projectID[:]),
|
||||
@ -108,11 +108,11 @@ func (db *bucketsDB) GetMinimalBucket(ctx context.Context, bucketName []byte, pr
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return buckets.Bucket{}, storj.ErrBucketNotFound.New("%s", bucketName)
|
||||
return buckets.MinimalBucket{}, buckets.ErrBucketNotFound.New("%s", bucketName)
|
||||
}
|
||||
return buckets.Bucket{}, storj.ErrBucket.Wrap(err)
|
||||
return buckets.MinimalBucket{}, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
return buckets.Bucket{
|
||||
return buckets.MinimalBucket{
|
||||
Name: bucketName,
|
||||
CreatedAt: row.CreatedAt,
|
||||
}, nil
|
||||
@ -126,7 +126,7 @@ func (db *bucketsDB) HasBucket(ctx context.Context, bucketName []byte, projectID
|
||||
dbx.BucketMetainfo_ProjectId(projectID[:]),
|
||||
dbx.BucketMetainfo_Name(bucketName),
|
||||
)
|
||||
return exists, storj.ErrBucket.Wrap(err)
|
||||
return exists, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
|
||||
// GetBucketID returns an existing bucket id.
|
||||
@ -138,20 +138,20 @@ func (db *bucketsDB) GetBucketID(ctx context.Context, bucket metabase.BucketLoca
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return uuid.UUID{}, storj.ErrBucketNotFound.New("%s", bucket.BucketName)
|
||||
return uuid.UUID{}, buckets.ErrBucketNotFound.New("%s", bucket.BucketName)
|
||||
}
|
||||
return uuid.UUID{}, storj.ErrBucket.Wrap(err)
|
||||
return uuid.UUID{}, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
|
||||
id, err := uuid.FromBytes(dbxID.Id)
|
||||
if err != nil {
|
||||
return id, storj.ErrBucket.Wrap(err)
|
||||
return id, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
return id, err
|
||||
}
|
||||
|
||||
// UpdateBucket updates a bucket.
|
||||
func (db *bucketsDB) UpdateBucket(ctx context.Context, bucket storj.Bucket) (_ storj.Bucket, err error) {
|
||||
func (db *bucketsDB) UpdateBucket(ctx context.Context, bucket buckets.Bucket) (_ buckets.Bucket, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
var updateFields dbx.BucketMetainfo_Update_Fields
|
||||
@ -167,7 +167,7 @@ func (db *bucketsDB) UpdateBucket(ctx context.Context, bucket storj.Bucket) (_ s
|
||||
|
||||
dbxBucket, err := db.db.Update_BucketMetainfo_By_ProjectId_And_Name(ctx, dbx.BucketMetainfo_ProjectId(bucket.ProjectID[:]), dbx.BucketMetainfo_Name([]byte(bucket.Name)), updateFields)
|
||||
if err != nil {
|
||||
return storj.Bucket{}, storj.ErrBucket.Wrap(err)
|
||||
return buckets.Bucket{}, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
return convertDBXtoBucket(dbxBucket)
|
||||
}
|
||||
@ -180,16 +180,16 @@ func (db *bucketsDB) DeleteBucket(ctx context.Context, bucketName []byte, projec
|
||||
dbx.BucketMetainfo_Name(bucketName),
|
||||
)
|
||||
if err != nil {
|
||||
return storj.ErrBucket.Wrap(err)
|
||||
return buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
if !deleted {
|
||||
return storj.ErrBucketNotFound.New("%s", bucketName)
|
||||
return buckets.ErrBucketNotFound.New("%s", bucketName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListBuckets returns a list of buckets for a project.
|
||||
func (db *bucketsDB) ListBuckets(ctx context.Context, projectID uuid.UUID, listOpts storj.BucketListOptions, allowedBuckets macaroon.AllowedBuckets) (bucketList storj.BucketList, err error) {
|
||||
func (db *bucketsDB) ListBuckets(ctx context.Context, projectID uuid.UUID, listOpts buckets.ListOptions, allowedBuckets macaroon.AllowedBuckets) (bucketList buckets.List, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
const defaultListLimit = 10000
|
||||
@ -222,7 +222,7 @@ func (db *bucketsDB) ListBuckets(ctx context.Context, projectID uuid.UUID, listO
|
||||
return bucketList, errors.New("unknown list direction")
|
||||
}
|
||||
if err != nil {
|
||||
return bucketList, storj.ErrBucket.Wrap(err)
|
||||
return bucketList, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
|
||||
bucketList.More = len(dbxBuckets) > listOpts.Limit
|
||||
@ -234,7 +234,7 @@ func (db *bucketsDB) ListBuckets(ctx context.Context, projectID uuid.UUID, listO
|
||||
}
|
||||
|
||||
if bucketList.Items == nil {
|
||||
bucketList.Items = make([]storj.Bucket, 0, len(dbxBuckets))
|
||||
bucketList.Items = make([]buckets.Bucket, 0, len(dbxBuckets))
|
||||
}
|
||||
|
||||
for _, dbxBucket := range dbxBuckets {
|
||||
@ -243,7 +243,7 @@ func (db *bucketsDB) ListBuckets(ctx context.Context, projectID uuid.UUID, listO
|
||||
if bucketAllowed || allowedBuckets.All {
|
||||
item, err := convertDBXtoBucket(dbxBucket)
|
||||
if err != nil {
|
||||
return bucketList, storj.ErrBucket.Wrap(err)
|
||||
return bucketList, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
bucketList.Items = append(bucketList.Items, item)
|
||||
}
|
||||
@ -252,7 +252,7 @@ func (db *bucketsDB) ListBuckets(ctx context.Context, projectID uuid.UUID, listO
|
||||
if len(bucketList.Items) < listOpts.Limit && bucketList.More {
|
||||
// If we filtered out disallowed buckets, then get more buckets
|
||||
// out of database so that we return `limit` number of buckets
|
||||
listOpts = storj.BucketListOptions{
|
||||
listOpts = buckets.ListOptions{
|
||||
Cursor: string(dbxBuckets[len(dbxBuckets)-1].Name),
|
||||
Limit: listOpts.Limit,
|
||||
Direction: storj.After,
|
||||
@ -274,17 +274,17 @@ func (db *bucketsDB) CountBuckets(ctx context.Context, projectID uuid.UUID) (cou
|
||||
return int(count64), nil
|
||||
}
|
||||
|
||||
func convertDBXtoBucket(dbxBucket *dbx.BucketMetainfo) (bucket storj.Bucket, err error) {
|
||||
func convertDBXtoBucket(dbxBucket *dbx.BucketMetainfo) (bucket buckets.Bucket, err error) {
|
||||
id, err := uuid.FromBytes(dbxBucket.Id)
|
||||
if err != nil {
|
||||
return bucket, storj.ErrBucket.Wrap(err)
|
||||
return bucket, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
project, err := uuid.FromBytes(dbxBucket.ProjectId)
|
||||
if err != nil {
|
||||
return bucket, storj.ErrBucket.Wrap(err)
|
||||
return bucket, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
|
||||
bucket = storj.Bucket{
|
||||
bucket = buckets.Bucket{
|
||||
ID: id,
|
||||
Name: string(dbxBucket.Name),
|
||||
ProjectID: project,
|
||||
@ -312,7 +312,7 @@ func convertDBXtoBucket(dbxBucket *dbx.BucketMetainfo) (bucket storj.Bucket, err
|
||||
if dbxBucket.PartnerId != nil {
|
||||
partnerID, err := uuid.FromBytes(dbxBucket.PartnerId)
|
||||
if err != nil {
|
||||
return bucket, storj.ErrBucket.Wrap(err)
|
||||
return bucket, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
bucket.PartnerID = partnerID
|
||||
}
|
||||
@ -339,7 +339,7 @@ func (db *bucketsDB) IterateBucketLocations(ctx context.Context, projectID uuid.
|
||||
ORDER BY (project_id, name) ASC LIMIT $3
|
||||
`, projectID, bucketName, moreLimit)
|
||||
if err != nil {
|
||||
return false, storj.ErrBucket.New("BatchBuckets query error: %s", err)
|
||||
return false, buckets.ErrBucket.New("BatchBuckets query error: %s", err)
|
||||
}
|
||||
defer func() {
|
||||
err = errs.Combine(err, Error.Wrap(rows.Close()))
|
||||
@ -349,14 +349,14 @@ func (db *bucketsDB) IterateBucketLocations(ctx context.Context, projectID uuid.
|
||||
var bucketLocation metabase.BucketLocation
|
||||
|
||||
if err = rows.Scan(&bucketLocation.ProjectID, &bucketLocation.BucketName); err != nil {
|
||||
return false, storj.ErrBucket.New("bucket location scan error: %s", err)
|
||||
return false, buckets.ErrBucket.New("bucket location scan error: %s", err)
|
||||
}
|
||||
|
||||
result = append(result, bucketLocation)
|
||||
}
|
||||
|
||||
if err = rows.Err(); err != nil {
|
||||
return false, storj.ErrBucket.Wrap(err)
|
||||
return false, buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
|
||||
if len(result) == 0 {
|
||||
|
@ -11,12 +11,12 @@ import (
|
||||
|
||||
"storj.io/common/memory"
|
||||
"storj.io/common/pb"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite/accounting"
|
||||
"storj.io/storj/satellite/buckets"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/metabase"
|
||||
"storj.io/storj/satellite/orders"
|
||||
@ -278,7 +278,7 @@ func Test_GetProjectTotalByPartner(t *testing.T) {
|
||||
for _, name := range partnerNames {
|
||||
total := expectedTotal{}
|
||||
|
||||
bucket := storj.Bucket{
|
||||
bucket := buckets.Bucket{
|
||||
ID: testrand.UUID(),
|
||||
Name: testrand.BucketName(),
|
||||
ProjectID: project.ID,
|
||||
|
Loading…
Reference in New Issue
Block a user