Skip to content

Commit

Permalink
fix: preferences should be false incase of invalid bucket (#2661)
Browse files Browse the repository at this point in the history
  • Loading branch information
BonapartePC authored Nov 7, 2022
1 parent 0964e83 commit 725e9e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
12 changes: 8 additions & 4 deletions services/fileuploader/fileuploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,24 @@ func (p *provider) updateLoop(ctx context.Context, backendConfig backendconfig.B

settings := make(map[string]StorageSettings)

var bucket backendconfig.StorageBucket
var preferences backendconfig.StoragePreferences

for ev := range ch {
configs := ev.Data.(map[string]backendconfig.ConfigT)
for _, c := range configs {

var bucket backendconfig.StorageBucket
var preferences backendconfig.StoragePreferences

if c.Settings.DataRetention.UseSelfStorage {
settings := c.Settings.DataRetention.StorageBucket
defaultBucket := getDefaultBucket(ctx, settings.Type)
bucket = overrideWithSettings(defaultBucket.Config, settings, c.WorkspaceID)
} else {
bucket = getDefaultBucket(ctx, config.GetString("JOBS_BACKUP_STORAGE_PROVIDER", "S3"))
}
preferences = c.Settings.DataRetention.StoragePreferences
// bucket type and configuration must not be empty
if bucket.Type != "" && len(bucket.Config) > 0 {
preferences = c.Settings.DataRetention.StoragePreferences
}
settings[c.WorkspaceID] = StorageSettings{
Bucket: bucket,
Preferences: preferences,
Expand Down
14 changes: 8 additions & 6 deletions services/fileuploader/fileuploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ func TestFileUploaderUpdatingWithConfigBackend(t *testing.T) {
DataRetention: backendconfig.DataRetention{
UseSelfStorage: true,
StorageBucket: backendconfig.StorageBucket{
Type: "some-type",
Config: map[string]interface{}{
"some-key": "some-value",
},
Type: "",
Config: map[string]interface{}{},
},
StoragePreferences: backendconfig.StoragePreferences{
ProcErrors: true,
GatewayDumps: true,
ProcErrors: false,
GatewayDumps: false,
},
},
},
Expand All @@ -103,6 +101,10 @@ func TestFileUploaderUpdatingWithConfigBackend(t *testing.T) {
preferences, err = fileUploaderProvider.GetStoragePreferences("testWorkspaceId-0")
Expect(err).To(HaveOccurred())
Expect(preferences).To(BeEquivalentTo(backendconfig.StoragePreferences{}))

preferences, err = fileUploaderProvider.GetStoragePreferences("testWorkspaceId-2")
Expect(err).To(BeNil())
Expect(preferences).To(BeEquivalentTo(backendconfig.StoragePreferences{}))
}

func TestFileUploaderWithoutConfigUpdates(t *testing.T) {
Expand Down

0 comments on commit 725e9e7

Please sign in to comment.