satellite/metainfo: ListBuckets extended with value attribution assigned to bucket

We need to provide the ability to see bucket attribution on the gateway side
so customers can validate if bucket is attributed to them. Extendet metainfo.ListBuckets
request with UserAgent.

Fixes https://github.com/storj/storj/issues/4965

Change-Id: I5624874a7faa14cda06183ad44013e9ebb385b63
This commit is contained in:
Qweder93 2022-07-12 18:53:12 +03:00 committed by Storj Robot
parent 0317c819dc
commit cf12802a12
6 changed files with 63 additions and 6 deletions

2
go.mod
View File

@ -51,7 +51,7 @@ require (
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
gopkg.in/segmentio/analytics-go.v3 v3.1.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
storj.io/common v0.0.0-20220630081130-5ba97afece12
storj.io/common v0.0.0-20220708152916-e2f08365ed65
storj.io/drpc v0.0.32
storj.io/monkit-jaeger v0.0.0-20220614151325-3ae4cae696b8
storj.io/private v0.0.0-20220614154538-e18b72a55f43

4
go.sum
View File

@ -950,8 +950,8 @@ sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3
storj.io/common v0.0.0-20220131120956-e74f624a3d55/go.mod h1:m0489td5+rKDdoiYOzCkh3CfGW/cLyntZiYfso+QfMs=
storj.io/common v0.0.0-20220216094301-b27f3c9d69e1/go.mod h1:xW3PPPGBo4bdMtEP9GREnmxQptmJNuDg1tEHcA4zqog=
storj.io/common v0.0.0-20220621110021-1cde7e384e77/go.mod h1:PdwPrX+QWAm4vgVyka5U13vA0jKk49MpV4tzW4HTaz0=
storj.io/common v0.0.0-20220630081130-5ba97afece12 h1:eHGe7N4bIaH4lnH4apt5OIE0UxXs1NxApOy4/Cy5cWU=
storj.io/common v0.0.0-20220630081130-5ba97afece12/go.mod h1:PdwPrX+QWAm4vgVyka5U13vA0jKk49MpV4tzW4HTaz0=
storj.io/common v0.0.0-20220708152916-e2f08365ed65 h1:pbJjM55dogMugIAdEq+j9149gan6MpMLSszArnTLMtc=
storj.io/common v0.0.0-20220708152916-e2f08365ed65/go.mod h1:PdwPrX+QWAm4vgVyka5U13vA0jKk49MpV4tzW4HTaz0=
storj.io/drpc v0.0.29/go.mod h1:6rcOyR/QQkSTX/9L5ZGtlZaE2PtXTTZl8d+ulSeeYEg=
storj.io/drpc v0.0.29/go.mod h1:6rcOyR/QQkSTX/9L5ZGtlZaE2PtXTTZl8d+ulSeeYEg=
storj.io/drpc v0.0.32 h1:5p5ZwsK/VOgapaCu+oxaPVwO6UwIs+iwdMiD50+R4PI=

View File

@ -333,6 +333,7 @@ func (endpoint *Endpoint) ListBuckets(ctx context.Context, req *pb.BucketListReq
bucketItems[i] = &pb.BucketListItem{
Name: []byte(item.Name),
CreatedAt: item.Created,
UserAgent: item.UserAgent,
}
}

View File

@ -201,3 +201,59 @@ func TestDeleteBucket(t *testing.T) {
require.Len(t, buckets.GetItems(), 0)
})
}
func TestListBucketsWithAttribution(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
satellite := planet.Satellites[0]
apiKey := planet.Uplinks[0].APIKey[planet.Satellites[0].ID()]
type testCase struct {
UserAgent string
Bucket string
}
var testCases = []testCase{
{
Bucket: "bucket-without-user-agent",
},
{
UserAgent: "storj",
Bucket: "bucket-with-user-agent",
},
}
bucketExists := func(tc testCase, buckets *pb.BucketListResponse) bool {
for _, bucket := range buckets.Items {
if string(bucket.Name) == tc.Bucket {
require.EqualValues(t, tc.UserAgent, string(bucket.UserAgent))
return true
}
}
t.Fatalf("bucket was not found in results:%s", tc.Bucket)
return false
}
for _, tc := range testCases {
config := uplink.Config{
UserAgent: tc.UserAgent,
}
project, err := config.OpenProject(ctx, planet.Uplinks[0].Access[satellite.ID()])
require.NoError(t, err)
_, err = project.CreateBucket(ctx, tc.Bucket)
require.NoError(t, err)
buckets, err := satellite.Metainfo.Endpoint.ListBuckets(ctx, &pb.BucketListRequest{
Header: &pb.RequestHeader{
ApiKey: apiKey.SerializeRaw(),
},
Direction: int32(storj.Forward),
})
require.NoError(t, err)
require.True(t, bucketExists(tc, buckets))
}
})
}

View File

@ -10,7 +10,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.17.0
storj.io/common v0.0.0-20220630081130-5ba97afece12
storj.io/common v0.0.0-20220708152916-e2f08365ed65
storj.io/gateway-mt v1.18.1-0.20211210081136-cada9a567d31
storj.io/private v0.0.0-20220614154538-e18b72a55f43
storj.io/storj v0.12.1-0.20220705102727-0f626a59c103

View File

@ -1486,8 +1486,8 @@ storj.io/common v0.0.0-20211102144601-401a79f0706a/go.mod h1:a2Kw7Uipu929OFANfWK
storj.io/common v0.0.0-20220131120956-e74f624a3d55/go.mod h1:m0489td5+rKDdoiYOzCkh3CfGW/cLyntZiYfso+QfMs=
storj.io/common v0.0.0-20220216094301-b27f3c9d69e1/go.mod h1:xW3PPPGBo4bdMtEP9GREnmxQptmJNuDg1tEHcA4zqog=
storj.io/common v0.0.0-20220621110021-1cde7e384e77/go.mod h1:PdwPrX+QWAm4vgVyka5U13vA0jKk49MpV4tzW4HTaz0=
storj.io/common v0.0.0-20220630081130-5ba97afece12 h1:eHGe7N4bIaH4lnH4apt5OIE0UxXs1NxApOy4/Cy5cWU=
storj.io/common v0.0.0-20220630081130-5ba97afece12/go.mod h1:PdwPrX+QWAm4vgVyka5U13vA0jKk49MpV4tzW4HTaz0=
storj.io/common v0.0.0-20220708152916-e2f08365ed65 h1:pbJjM55dogMugIAdEq+j9149gan6MpMLSszArnTLMtc=
storj.io/common v0.0.0-20220708152916-e2f08365ed65/go.mod h1:PdwPrX+QWAm4vgVyka5U13vA0jKk49MpV4tzW4HTaz0=
storj.io/dotworld v0.0.0-20210324183515-0d11aeccd840/go.mod h1:KU9YvEgRrMMiWLvH8pzn1UkoCoxggKIPvQxmNdx7aXQ=
storj.io/drpc v0.0.11/go.mod h1:TiFc2obNjL9/3isMW1Rpxjy8V9uE0B2HMeMFGiiI7Iw=
storj.io/drpc v0.0.24/go.mod h1:ofQUDPQbbIymRDKE0tms48k8bLP5Y+dsI9CbXGv3gko=