Skip to content

Commit c6a8f2c

Browse files
authored
fix(api): application crypto migration with null vcs_strategy (#5135)
1 parent fb62ee3 commit c6a8f2c

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

engine/api/migrate/refactor_app_crypto.go

+15-16
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,25 @@ func refactorApplicationCrypto(ctx context.Context, db *gorp.DbMap, id int64) er
7979
return sdk.WrapError(err, "unable to select and lock application %d", id)
8080
}
8181

82-
if len(btes) == 0 {
83-
return nil
84-
}
85-
8682
var vcsStrategy sdk.RepositoryStrategy
87-
if err := json.Unmarshal(btes, &vcsStrategy); err != nil {
88-
return sdk.WrapError(err, "unable to unmarshal application RepositoryStrategy %d", id)
89-
}
83+
var clearPWD []byte
84+
if len(btes) != 0 {
85+
if err := json.Unmarshal(btes, &vcsStrategy); err != nil {
86+
return sdk.WrapError(err, "unable to unmarshal application RepositoryStrategy %d", id)
87+
}
9088

91-
encryptedPassword, err64 := base64.StdEncoding.DecodeString(vcsStrategy.Password)
92-
if err64 != nil {
93-
return sdk.WrapError(err64, "unable to decode password for application %d", id)
94-
}
89+
encryptedPassword, err := base64.StdEncoding.DecodeString(vcsStrategy.Password)
90+
if err != nil {
91+
return sdk.WrapError(err, "unable to decode password for application %d", id)
92+
}
9593

96-
clearPWD, err := secret.Decrypt([]byte(encryptedPassword))
97-
if err != nil {
98-
return sdk.WrapError(err, "Unable to decrypt password for application %d", id)
99-
}
94+
clearPWD, err = secret.Decrypt([]byte(encryptedPassword))
95+
if err != nil {
96+
return sdk.WrapError(err, "Unable to decrypt password for application %d", id)
97+
}
10098

101-
vcsStrategy.Password = string(clearPWD)
99+
vcsStrategy.Password = string(clearPWD)
100+
}
102101

103102
var tmpApp = sdk.Application{
104103
ID: id,

0 commit comments

Comments
 (0)