satellite/*: changes to stop using storj.ListDirection

Currently this duplicates the constants, because we cannot yet bump
common nor uplink.

Change-Id: I81818df8a9092e0b358eb946c31f2a42ac9dbf0a
This commit is contained in:
Egon Elbre 2023-04-19 15:25:12 +03:00
parent 54beea82da
commit 41931970fd
9 changed files with 24 additions and 18 deletions

View File

@ -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",

View File

@ -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)

View File

@ -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,
}
}

View File

@ -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) {

View File

@ -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{

View File

@ -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 {

View File

@ -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))

View File

@ -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,
},
})

View File

@ -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
}