Skip to content

Commit 06074b3

Browse files
Furistoroboquat
authored andcommitted
[content-service] Review Comments
- Ensure all items are fetched - Remove double init of client - Specify region and credentials from config - Remove insecure s3 test (deprecated)
1 parent 6d43c13 commit 06074b3

File tree

12 files changed

+48
-11231
lines changed

12 files changed

+48
-11231
lines changed

components/content-service-api/go/config/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ type MinIOConfig struct {
111111

112112
// S3Config configures the S3 remote storage backend
113113
type S3Config struct {
114-
Bucket string `json:"bucket"`
114+
Bucket string `json:"bucket"`
115+
Region string `json:"region"`
116+
CredentialsFile string `json:"credentialsFile"`
115117
}
116118

117119
type PProf struct {

components/content-service/cmd/test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
22
// Licensed under the GNU Affero General Public License (AGPL).
33
// See License-AGPL.txt in the project root for license information.
44

@@ -269,7 +269,9 @@ func createDirectAccess() (direct storage.DirectAccess, err error) {
269269
cfg = &config.StorageConfig{
270270
Kind: config.S3Storage,
271271
S3Config: &config.S3Config{
272-
Bucket: "gitpod-s3",
272+
Bucket: "gitpod-s3",
273+
Region: "eu-central-1",
274+
CredentialsFile: "./credentials",
273275
},
274276
}
275277
}
@@ -305,7 +307,9 @@ func createPresignedAccess() (presigned storage.PresignedAccess, err error) {
305307
cfg = &config.StorageConfig{
306308
Kind: config.S3Storage,
307309
S3Config: &config.S3Config{
308-
Bucket: "gitpod-s3",
310+
Bucket: "gitpod-s3",
311+
Region: "eu-central-1",
312+
CredentialsFile: "./credentials",
309313
},
310314
}
311315
}

components/content-service/pkg/storage/s3.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818

1919
"github.com/aws/aws-sdk-go-v2/aws"
2020
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
21-
awsconfig "github.com/aws/aws-sdk-go-v2/config"
2221
s3manager "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
2322
"github.com/aws/aws-sdk-go-v2/service/s3"
2423
"github.com/aws/aws-sdk-go-v2/service/s3/types"
@@ -309,13 +308,6 @@ func (*s3Storage) EnsureExists(ctx context.Context) error {
309308

310309
// Init implements DirectAccess
311310
func (s3st *s3Storage) Init(ctx context.Context, owner string, workspace string, instance string) error {
312-
cfg, err := awsconfig.LoadDefaultConfig(ctx)
313-
if err != nil {
314-
return err
315-
}
316-
317-
s3st.client = s3.NewFromConfig(cfg)
318-
319311
s3st.OwnerID = owner
320312
s3st.WorkspaceID = workspace
321313
s3st.InstanceID = instance
@@ -328,17 +320,25 @@ func (s3st *s3Storage) ListObjects(ctx context.Context, prefix string) ([]string
328320
return nil, xerrors.Errorf("prefix must start with the owner ID")
329321
}
330322

331-
objs, err := s3st.client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{
323+
var res []string
324+
listParams := &s3.ListObjectsV2Input{
332325
Bucket: aws.String(s3st.Config.Bucket),
333326
Prefix: aws.String(prefix),
334-
})
335-
if err != nil {
336-
return nil, xerrors.Errorf("cannot list objects: %w", err)
337327
}
328+
fetchObjects := true
329+
for fetchObjects {
330+
objs, err := s3st.client.ListObjectsV2(ctx, listParams)
331+
332+
if err != nil {
333+
return nil, xerrors.Errorf("cannot list objects: %w", err)
334+
}
335+
336+
for _, o := range objs.Contents {
337+
res = append(res, *o.Key)
338+
}
338339

339-
res := make([]string, len(objs.Contents))
340-
for i := range objs.Contents {
341-
res[i] = *objs.Contents[i].Key
340+
listParams.ContinuationToken = objs.NextContinuationToken
341+
fetchObjects = objs.IsTruncated
342342
}
343343

344344
return res, nil

components/content-service/pkg/storage/storage.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,12 @@ func NewDirectAccess(c *config.StorageConfig) (DirectAccess, error) {
228228
case config.MinIOStorage:
229229
return newDirectMinIOAccess(c.MinIOConfig)
230230
case config.S3Storage:
231-
cfg, err := awsconfig.LoadDefaultConfig(context.TODO())
231+
cfg, err := awsconfig.LoadDefaultConfig(context.TODO(), awsconfig.WithSharedConfigFiles([]string{c.S3Config.CredentialsFile}))
232232
if err != nil {
233233
return nil, err
234234
}
235+
236+
cfg.Region = c.S3Config.Region
235237
return newDirectS3Access(s3.NewFromConfig(cfg), S3Config{
236238
Bucket: c.S3Config.Bucket,
237239
}), nil
@@ -253,10 +255,12 @@ func NewPresignedAccess(c *config.StorageConfig) (PresignedAccess, error) {
253255
case config.MinIOStorage:
254256
return newPresignedMinIOAccess(c.MinIOConfig)
255257
case config.S3Storage:
256-
cfg, err := awsconfig.LoadDefaultConfig(context.TODO())
258+
cfg, err := awsconfig.LoadDefaultConfig(context.TODO(), awsconfig.WithSharedConfigFiles([]string{c.S3Config.CredentialsFile}))
257259
if err != nil {
258260
return nil, err
259261
}
262+
263+
cfg.Region = c.S3Config.Region
260264
return NewPresignedS3Access(s3.NewFromConfig(cfg), S3Config{
261265
Bucket: c.S3Config.Bucket,
262266
}), nil

install/installer/cmd/testdata/render/aws-setup/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ metadata:
2424
objectStorage:
2525
inCluster: false
2626
s3:
27-
region: eu-west-2
2827
endpoint: s3.amazonaws.com
2928
bucket: s3-bucket
3029
credentials:

install/installer/cmd/testdata/render/aws-setup/output.golden

Lines changed: 12 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/cmd/testdata/render/insecure-s3-setup/config.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)