satellite: Remove remaining references to "partner ID"

This field is deprecated in favor of UserAgent; Removing these
references is the final step necessary before dropping the columns from
the database.

https: //github.com/storj/storj/issues/5432
Change-Id: I3a6619170dcf382f82dc8eddb73b6547eaf636f0
This commit is contained in:
Moby von Briesen 2023-04-14 12:39:11 -04:00 committed by Maximillian von Briesen
parent 41931970fd
commit 3679e29a93
5 changed files with 13 additions and 37 deletions

View File

@ -31,7 +31,6 @@ type Bucket struct {
ID uuid.UUID
Name string
ProjectID uuid.UUID
PartnerID uuid.UUID
UserAgent []byte
Created time.Time
PathCipher storj.CipherSuite

View File

@ -27,7 +27,7 @@ func TestUsers(t *testing.T) {
// create user
userPassHash := testrand.Bytes(8)
// create an user with no partnerID
// create an user with no UserAgent
_, err := consoleDB.Users().Insert(ctx, &console.User{
ID: testrand.UUID(),
FullName: "John Doe",
@ -37,16 +37,18 @@ func TestUsers(t *testing.T) {
})
require.NoError(t, err)
// create a project with partnerID
// create a project with UserAgent
testUserAgent := []byte("test user agent")
_, err = consoleDB.Projects().Insert(ctx, &console.Project{
ID: testrand.UUID(),
Name: "John Doe",
Description: "some description",
CreatedAt: time.Now(),
UserAgent: testUserAgent,
})
require.NoError(t, err)
// create a project with no partnerID
// create a project with no UserAgent
proj, err := consoleDB.Projects().Insert(ctx, &console.Project{
ID: testrand.UUID(),
Name: "John Doe",
@ -55,7 +57,7 @@ func TestUsers(t *testing.T) {
})
require.NoError(t, err)
// create a APIKey with no partnerID
// create a APIKey with no UserAgent
_, err = consoleDB.APIKeys().Create(ctx, testrand.Bytes(8), console.APIKeyInfo{
ID: testrand.UUID(),
ProjectID: proj.ID,
@ -65,7 +67,7 @@ func TestUsers(t *testing.T) {
})
require.NoError(t, err)
// create a bucket with no partnerID
// create a bucket with no UserAgent
_, err = bucketService.CreateBucket(ctx, buckets.Bucket{
ID: testrand.UUID(),
Name: "testbucket",
@ -76,21 +78,21 @@ func TestUsers(t *testing.T) {
})
require.NoError(t, err)
// update a bucket with partnerID
// update a bucket with UserAgent
bucket, err := bucketService.UpdateBucket(ctx, buckets.Bucket{
ID: testrand.UUID(),
Name: "testbucket",
ProjectID: proj.ID,
PartnerID: proj.ID,
Created: time.Now(),
PathCipher: storj.EncAESGCM,
DefaultSegmentsSize: int64(100),
UserAgent: testUserAgent,
})
require.NoError(t, err)
require.Equal(t, proj.ID, bucket.PartnerID)
require.Equal(t, testUserAgent, bucket.UserAgent)
bucket, err = bucketService.GetBucket(ctx, []byte("testbucket"), proj.ID)
require.NoError(t, err)
require.Equal(t, proj.ID, bucket.PartnerID)
require.Equal(t, testUserAgent, bucket.UserAgent)
})
}

View File

@ -23,8 +23,7 @@ import (
// MaxUserAgentLength is the maximum allowable length of the User Agent.
const MaxUserAgentLength = 500
// ensureAttribution ensures that the bucketName has the partner information specified by project-level user agent, header user agent, or keyInfo partner ID.
// PartnerID from keyInfo is a value associated with registered user and prevails over header user agent.
// ensureAttribution ensures that the bucketName has the partner information specified by project-level user agent, or header user agent.
//
// Assumes that the user has permissions sufficient for authenticating.
func (endpoint *Endpoint) ensureAttribution(ctx context.Context, header *pb.RequestHeader, keyInfo *console.APIKeyInfo, bucketName, projectUserAgent []byte) (err error) {

View File

@ -8,7 +8,6 @@ import (
"fmt"
"time"
"github.com/zeebo/errs"
"go.uber.org/zap"
"storj.io/common/macaroon"
@ -370,21 +369,10 @@ func convertProtoToBucket(req *pb.BucketCreateRequest, projectID uuid.UUID) (buc
return buckets.Bucket{}, err
}
// TODO: resolve partner id
var partnerID uuid.UUID
err = partnerID.UnmarshalJSON(req.GetPartnerId())
// bucket's partnerID should never be set
// it is always read back from buckets DB
if err != nil && !partnerID.IsZero() {
return bucket, errs.New("Invalid uuid")
}
return buckets.Bucket{
ID: bucketID,
Name: string(req.GetName()),
ProjectID: projectID,
PartnerID: partnerID,
}, nil
}

View File

@ -27,9 +27,8 @@ func (db *bucketsDB) CreateBucket(ctx context.Context, bucket buckets.Bucket) (_
defer mon.Task()(&ctx)(&err)
optionalFields := dbx.BucketMetainfo_Create_Fields{}
if !bucket.PartnerID.IsZero() || bucket.UserAgent != nil {
if bucket.UserAgent != nil {
optionalFields = dbx.BucketMetainfo_Create_Fields{
PartnerId: dbx.BucketMetainfo_PartnerId(bucket.PartnerID[:]),
UserAgent: dbx.BucketMetainfo_UserAgent(bucket.UserAgent),
}
}
@ -155,9 +154,6 @@ func (db *bucketsDB) UpdateBucket(ctx context.Context, bucket buckets.Bucket) (_
defer mon.Task()(&ctx)(&err)
var updateFields dbx.BucketMetainfo_Update_Fields
if !bucket.PartnerID.IsZero() {
updateFields.PartnerId = dbx.BucketMetainfo_PartnerId(bucket.PartnerID[:])
}
if bucket.UserAgent != nil {
updateFields.UserAgent = dbx.BucketMetainfo_UserAgent(bucket.UserAgent)
@ -309,14 +305,6 @@ func convertDBXtoBucket(dbxBucket *dbx.BucketMetainfo) (bucket buckets.Bucket, e
bucket.Placement = storj.PlacementConstraint(*dbxBucket.Placement)
}
if dbxBucket.PartnerId != nil {
partnerID, err := uuid.FromBytes(dbxBucket.PartnerId)
if err != nil {
return bucket, buckets.ErrBucket.Wrap(err)
}
bucket.PartnerID = partnerID
}
if dbxBucket.UserAgent != nil {
bucket.UserAgent = dbxBucket.UserAgent
}