diff --git a/cmd/application_env_create.go b/cmd/application_env_create.go index 044719f4..b6ae5e61 100644 --- a/cmd/application_env_create.go +++ b/cmd/application_env_create.go @@ -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) @@ -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) diff --git a/cmd/container_env_create.go b/cmd/container_env_create.go index 3c63e8e6..5bb1c3d8 100644 --- a/cmd/container_env_create.go +++ b/cmd/container_env_create.go @@ -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) @@ -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) diff --git a/cmd/cronjob_env_create.go b/cmd/cronjob_env_create.go index 1d7ab7c0..601ccc29 100644 --- a/cmd/cronjob_env_create.go +++ b/cmd/cronjob_env_create.go @@ -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) @@ -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) diff --git a/cmd/helm_env_create.go b/cmd/helm_env_create.go index 77db9243..a81da75d 100644 --- a/cmd/helm_env_create.go +++ b/cmd/helm_env_create.go @@ -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) @@ -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) diff --git a/cmd/lifecycle_env_create.go b/cmd/lifecycle_env_create.go index 4c8521ab..8f6f9bf7 100644 --- a/cmd/lifecycle_env_create.go +++ b/cmd/lifecycle_env_create.go @@ -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) @@ -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) diff --git a/utils/env_var.go b/utils/env_var.go index 635d78d1..3826f6a4 100644 --- a/utils/env_var.go +++ b/utils/env_var.go @@ -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 } @@ -172,7 +174,7 @@ func CreateEnvironmentVariable( Value: value, MountPath: qovery.NullableString{}, IsSecret: isSecret, - VariableScope: variableScope, + VariableScope: parentScope, VariableParentId: parentId, } @@ -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":