Skip to content

Commit

Permalink
fix(api): application crypto migration with null vcs_strategy (#5135)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored Apr 20, 2020
1 parent fb62ee3 commit c6a8f2c
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions engine/api/migrate/refactor_app_crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,25 @@ func refactorApplicationCrypto(ctx context.Context, db *gorp.DbMap, id int64) er
return sdk.WrapError(err, "unable to select and lock application %d", id)
}

if len(btes) == 0 {
return nil
}

var vcsStrategy sdk.RepositoryStrategy
if err := json.Unmarshal(btes, &vcsStrategy); err != nil {
return sdk.WrapError(err, "unable to unmarshal application RepositoryStrategy %d", id)
}
var clearPWD []byte
if len(btes) != 0 {
if err := json.Unmarshal(btes, &vcsStrategy); err != nil {
return sdk.WrapError(err, "unable to unmarshal application RepositoryStrategy %d", id)
}

encryptedPassword, err64 := base64.StdEncoding.DecodeString(vcsStrategy.Password)
if err64 != nil {
return sdk.WrapError(err64, "unable to decode password for application %d", id)
}
encryptedPassword, err := base64.StdEncoding.DecodeString(vcsStrategy.Password)
if err != nil {
return sdk.WrapError(err, "unable to decode password for application %d", id)
}

clearPWD, err := secret.Decrypt([]byte(encryptedPassword))
if err != nil {
return sdk.WrapError(err, "Unable to decrypt password for application %d", id)
}
clearPWD, err = secret.Decrypt([]byte(encryptedPassword))
if err != nil {
return sdk.WrapError(err, "Unable to decrypt password for application %d", id)
}

vcsStrategy.Password = string(clearPWD)
vcsStrategy.Password = string(clearPWD)
}

var tmpApp = sdk.Application{
ID: id,
Expand Down

0 comments on commit c6a8f2c

Please sign in to comment.