satellite/metainfo: return NotFound status for (Get|Set)BucketVersioning
We need to return NotFound rpc status when bucket doesn't exist. Change-Id: I3abdd588e2af288618b05513884bc0c545bcbacf
This commit is contained in:
parent
c2788ab6ae
commit
220920edb9
@ -104,6 +104,9 @@ func (endpoint *Endpoint) GetBucketVersioning(ctx context.Context, req *pb.GetBu
|
||||
|
||||
versioning, err := endpoint.buckets.GetBucketVersioningState(ctx, req.GetName(), keyInfo.ProjectID)
|
||||
if err != nil {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return nil, rpcstatus.Error(rpcstatus.NotFound, err.Error())
|
||||
}
|
||||
endpoint.log.Error("internal", zap.Error(err))
|
||||
return nil, rpcstatus.Error(rpcstatus.Internal, "unable to get versioning state for the bucket")
|
||||
}
|
||||
@ -138,6 +141,9 @@ func (endpoint *Endpoint) SetBucketVersioning(ctx context.Context, req *pb.SetBu
|
||||
err = endpoint.buckets.SuspendBucketVersioning(ctx, req.GetName(), keyInfo.ProjectID)
|
||||
}
|
||||
if err != nil {
|
||||
if buckets.ErrBucketNotFound.Has(err) {
|
||||
return nil, rpcstatus.Error(rpcstatus.NotFound, err.Error())
|
||||
}
|
||||
endpoint.log.Error("internal", zap.Error(err))
|
||||
return nil, rpcstatus.Error(rpcstatus.Internal, "unable to enable versioning for the bucket")
|
||||
}
|
||||
|
@ -379,6 +379,32 @@ func TestEnableSuspendBucketVersioning(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := satellite.API.Metainfo.Endpoint.GetBucketVersioning(ctx, &pb.GetBucketVersioningRequest{
|
||||
Header: &pb.RequestHeader{
|
||||
ApiKey: planet.Uplinks[0].APIKey[satellite.ID()].SerializeRaw(),
|
||||
},
|
||||
Name: []byte("non-existing-bucket"),
|
||||
})
|
||||
require.True(t, errs2.IsRPC(err, rpcstatus.NotFound))
|
||||
|
||||
_, err = satellite.API.Metainfo.Endpoint.SetBucketVersioning(ctx, &pb.SetBucketVersioningRequest{
|
||||
Header: &pb.RequestHeader{
|
||||
ApiKey: planet.Uplinks[0].APIKey[satellite.ID()].SerializeRaw(),
|
||||
},
|
||||
Name: []byte("non-existing-bucket"),
|
||||
Versioning: true,
|
||||
})
|
||||
require.True(t, errs2.IsRPC(err, rpcstatus.NotFound))
|
||||
|
||||
_, err = satellite.API.Metainfo.Endpoint.SetBucketVersioning(ctx, &pb.SetBucketVersioningRequest{
|
||||
Header: &pb.RequestHeader{
|
||||
ApiKey: planet.Uplinks[0].APIKey[satellite.ID()].SerializeRaw(),
|
||||
},
|
||||
Name: []byte("non-existing-bucket"),
|
||||
Versioning: false,
|
||||
})
|
||||
require.True(t, errs2.IsRPC(err, rpcstatus.NotFound))
|
||||
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
initialVersioningState buckets.Versioning
|
||||
|
@ -135,7 +135,10 @@ func (db *bucketsDB) EnableBucketVersioning(ctx context.Context, bucketName []by
|
||||
if err != nil {
|
||||
return buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
if dbxBucket == nil || buckets.Versioning(dbxBucket.Versioning) != buckets.VersioningEnabled {
|
||||
if dbxBucket == nil {
|
||||
return buckets.ErrBucketNotFound.New("%s", bucketName)
|
||||
}
|
||||
if buckets.Versioning(dbxBucket.Versioning) != buckets.VersioningEnabled {
|
||||
return buckets.ErrBucket.New("cannot transition bucket versioning state to enabled")
|
||||
}
|
||||
return nil
|
||||
@ -155,7 +158,10 @@ func (db *bucketsDB) SuspendBucketVersioning(ctx context.Context, bucketName []b
|
||||
if err != nil {
|
||||
return buckets.ErrBucket.Wrap(err)
|
||||
}
|
||||
if dbxBucket == nil || buckets.Versioning(dbxBucket.Versioning) != buckets.VersioningSuspended {
|
||||
if dbxBucket == nil {
|
||||
return buckets.ErrBucketNotFound.New("%s", bucketName)
|
||||
}
|
||||
if buckets.Versioning(dbxBucket.Versioning) != buckets.VersioningSuspended {
|
||||
return buckets.ErrBucket.New("cannot transition bucket versioning state to suspended")
|
||||
}
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user