Skip to content

Commit

Permalink
fix: creation of env variable at Project and Environment scope
Browse files Browse the repository at this point in the history
  • Loading branch information
pggb25 committed Jan 2, 2024
1 parent 4be9e3b commit 229128c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 33 deletions.
4 changes: 2 additions & 2 deletions cmd/application_env_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var applicationEnvCreateCmd = &cobra.Command{
}

client := utils.GetQoveryClient(tokenType, token)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
_, projectId, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -49,7 +49,7 @@ var applicationEnvCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateEnvironmentVariable(client, application.Id, utils.ApplicationScope, utils.Key, utils.Value, utils.IsSecret)
err = utils.CreateEnvironmentVariable(client, projectId, envId, application.Id, utils.ApplicationScope, utils.Key, utils.Value, utils.IsSecret)

if err != nil {
utils.PrintlnError(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/container_env_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var containerEnvCreateCmd = &cobra.Command{
}

client := utils.GetQoveryClient(tokenType, token)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
_, projectId, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -49,7 +49,7 @@ var containerEnvCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateEnvironmentVariable(client, container.Id, utils.ContainerScope, utils.Key, utils.Value, utils.IsSecret)
err = utils.CreateEnvironmentVariable(client, projectId, envId, container.Id, utils.ContainerScope, utils.Key, utils.Value, utils.IsSecret)

if err != nil {
utils.PrintlnError(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/cronjob_env_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var cronjobEnvCreateCmd = &cobra.Command{
}

client := utils.GetQoveryClient(tokenType, token)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
_, projectId, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -49,7 +49,7 @@ var cronjobEnvCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateEnvironmentVariable(client, cronjob.CronJobResponse.Id, utils.JobScope, utils.Key, utils.Value, utils.IsSecret)
err = utils.CreateEnvironmentVariable(client, projectId, envId, cronjob.CronJobResponse.Id, utils.JobScope, utils.Key, utils.Value, utils.IsSecret)

if err != nil {
utils.PrintlnError(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/helm_env_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var helmEnvCreateCmd = &cobra.Command{
}

client := utils.GetQoveryClient(tokenType, token)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
_, projectId, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -49,7 +49,7 @@ var helmEnvCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateEnvironmentVariable(client, helm.Id, utils.HelmScope, utils.Key, utils.Value, utils.IsSecret)
err = utils.CreateEnvironmentVariable(client, projectId, envId, helm.Id, utils.HelmScope, utils.Key, utils.Value, utils.IsSecret)

if err != nil {
utils.PrintlnError(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/lifecycle_env_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var lifecycleEnvCreateCmd = &cobra.Command{
}

client := utils.GetQoveryClient(tokenType, token)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
_, projectId, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -49,7 +49,7 @@ var lifecycleEnvCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateEnvironmentVariable(client, lifecycle.LifecycleJobResponse.Id, utils.JobScope, utils.Key, utils.Value, utils.IsSecret)
err = utils.CreateEnvironmentVariable(client, projectId, envId, lifecycle.LifecycleJobResponse.Id, utils.JobScope, utils.Key, utils.Value, utils.IsSecret)

if err != nil {
utils.PrintlnError(err)
Expand Down
28 changes: 5 additions & 23 deletions utils/env_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,16 @@ func FromEnvironmentVariableToEnvVarLineOutput(envVar qovery.VariableResponse) E

func CreateEnvironmentVariable(
client *qovery.APIClient,
parentId string,
projectId string,
environmentId string,
serviceId string,
scope string,
key string,
value string,
isSecret bool,
) error {

variableScope, err := VariableScopeFrom(scope)
parentId, parentScope, err := getParentIdByScope(scope, projectId, environmentId, serviceId)
if err != nil {
return err
}
Expand All @@ -172,7 +174,7 @@ func CreateEnvironmentVariable(
Value: value,
MountPath: qovery.NullableString{},
IsSecret: isSecret,
VariableScope: variableScope,
VariableScope: parentScope,
VariableParentId: parentId,
}

Expand Down Expand Up @@ -228,26 +230,6 @@ func ServiceTypeToScope(serviceType ServiceType) (qovery.APIVariableScopeEnum, e
return qovery.APIVARIABLESCOPEENUM_BUILT_IN, fmt.Errorf("the service type %s is not supported", serviceType)
}

func VariableScopeFrom(scope string) (qovery.APIVariableScopeEnum, error) {
switch scope {
case "APPLICATION":
return qovery.APIVARIABLESCOPEENUM_APPLICATION, nil
case "BUILT_IN":
return qovery.APIVARIABLESCOPEENUM_BUILT_IN, nil
case "ENVIRONMENT":
return qovery.APIVARIABLESCOPEENUM_ENVIRONMENT, nil
case "PROJECT":
return qovery.APIVARIABLESCOPEENUM_PROJECT, nil
case "CONTAINER":
return qovery.APIVARIABLESCOPEENUM_CONTAINER, nil
case "JOB":
return qovery.APIVARIABLESCOPEENUM_JOB, nil
case "HELM":
return qovery.APIVARIABLESCOPEENUM_HELM, nil
}
return qovery.APIVARIABLESCOPEENUM_BUILT_IN, fmt.Errorf("the scope %s is not supported", scope)
}

func getParentIdByScope(scope string, projectId string, environmentId string, serviceId string) (string, qovery.APIVariableScopeEnum, error) {
switch scope {
case "PROJECT":
Expand Down

0 comments on commit 229128c

Please sign in to comment.