Skip to content

Commit

Permalink
miniogw: fix up mappings to latest uplink code
Browse files Browse the repository at this point in the history
- use the new uplink ErrRetentionNotFound error type. Additionally
this should return a 404 with the right status S3 uses. Note that
if the bucket has no lock enabled, GetObjectRetention does the same
as S3 and return a 400 response bucket lock not configured.

- uplink ErrBucketNoLock, ErrNoObjectLockConfiguration, and
ErrBucketNoVersioningObjectLock should all map to
miniogw.ErrRetentionNotFound, a 400 status. We will need to also
map ObjectLockDisabled (for when the feature is disabled entirely)
as well as ProjectLockDisabled to this same error, but these will
come in a later change.

Updates storj/edge#498

Change-Id: Ic3702e24cb3e8f177eac303ccb3f9869a8de96b5
  • Loading branch information
halkyon committed Sep 11, 2024
1 parent 6229533 commit f511249
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ require (
github.com/zeebo/errs v1.3.0
go.uber.org/zap v1.27.0
golang.org/x/term v0.22.0
storj.io/common v0.0.0-20240821205240-79830b9841af
storj.io/common v0.0.0-20240910045755-9bb1876b820d
storj.io/minio v0.0.0-20240909102711-e7361135e625
storj.io/uplink v1.13.2-0.20240826160422-a98008006b25
storj.io/uplink v1.13.2-0.20240910182434-0e957acdd923
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,8 @@ sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1
sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
storj.io/common v0.0.0-20220719163320-cd2ef8e1b9b0/go.mod h1:mCYV6Ud5+cdbuaxdPD5Zht/HYaIn0sffnnws9ErkrMQ=
storj.io/common v0.0.0-20240821205240-79830b9841af h1:5LEX8GjTazE/Op1y+omHxq1x+i2S/FC7doTNIlEAME4=
storj.io/common v0.0.0-20240821205240-79830b9841af/go.mod h1:XMpwKxc04HCBl4H5IFCGv1ca5Dm0tvH4NL7Jx+JhxuA=
storj.io/common v0.0.0-20240910045755-9bb1876b820d h1:spTR9UZ0ba3jTuBYVJlH7TIn3eBejr+QHGCFyLno6Jc=
storj.io/common v0.0.0-20240910045755-9bb1876b820d/go.mod h1:XMpwKxc04HCBl4H5IFCGv1ca5Dm0tvH4NL7Jx+JhxuA=
storj.io/drpc v0.0.32/go.mod h1:6rcOyR/QQkSTX/9L5ZGtlZaE2PtXTTZl8d+ulSeeYEg=
storj.io/drpc v0.0.35-0.20240709171858-0075ac871661 h1:hLvEV2RMTscX3JHPd+LSQCeTt8i1Q0Yt7U2EdfyMnaQ=
storj.io/drpc v0.0.35-0.20240709171858-0075ac871661/go.mod h1:Y9LZaa8esL1PW2IDMqJE7CFSNq7d5bQ3RI7mGPtmKMg=
Expand All @@ -1136,5 +1136,5 @@ storj.io/monkit-jaeger v0.0.0-20240221095020-52b0792fa6cd h1:XkLxAvogynNQu/1gM/F
storj.io/monkit-jaeger v0.0.0-20240221095020-52b0792fa6cd/go.mod h1:nwyyJiAFAPRu81qBfAE5cBGkVXROYSNJu9pGXLtStHE=
storj.io/picobuf v0.0.3 h1:xAUPB5ZUGfxkqd3bnw3zp01kkWb9wlhg4vtZWUs2S9A=
storj.io/picobuf v0.0.3/go.mod h1:4V4xelV1RSCck5GgmkL/Txw9l6IfX3XcBzegmL5Kudo=
storj.io/uplink v1.13.2-0.20240826160422-a98008006b25 h1:fze5hxJ8rwKphUAT2Dox/hAGXztSicTSCN808ONlYF4=
storj.io/uplink v1.13.2-0.20240826160422-a98008006b25/go.mod h1:x0MQr4UfFsQBwgVWZAtEsLpuwAn6dg7G0Mpne1r516E=
storj.io/uplink v1.13.2-0.20240910182434-0e957acdd923 h1:WFKOfGBxmAcL4powcuSyGMdnqjW2PtfTe7NTRuvY0qY=
storj.io/uplink v1.13.2-0.20240910182434-0e957acdd923/go.mod h1:B+K9hsxSbtIYIR9yB/GpNlp88l0Of7aemjKodAx5Gwg=
14 changes: 10 additions & 4 deletions miniogw/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ var (
// ErrRetentionNotFound is a custom error returned when attempting to get retention config for an object
// that doesn't have any.
ErrRetentionNotFound = miniogo.ErrorResponse{
Code: "InvalidRequest",
StatusCode: http.StatusBadRequest,
Code: "NoSuchObjectLockConfiguration",
StatusCode: http.StatusNotFound,
Message: "Object is missing retention configuration",
}

Expand Down Expand Up @@ -1555,9 +1555,9 @@ func ConvertError(err error, bucketName, object string) error {
return minio.MethodNotAllowed{Bucket: bucketName, Object: object}
case errors.Is(err, io.ErrUnexpectedEOF):
return minio.IncompleteBody{Bucket: bucketName, Object: object}
case errors.Is(err, bucket.ErrBucketNoLock):
case noLockEnabledErr(err):
return ErrBucketObjectLockNotEnabled
case metaclient.ErrRetentionNotFound.Has(err):
case errors.Is(err, versioned.ErrRetentionNotFound):
return ErrRetentionNotFound
case errors.Is(err, syscall.ECONNRESET):
// This specific error happens when the satellite shuts down or is
Expand All @@ -1575,6 +1575,12 @@ func ConvertError(err error, bucketName, object string) error {
}
}

func noLockEnabledErr(err error) bool {
return errors.Is(err, bucket.ErrBucketNoLock) ||
errors.Is(err, versioned.ErrNoObjectLockConfiguration) ||
errors.Is(err, versioned.ErrBucketNoVersioningObjectLock)
}

func projectFromContext(ctx context.Context, bucket, object string) (*uplink.Project, error) {
pr, ok := GetUplinkProject(ctx)
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions testsuite/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ require (
github.com/stretchr/testify v1.9.0
github.com/zeebo/errs v1.3.0
go.uber.org/zap v1.27.0
storj.io/common v0.0.0-20240902133111-40dc2fade9ab
storj.io/common v0.0.0-20240910045755-9bb1876b820d
storj.io/gateway v0.0.0-00010101000000-000000000000
storj.io/minio v0.0.0-20240909102711-e7361135e625
storj.io/storj v1.91.0-alpha.0.20240909190826-79d153edcf35
storj.io/uplink v1.13.2-0.20240826160422-a98008006b25
storj.io/uplink v1.13.2-0.20240910182434-0e957acdd923
)

require (
Expand Down
8 changes: 4 additions & 4 deletions testsuite/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2624,8 +2624,8 @@ sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1
sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
storj.io/common v0.0.0-20220719163320-cd2ef8e1b9b0/go.mod h1:mCYV6Ud5+cdbuaxdPD5Zht/HYaIn0sffnnws9ErkrMQ=
storj.io/common v0.0.0-20240902133111-40dc2fade9ab h1:my3cBpb6JeD6TFU4/Ty+fTuT3Dm6v0LvRLWMq7O6x4g=
storj.io/common v0.0.0-20240902133111-40dc2fade9ab/go.mod h1:XMpwKxc04HCBl4H5IFCGv1ca5Dm0tvH4NL7Jx+JhxuA=
storj.io/common v0.0.0-20240910045755-9bb1876b820d h1:spTR9UZ0ba3jTuBYVJlH7TIn3eBejr+QHGCFyLno6Jc=
storj.io/common v0.0.0-20240910045755-9bb1876b820d/go.mod h1:XMpwKxc04HCBl4H5IFCGv1ca5Dm0tvH4NL7Jx+JhxuA=
storj.io/drpc v0.0.32/go.mod h1:6rcOyR/QQkSTX/9L5ZGtlZaE2PtXTTZl8d+ulSeeYEg=
storj.io/drpc v0.0.35-0.20240709171858-0075ac871661 h1:hLvEV2RMTscX3JHPd+LSQCeTt8i1Q0Yt7U2EdfyMnaQ=
storj.io/drpc v0.0.35-0.20240709171858-0075ac871661/go.mod h1:Y9LZaa8esL1PW2IDMqJE7CFSNq7d5bQ3RI7mGPtmKMg=
Expand All @@ -2641,5 +2641,5 @@ storj.io/picobuf v0.0.3 h1:xAUPB5ZUGfxkqd3bnw3zp01kkWb9wlhg4vtZWUs2S9A=
storj.io/picobuf v0.0.3/go.mod h1:4V4xelV1RSCck5GgmkL/Txw9l6IfX3XcBzegmL5Kudo=
storj.io/storj v1.91.0-alpha.0.20240909190826-79d153edcf35 h1:EA2AA8fssz0SnItU7WGa+z/XqqOdutaVFUjj/P6Y1eg=
storj.io/storj v1.91.0-alpha.0.20240909190826-79d153edcf35/go.mod h1:qP0EjrwwFpcx9zgSFG8gU7hFECn+mVdPS2q3MdMsY8w=
storj.io/uplink v1.13.2-0.20240826160422-a98008006b25 h1:fze5hxJ8rwKphUAT2Dox/hAGXztSicTSCN808ONlYF4=
storj.io/uplink v1.13.2-0.20240826160422-a98008006b25/go.mod h1:x0MQr4UfFsQBwgVWZAtEsLpuwAn6dg7G0Mpne1r516E=
storj.io/uplink v1.13.2-0.20240910182434-0e957acdd923 h1:WFKOfGBxmAcL4powcuSyGMdnqjW2PtfTe7NTRuvY0qY=
storj.io/uplink v1.13.2-0.20240910182434-0e957acdd923/go.mod h1:B+K9hsxSbtIYIR9yB/GpNlp88l0Of7aemjKodAx5Gwg=
13 changes: 10 additions & 3 deletions testsuite/miniogw/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ func TestCopyObjectWithObjectLock(t *testing.T) {
},
})
require.Error(t, err)
require.ErrorIs(t, err, miniogw.ErrBucketObjectLockNotEnabled)

_, err = project.DeleteBucketWithObjects(ctx, destBucket)
require.NoError(t, err)
Expand Down Expand Up @@ -2941,10 +2942,12 @@ func TestPutObjectWithOL(t *testing.T) {
t.Parallel()

runTestWithObjectLock(t, func(t *testing.T, ctx context.Context, layer minio.ObjectLayer, project *uplink.Project) {
err := layer.MakeBucketWithLocation(ctx, testBucket, minio.BucketOptions{
invalidBucket := "invalid-bucket"
require.NoError(t, layer.MakeBucketWithLocation(ctx, invalidBucket, minio.BucketOptions{}))

require.NoError(t, layer.MakeBucketWithLocation(ctx, testBucket, minio.BucketOptions{
LockEnabled: true,
})
require.NoError(t, err)
}))

retention := &lock.ObjectRetention{
Mode: lock.RetCompliance,
Expand All @@ -2955,6 +2958,10 @@ func TestPutObjectWithOL(t *testing.T) {

userDefined := map[string]string{}
opts := minio.ObjectOptions{UserDefined: userDefined, Retention: retention}

_, err := layer.PutObject(ctx, invalidBucket, testFile, nil, opts)
require.ErrorIs(t, err, miniogw.ErrBucketObjectLockNotEnabled)

_, err = layer.PutObject(ctx, testBucket, testFile, nil, opts)
require.NoError(t, err)

Expand Down

0 comments on commit f511249

Please sign in to comment.