From 41931970fd848c575f4a35f05461473dc2a4ca82 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Wed, 19 Apr 2023 15:25:12 +0300 Subject: [PATCH] satellite/*: changes to stop using storj.ListDirection Currently this duplicates the constants, because we cannot yet bump common nor uplink. Change-Id: I81818df8a9092e0b358eb946c31f2a42ac9dbf0a --- satellite/admin/project.go | 3 +-- satellite/admin/project_test.go | 3 +-- satellite/buckets/db.go | 14 ++++++++++++-- satellite/buckets/db_test.go | 4 ++-- satellite/console/service.go | 3 +-- satellite/metainfo/endpoint_bucket.go | 3 +-- satellite/metainfo/endpoint_bucket_test.go | 4 ++-- satellite/metainfo/endpoint_test.go | 2 +- satellite/satellitedb/bucketsdb.go | 6 +++--- 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/satellite/admin/project.go b/satellite/admin/project.go index 9507fc021..7db31f8b8 100644 --- a/satellite/admin/project.go +++ b/satellite/admin/project.go @@ -18,7 +18,6 @@ import ( "storj.io/common/macaroon" "storj.io/common/memory" - "storj.io/common/storj" "storj.io/common/uuid" "storj.io/storj/satellite/buckets" "storj.io/storj/satellite/console" @@ -465,7 +464,7 @@ func (server *Server) deleteProject(w http.ResponseWriter, r *http.Request) { return } - options := buckets.ListOptions{Limit: 1, Direction: storj.Forward} + options := buckets.ListOptions{Limit: 1, Direction: buckets.DirectionForward} buckets, err := server.buckets.ListBuckets(ctx, projectUUID, options, macaroon.AllowedBuckets{All: true}) if err != nil { sendJSONError(w, "unable to list buckets", diff --git a/satellite/admin/project_test.go b/satellite/admin/project_test.go index d4cd4ea38..d771993ed 100644 --- a/satellite/admin/project_test.go +++ b/satellite/admin/project_test.go @@ -18,7 +18,6 @@ import ( "storj.io/common/macaroon" "storj.io/common/memory" - "storj.io/common/storj" "storj.io/common/testcontext" "storj.io/common/uuid" "storj.io/storj/private/testplanet" @@ -308,7 +307,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, buckets.ListOptions{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: buckets.DirectionForward}, macaroon.AllowedBuckets{All: true}) require.NoError(t, err) require.Len(t, buckets.Items, 0) diff --git a/satellite/buckets/db.go b/satellite/buckets/db.go index 1e56c2d72..c19622047 100644 --- a/satellite/buckets/db.go +++ b/satellite/buckets/db.go @@ -41,6 +41,16 @@ type Bucket struct { Placement storj.PlacementConstraint } +// ListDirection specifies listing direction. +type ListDirection int32 + +const ( + // DirectionForward lists forwards from cursor, including cursor. + DirectionForward = 1 + // DirectionAfter lists forwards from cursor, without cursor. + DirectionAfter = 2 +) + // MinimalBucket contains minimal bucket fields for metainfo protocol. type MinimalBucket struct { Name []byte @@ -50,7 +60,7 @@ type MinimalBucket struct { // ListOptions lists objects. type ListOptions struct { Cursor string - Direction storj.ListDirection + Direction ListDirection Limit int } @@ -62,7 +72,7 @@ func (opts ListOptions) NextPage(list List) ListOptions { return ListOptions{ Cursor: list.Items[len(list.Items)-1].Name, - Direction: storj.After, + Direction: DirectionAfter, Limit: opts.Limit, } } diff --git a/satellite/buckets/db_test.go b/satellite/buckets/db_test.go index 0cfb636f1..14c05298b 100644 --- a/satellite/buckets/db_test.go +++ b/satellite/buckets/db_test.go @@ -158,7 +158,7 @@ func TestListBucketsAllAllowed(t *testing.T) { listOpts := buckets.ListOptions{ Cursor: tt.cursor, - Direction: storj.Forward, + Direction: buckets.DirectionForward, Limit: tt.limit, } bucketList, err := bucketsDB.ListBuckets(ctx, project.ID, listOpts, allowedBuckets) @@ -215,7 +215,7 @@ func TestListBucketsNotAllowed(t *testing.T) { tt := tt // avoid scopelint error listOpts := buckets.ListOptions{ Cursor: tt.cursor, - Direction: storj.Forward, + Direction: buckets.DirectionForward, Limit: tt.limit, } t.Run(tt.name, func(t *testing.T) { diff --git a/satellite/console/service.go b/satellite/console/service.go index d8c1bfa5d..efbaeb1c8 100644 --- a/satellite/console/service.go +++ b/satellite/console/service.go @@ -25,7 +25,6 @@ import ( "storj.io/common/currency" "storj.io/common/macaroon" "storj.io/common/memory" - "storj.io/common/storj" "storj.io/common/uuid" "storj.io/private/cfgstruct" "storj.io/storj/private/api" @@ -2486,7 +2485,7 @@ func (s *Service) GetAllBucketNames(ctx context.Context, projectID uuid.UUID) (_ } listOptions := buckets.ListOptions{ - Direction: storj.Forward, + Direction: buckets.DirectionForward, } allowedBuckets := macaroon.AllowedBuckets{ diff --git a/satellite/metainfo/endpoint_bucket.go b/satellite/metainfo/endpoint_bucket.go index b302196c8..027235859 100644 --- a/satellite/metainfo/endpoint_bucket.go +++ b/satellite/metainfo/endpoint_bucket.go @@ -15,7 +15,6 @@ import ( "storj.io/common/memory" "storj.io/common/pb" "storj.io/common/rpc/rpcstatus" - "storj.io/common/storj" "storj.io/common/uuid" "storj.io/storj/satellite/buckets" "storj.io/storj/satellite/metabase" @@ -321,7 +320,7 @@ func (endpoint *Endpoint) ListBuckets(ctx context.Context, req *pb.BucketListReq listOpts := buckets.ListOptions{ Cursor: string(req.Cursor), Limit: int(req.Limit), - Direction: storj.ListDirection(req.Direction), + Direction: buckets.ListDirection(req.Direction), } bucketList, err := endpoint.buckets.ListBuckets(ctx, keyInfo.ProjectID, listOpts, allowedBuckets) if err != nil { diff --git a/satellite/metainfo/endpoint_bucket_test.go b/satellite/metainfo/endpoint_bucket_test.go index 211bcdab7..ccfaf8b6c 100644 --- a/satellite/metainfo/endpoint_bucket_test.go +++ b/satellite/metainfo/endpoint_bucket_test.go @@ -196,7 +196,7 @@ func TestDeleteBucket(t *testing.T) { Header: &pb.RequestHeader{ ApiKey: apiKey.SerializeRaw(), }, - Direction: int32(storj.Forward), + Direction: buckets.DirectionForward, }) require.NoError(t, err) require.Len(t, buckets.GetItems(), 0) @@ -251,7 +251,7 @@ func TestListBucketsWithAttribution(t *testing.T) { Header: &pb.RequestHeader{ ApiKey: apiKey.SerializeRaw(), }, - Direction: int32(storj.Forward), + Direction: buckets.DirectionForward, }) require.NoError(t, err) require.True(t, bucketExists(tc, buckets)) diff --git a/satellite/metainfo/endpoint_test.go b/satellite/metainfo/endpoint_test.go index 356d37f87..bf0ff015f 100644 --- a/satellite/metainfo/endpoint_test.go +++ b/satellite/metainfo/endpoint_test.go @@ -96,7 +96,7 @@ func TestEndpoint_NoStorageNodes(t *testing.T) { _, err = client.ListBuckets(ctx, metaclient.ListBucketsParams{ ListOpts: metaclient.BucketListOptions{ Cursor: "", - Direction: storj.Forward, + Direction: metaclient.Forward, Limit: 10, }, }) diff --git a/satellite/satellitedb/bucketsdb.go b/satellite/satellitedb/bucketsdb.go index 8c7774c3d..4b0e557b6 100644 --- a/satellite/satellitedb/bucketsdb.go +++ b/satellite/satellitedb/bucketsdb.go @@ -202,7 +202,7 @@ func (db *bucketsDB) ListBuckets(ctx context.Context, projectID uuid.UUID, listO var dbxBuckets []*dbx.BucketMetainfo switch listOpts.Direction { // For simplictiy we are only supporting the forward direction for listing buckets - case storj.Forward: + case buckets.DirectionForward: dbxBuckets, err = db.db.Limited_BucketMetainfo_By_ProjectId_And_Name_GreaterOrEqual_OrderBy_Asc_Name(ctx, dbx.BucketMetainfo_ProjectId(projectID[:]), dbx.BucketMetainfo_Name([]byte(listOpts.Cursor)), @@ -211,7 +211,7 @@ func (db *bucketsDB) ListBuckets(ctx context.Context, projectID uuid.UUID, listO ) // After is only called by BucketListOptions.NextPage and is the paginated Forward direction - case storj.After: + case buckets.DirectionAfter: dbxBuckets, err = db.db.Limited_BucketMetainfo_By_ProjectId_And_Name_Greater_OrderBy_Asc_Name(ctx, dbx.BucketMetainfo_ProjectId(projectID[:]), dbx.BucketMetainfo_Name([]byte(listOpts.Cursor)), @@ -255,7 +255,7 @@ func (db *bucketsDB) ListBuckets(ctx context.Context, projectID uuid.UUID, listO listOpts = buckets.ListOptions{ Cursor: string(dbxBuckets[len(dbxBuckets)-1].Name), Limit: listOpts.Limit, - Direction: storj.After, + Direction: buckets.DirectionAfter, } continue }