Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: creation of env variable at Project and Environment scope #236

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading