Skip to content

Commit

Permalink
fix(engine): env ascode with many secrets (#5839)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Jun 9, 2021
1 parent 1f88624 commit 65c6e95
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions engine/api/environment/environment_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,29 @@ func ParseAndImport(ctx context.Context, db gorpmapper.SqlExecutorWithTx, proj s
envSecrets := make([]sdk.Variable, 0)

//Compute variables
for p, v := range eenv.Values {
switch v.Type {
for p := range eenv.Values {
value := eenv.Values[p].Value
vtype := eenv.Values[p].Type

switch vtype {
case "":
v.Type = sdk.StringVariable
vtype = sdk.StringVariable
case sdk.SecretVariable:
secret, err := decryptFunc(db, proj.ID, v.Value)
secret, err := decryptFunc(db, proj.ID, value)
if err != nil {
return env, nil, nil, sdk.WrapError(err, "Unable to decrypt secret variable")
}
v.Value = secret
value = secret
}

vv := sdk.EnvironmentVariable{Name: p, Type: v.Type, Value: v.Value, EnvironmentID: env.ID}
vv := sdk.EnvironmentVariable{Name: p, Type: vtype, Value: value, EnvironmentID: env.ID}
env.Variables = append(env.Variables, vv)

if v.Type == sdk.SecretVariable {
if vtype == sdk.SecretVariable {
envSecrets = append(envSecrets, sdk.Variable{
Name: fmt.Sprintf("cds.env.%s", vv.Name),
Type: v.Type,
Value: v.Value,
Type: vtype,
Value: value,
})
}
}
Expand Down

0 comments on commit 65c6e95

Please sign in to comment.