Skip to content

Commit

Permalink
Fix Env Var Issues (#1547)
Browse files Browse the repository at this point in the history
* fix env var issues

* make error message less confusing

* fix variable secret value test

* fix test
  • Loading branch information
sunkickr authored and kushalmalani committed Feb 13, 2024
1 parent 048286d commit c3c276b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
14 changes: 9 additions & 5 deletions cloud/deployment/deployment_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (

var (
errVarBool = false
errVarCreateUpdate = errors.New("there was an error while creating or updating one or more of the environment variables. Check the logs above for more information")
errVarCreateUpdate = errors.New("there was an error while creating or updating one or more of the environment variables. Check the command output above for more information")
environmentVariablesObjects = []astroplatformcore.DeploymentEnvironmentVariable{}
printValue = "****"
)

func VariableList(deploymentID, variableKey, ws, envFile, deploymentName string, useEnvFile bool, platformCoreClient astroplatformcore.CoreClient, out io.Writer) error {
Expand Down Expand Up @@ -47,13 +48,16 @@ func VariableList(deploymentID, variableKey, ws, envFile, deploymentName string,

var nbEnvVarFound int
for i := range environmentVariablesObjects {
if environmentVariablesObjects[i].Value != nil && !environmentVariablesObjects[i].IsSecret {
printValue = *environmentVariablesObjects[i].Value
}
if environmentVariablesObjects[i].Key == variableKey {
nbEnvVarFound++
varTab.AddRow([]string{strconv.Itoa(nbEnvVarFound), environmentVariablesObjects[i].Key, *environmentVariablesObjects[i].Value, strconv.FormatBool(environmentVariablesObjects[i].IsSecret)}, false)
varTab.AddRow([]string{strconv.Itoa(nbEnvVarFound), environmentVariablesObjects[i].Key, printValue, strconv.FormatBool(environmentVariablesObjects[i].IsSecret)}, false)
break
} else if variableKey == "" {
nbEnvVarFound++
varTab.AddRow([]string{strconv.Itoa(nbEnvVarFound), environmentVariablesObjects[i].Key, *environmentVariablesObjects[i].Value, strconv.FormatBool(environmentVariablesObjects[i].IsSecret)}, false)
varTab.AddRow([]string{strconv.Itoa(nbEnvVarFound), environmentVariablesObjects[i].Key, printValue, strconv.FormatBool(environmentVariablesObjects[i].IsSecret)}, false)
}
}

Expand Down Expand Up @@ -138,8 +142,8 @@ func VariableModify(deploymentID, variableKey, variableValue, ws, envFile, deplo
var index int
for i := range environmentVariablesObjects {
index = i + 1
printValue := notApplicable
if environmentVariablesObjects[i].Value != nil {

if environmentVariablesObjects[i].Value != nil && !environmentVariablesObjects[i].IsSecret {
printValue = *environmentVariablesObjects[i].Value
}
varTab.AddRow([]string{strconv.Itoa(index), environmentVariablesObjects[i].Key, printValue, strconv.FormatBool(environmentVariablesObjects[i].IsSecret)}, false)
Expand Down
6 changes: 4 additions & 2 deletions cloud/deployment/deployment_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ func TestVariableModify(t *testing.T) {
})

t.Run("success with secret value", func(t *testing.T) {
printValue = "****"

mockCoreClient.On("GetDeploymentOptionsWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&GetDeploymentOptionsResponseOK, nil).Times(1)
mockPlatformCoreClient.On("UpdateDeploymentWithResponse", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&mockUpdateDeploymentResponse, nil).Times(1)
mockPlatformCoreClient.On("ListDeploymentsWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&mockListDeploymentsResponse, nil).Times(2)
Expand All @@ -168,11 +170,11 @@ func TestVariableModify(t *testing.T) {
}

buf := new(bytes.Buffer)
err := VariableModify("test-id-1", "test-key-2", "test-value-2", ws, "", "", []string{}, false, false, false, mockCoreClient, mockPlatformCoreClient, buf)
err := VariableModify("test-id-1", "test-key-2", "test-value-2", ws, "", "", []string{}, false, false, true, mockCoreClient, mockPlatformCoreClient, buf)
assert.NoError(t, err)
assert.Contains(t, buf.String(), "test-key-1")
assert.Contains(t, buf.String(), "test-key-2")
assert.Contains(t, buf.String(), "N/A")
assert.Contains(t, buf.String(), "****")
mockCoreClient.AssertExpectations(t)
mockPlatformCoreClient.AssertExpectations(t)
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloud/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func deploymentCreate(cmd *cobra.Command, _ []string, out io.Writer) error { //n
return errors.New("Invalid --type value")
}
if cicdEnforcement != "" && !(cicdEnforcement == enable || cicdEnforcement == disable) {
return errors.New("Invalid --enforce-cicd value")
return errors.New("Invalid --cicd-enforcment value")
}
if deploymentCreateEnforceCD && cicdEnforcement == disable {
return errors.New("flags --enforce-cicd and --cicd-enforcment contradict each other. Use only --cicd-enforcment")
Expand Down

0 comments on commit c3c276b

Please sign in to comment.