-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[content-service] Add support to use existing S3 bucket #10073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
689aa9b
[content-service] Add support to use existing S3 bucket
aledbf 53d61ee
Update go modules
aledbf c1bb7fd
[content-service] add tests to minio provider
sagor999 387d6bb
[content-service] fix s3 access when using dedicated bucket
sagor999 2bd5d6f
[content-service] add omitempty to BucketName for minio config
sagor999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package storage | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
config "github.com/gitpod-io/gitpod/content-service/api/config" | ||
) | ||
|
||
func TestMinioBucketName(t *testing.T) { | ||
tests := []struct { | ||
Name string | ||
BucketNameConfig string | ||
OwnerID string | ||
ExpectedBucket string | ||
}{ | ||
{ | ||
Name: "no dedicated bucket", | ||
BucketNameConfig: "", | ||
OwnerID: "fake-owner-id", | ||
ExpectedBucket: "gitpod-user-fake-owner-id", | ||
}, | ||
{ | ||
Name: "with dedicated bucket", | ||
BucketNameConfig: "root-bucket", | ||
OwnerID: "fake-owner-id", | ||
ExpectedBucket: "root-bucket", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.Name, func(t *testing.T) { | ||
cfg := config.MinIOConfig{ | ||
Endpoint: "fake", | ||
AccessKeyID: "fake_access_key", | ||
SecretAccessKey: "fake_secret", | ||
Region: "none", | ||
BucketName: test.BucketNameConfig, | ||
} | ||
minio, err := newDirectMinIOAccess(cfg) | ||
if err != nil { | ||
t.Fatalf("failed to create minio access: '%v'", err) | ||
} | ||
|
||
actualBucketName := minio.Bucket(test.OwnerID) | ||
if actualBucketName != test.ExpectedBucket { | ||
t.Fatalf("[minio] unexpected bucket name: is '%s' but expected '%s'", actualBucketName, test.ExpectedBucket) | ||
} | ||
|
||
presignedMinio, err := newPresignedMinIOAccess(cfg) | ||
if err != nil { | ||
t.Fatalf("failed to create presigned minio access: '%v'", err) | ||
} | ||
|
||
actualBucketName = presignedMinio.Bucket(test.OwnerID) | ||
if actualBucketName != test.ExpectedBucket { | ||
t.Fatalf("[presigned minio] unexpected bucket name: is '%s' but expected '%s'", actualBucketName, test.ExpectedBucket) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestMinioBackupObject(t *testing.T) { | ||
tests := []struct { | ||
Name string | ||
BucketNameConfig string | ||
Username string | ||
Workspace string | ||
InstanceID string | ||
ObjectName string | ||
ExpectedBackupObject string | ||
}{ | ||
{ | ||
Name: "no dedicated bucket", | ||
BucketNameConfig: "", | ||
Username: "test-user", | ||
Workspace: "gitpodio-gitpod-2cx8z8e643x", | ||
InstanceID: "fa9aa2af-b6de-45fc-8b48-534bb440429f", | ||
ObjectName: "backup.tar", | ||
ExpectedBackupObject: "workspaces/gitpodio-gitpod-2cx8z8e643x/backup.tar", | ||
}, | ||
{ | ||
Name: "with dedicated bucket", | ||
BucketNameConfig: "root-bucket", | ||
Username: "test-user", | ||
Workspace: "gitpodio-gitpod-2cx8z8e643x", | ||
InstanceID: "fa9aa2af-b6de-45fc-8b48-534bb440429f", | ||
ObjectName: "backup.tar", | ||
ExpectedBackupObject: "test-user/workspaces/gitpodio-gitpod-2cx8z8e643x/backup.tar", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.Name, func(t *testing.T) { | ||
cfg := config.MinIOConfig{ | ||
Endpoint: "fake", | ||
AccessKeyID: "fake_access_key", | ||
SecretAccessKey: "fake_secret", | ||
Region: "none", | ||
BucketName: test.BucketNameConfig, | ||
} | ||
minio, err := newDirectMinIOAccess(cfg) | ||
if err != nil { | ||
t.Fatalf("failed to create minio access: '%v'", err) | ||
} | ||
err = minio.Init(context.Background(), test.Username, test.Workspace, test.InstanceID) | ||
if err != nil { | ||
t.Fatalf("failed to init minio access: '%v'", err) | ||
} | ||
|
||
actualBackupObject := minio.BackupObject(test.ObjectName) | ||
if actualBackupObject != test.ExpectedBackupObject { | ||
t.Fatalf("[minio] unexpected backup object name: is '%s' but expected '%s'", actualBackupObject, test.ExpectedBackupObject) | ||
} | ||
|
||
presignedMinio, err := newPresignedMinIOAccess(cfg) | ||
if err != nil { | ||
t.Fatalf("failed to create presigned minio access: '%v'", err) | ||
} | ||
|
||
actualBackupObject = presignedMinio.BackupObject(test.Username, test.Workspace, test.ObjectName) | ||
if actualBackupObject != test.ExpectedBackupObject { | ||
t.Fatalf("[presigned minio] unexpected backup object name: is '%s' but expected '%s'", actualBackupObject, test.ExpectedBackupObject) | ||
} | ||
|
||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.