satellite/metabase: simplify UpdateObjectLastCommitted

Change-Id: Ifec596ab1868baa03688e717adec7d2ab45eafa9
This commit is contained in:
Egon Elbre 2023-10-27 12:50:28 +03:00
parent 55bddb6ce1
commit 1fa918c255
3 changed files with 26 additions and 54 deletions

View File

@ -13,10 +13,8 @@ import (
// UpdateObjectLastCommittedMetadata contains arguments necessary for replacing an object metadata.
type UpdateObjectLastCommittedMetadata struct {
ProjectID uuid.UUID
BucketName string
ObjectKey ObjectKey
StreamID uuid.UUID
ObjectLocation
StreamID uuid.UUID
EncryptedMetadata []byte
EncryptedMetadataNonce []byte
@ -25,14 +23,10 @@ type UpdateObjectLastCommittedMetadata struct {
// Verify object stream fields.
func (obj *UpdateObjectLastCommittedMetadata) Verify() error {
switch {
case obj.ProjectID.IsZero():
return ErrInvalidRequest.New("ProjectID missing")
case obj.BucketName == "":
return ErrInvalidRequest.New("BucketName missing")
case len(obj.ObjectKey) == 0:
return ErrInvalidRequest.New("ObjectKey missing")
case obj.StreamID.IsZero():
if err := obj.ObjectLocation.Verify(); err != nil {
return err
}
if obj.StreamID.IsZero() {
return ErrInvalidRequest.New("StreamID missing")
}
return nil

View File

@ -23,9 +23,7 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: test.ObjectLocation.ProjectID,
BucketName: test.ObjectLocation.BucketName,
ObjectKey: test.ObjectLocation.ObjectKey,
ObjectLocation: test.ObjectLocation,
},
ErrClass: test.ErrClass,
ErrText: test.ErrText,
@ -40,10 +38,8 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
obj := metabasetest.RandObjectStream()
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: obj.ProjectID,
BucketName: obj.BucketName,
ObjectKey: obj.ObjectKey,
StreamID: uuid.UUID{},
ObjectLocation: obj.Location(),
StreamID: uuid.UUID{},
},
ErrClass: &metabase.ErrInvalidRequest,
ErrText: "StreamID missing",
@ -57,10 +53,8 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
obj := metabasetest.RandObjectStream()
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: obj.ProjectID,
BucketName: obj.BucketName,
ObjectKey: obj.ObjectKey,
StreamID: obj.StreamID,
ObjectLocation: obj.Location(),
StreamID: obj.StreamID,
},
ErrClass: &metabase.ErrObjectNotFound,
ErrText: "object with specified version and committed status is missing",
@ -80,10 +74,8 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: obj.ProjectID,
BucketName: obj.BucketName,
ObjectKey: obj.ObjectKey,
StreamID: obj.StreamID,
ObjectLocation: object.Location(),
StreamID: object.StreamID,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataNonce: encryptedMetadataNonce[:],
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
@ -117,9 +109,7 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: object2.ProjectID,
BucketName: object2.BucketName,
ObjectKey: object2.ObjectKey,
ObjectLocation: object2.Location(),
StreamID: object2.StreamID,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataNonce: encryptedMetadataNonce[:],
@ -151,9 +141,7 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: object.ProjectID,
BucketName: object.BucketName,
ObjectKey: object.ObjectKey,
ObjectLocation: object.Location(),
StreamID: object.StreamID,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataNonce: encryptedMetadataNonce[:],
@ -203,9 +191,7 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
// verify we cannot update the metadata of a deleted object
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: object.ProjectID,
BucketName: object.BucketName,
ObjectKey: object.ObjectKey,
ObjectLocation: object.Location(),
StreamID: object.StreamID,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataNonce: encryptedMetadataNonce[:],
@ -218,9 +204,7 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
// verify cannot update the metadata of the delete marker either
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: marker.ProjectID,
BucketName: marker.BucketName,
ObjectKey: marker.ObjectKey,
ObjectLocation: marker.Location(),
StreamID: marker.StreamID,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataNonce: encryptedMetadataNonce[:],
@ -276,9 +260,7 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
// verify we cannot update the metadata of a deleted object
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: object2.ProjectID,
BucketName: object2.BucketName,
ObjectKey: object2.ObjectKey,
ObjectLocation: object2.Location(),
StreamID: object2.StreamID,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataNonce: encryptedMetadataNonce[:],
@ -291,9 +273,7 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
// verify cannot update the metadata of the delete marker either
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: marker.ProjectID,
BucketName: marker.BucketName,
ObjectKey: marker.ObjectKey,
ObjectLocation: marker.Location(),
StreamID: marker.StreamID,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataNonce: encryptedMetadataNonce[:],
@ -346,9 +326,7 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: object2.ProjectID,
BucketName: object2.BucketName,
ObjectKey: object2.ObjectKey,
ObjectLocation: object2.Location(),
StreamID: object2.StreamID,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataNonce: encryptedMetadataNonce[:],
@ -391,9 +369,7 @@ func TestUpdateObjectLastCommittedMetadata(t *testing.T) {
metabasetest.UpdateObjectLastCommittedMetadata{
Opts: metabase.UpdateObjectLastCommittedMetadata{
ProjectID: object3.ProjectID,
BucketName: object3.BucketName,
ObjectKey: object3.ObjectKey,
ObjectLocation: object3.Location(),
StreamID: object3.StreamID,
EncryptedMetadata: encryptedMetadata,
EncryptedMetadataNonce: encryptedMetadataNonce[:],

View File

@ -1471,9 +1471,11 @@ func (endpoint *Endpoint) UpdateObjectMetadata(ctx context.Context, req *pb.Obje
}
err = endpoint.metabase.UpdateObjectLastCommittedMetadata(ctx, metabase.UpdateObjectLastCommittedMetadata{
ProjectID: keyInfo.ProjectID,
BucketName: string(req.Bucket),
ObjectKey: metabase.ObjectKey(req.EncryptedObjectKey),
ObjectLocation: metabase.ObjectLocation{
ProjectID: keyInfo.ProjectID,
BucketName: string(req.Bucket),
ObjectKey: metabase.ObjectKey(req.EncryptedObjectKey),
},
StreamID: id,
EncryptedMetadata: req.EncryptedMetadata,
EncryptedMetadataNonce: encryptedMetadataNonce,