Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

EVEREST-302 Improve validation for backupStorage #169

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 25 additions & 34 deletions api/backup_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (e *EverestServer) CreateBackupStorage(ctx echo.Context) error { //nolint:f
var accessKeyID, secretKeyID *string
defer e.cleanUpNewSecretsOnUpdateError(err, accessKeyID, secretKeyID)

accessKeyID, secretKeyID, err = e.createSecrets(c, &params.AccessKey, &params.SecretKey)
accessKeyID, secretKeyID, err = e.createSecrets(c, params.AccessKey, params.SecretKey)
if err != nil {
return ctx.JSON(http.StatusInternalServerError, Error{Message: pointer.ToString(err.Error())})
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func (e *EverestServer) performBackupStorageUpdate(
return ctx.JSON(http.StatusInternalServerError, Error{Message: pointer.ToString("Could not update config on the kubernetes cluster")})
}

e.deleteOldSecretsAfterUpdate(c, params, s)
e.deleteOldSecretsAfterUpdate(c, s)

result := BackupStorage{
Type: BackupStorageType(bs.Type),
Expand All @@ -318,51 +318,42 @@ func (e *EverestServer) performBackupStorageUpdate(

func (e *EverestServer) createSecrets(
ctx context.Context,
accessKey, secretKey *string,
accessKey, secretKey string,
) (*string, *string, error) {
var newAccessKeyID, newSecretKeyID *string
if accessKey != nil {
newID := uuid.NewString()
newAccessKeyID = &newID
newID := uuid.NewString()
newAccessKeyID = &newID

// create new AccessKey
err := e.secretsStorage.CreateSecret(ctx, newID, *accessKey)
if err != nil {
e.l.Error(err)
return newAccessKeyID, newSecretKeyID, errors.New("Could not store access key in secrets storage")
}
// create new AccessKey
err := e.secretsStorage.CreateSecret(ctx, newID, accessKey)
if err != nil {
e.l.Error(err)
return newAccessKeyID, newSecretKeyID, errors.New("Could not store access key in secrets storage")
}

if secretKey != nil {
newID := uuid.NewString()
newSecretKeyID = &newID
newID = uuid.NewString()
newSecretKeyID = &newID

// create new SecretKey
err := e.secretsStorage.CreateSecret(ctx, newID, *secretKey)
if err != nil {
e.l.Error(err)
return newAccessKeyID, newSecretKeyID, errors.New("Could not store secret key in secrets storage")
}
// create new SecretKey
err = e.secretsStorage.CreateSecret(ctx, newID, secretKey)
if err != nil {
e.l.Error(err)
return newAccessKeyID, newSecretKeyID, errors.New("Could not store secret key in secrets storage")
}

return newAccessKeyID, newSecretKeyID, nil
}

func (e *EverestServer) deleteOldSecretsAfterUpdate(ctx context.Context, params *UpdateBackupStorageParams, s *model.BackupStorage) {
func (e *EverestServer) deleteOldSecretsAfterUpdate(ctx context.Context, s *model.BackupStorage) {
// delete old AccessKey
if params.AccessKey != nil {
_, cErr := e.secretsStorage.DeleteSecret(ctx, s.AccessKeyID)
if cErr != nil {
e.l.Errorf("Failed to delete unused secret, please delete it manually. id = %s", s.AccessKeyID)
}
_, cErr := e.secretsStorage.DeleteSecret(ctx, s.AccessKeyID)
if cErr != nil {
e.l.Errorf("Failed to delete unused secret, please delete it manually. id = %s", s.AccessKeyID)
}

// delete old SecretKey
if params.SecretKey != nil {
_, cErr := e.secretsStorage.DeleteSecret(ctx, s.SecretKeyID)
if cErr != nil {
e.l.Errorf("Failed to delete unused secret, please delete it manually. id = %s", s.SecretKeyID)
}
_, cErr = e.secretsStorage.DeleteSecret(ctx, s.SecretKeyID)
if cErr != nil {
e.l.Errorf("Failed to delete unused secret, please delete it manually. id = %s", s.SecretKeyID)
}
}

Expand Down Expand Up @@ -426,7 +417,7 @@ func (e *EverestServer) updateBackupStorage(
err := e.storage.UpdateBackupStorage(ctx, tx, model.UpdateBackupStorageParams{
Name: backupStorageName,
Description: params.Description,
BucketName: params.BucketName,
BucketName: &params.BucketName,
URL: params.Url,
Region: params.Region,
AccessKeyID: newAccessKeyID,
Expand Down
130 changes: 65 additions & 65 deletions api/everest-server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 3 additions & 14 deletions api/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,9 @@ func validateStorageAccessByUpdate(oldData *storageData, params UpdateBackupStor
endpoint = params.Url
}

accessKey := oldData.accessKey
if params.AccessKey != nil {
accessKey = *params.AccessKey
}

secretKey := oldData.secretKey
if params.SecretKey != nil {
secretKey = *params.SecretKey
}

bucketName := oldData.storage.BucketName
if params.BucketName != nil {
bucketName = *params.BucketName
}
accessKey := params.AccessKey
secretKey := params.SecretKey
bucketName := params.BucketName

region := oldData.storage.Region
if params.Region != nil {
Expand Down
Loading
Loading