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

feat: Improve env var support #425

Merged
merged 4 commits into from
Feb 19, 2025
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
2 changes: 1 addition & 1 deletion cmd/application_env_alias_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var applicationEnvAliasCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateAlias(client, projectId, envId, application.Id, utils.ApplicationType, utils.Key, utils.Alias, utils.ApplicationScope)
err = utils.CreateServiceAlias(client, projectId, envId, application.Id, utils.ApplicationType, utils.Key, utils.Alias, utils.ApplicationScope)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/application_env_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var applicationEnvCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

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

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/application_env_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var applicationEnvDeleteCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.DeleteVariable(client, application.Id, utils.ApplicationType, utils.Key)
err = utils.DeleteServiceVariable(client, application.Id, utils.ApplicationType, utils.Key)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/application_env_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var applicationEnvListCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

envVars, err := utils.ListEnvironmentVariables(
envVars, err := utils.ListServiceVariables(
client,
application.Id,
utils.ApplicationType,
Expand Down
2 changes: 1 addition & 1 deletion cmd/application_env_override_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var applicationEnvOverrideCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateOverride(client, projectId, envId, application.Id, utils.ApplicationType, utils.Key, utils.Value, utils.ApplicationScope)
err = utils.CreateServiceOverride(client, projectId, envId, application.Id, utils.ApplicationType, utils.Key, utils.Value, utils.ApplicationScope)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/application_env_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var applicationEnvUpdateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.UpdateEnvironmentVariable(client, utils.Key, utils.Value, application.Id, utils.ApplicationType)
err = utils.UpdateServiceVariable(client, utils.Key, utils.Value, application.Id, utils.ApplicationType)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/container_env_alias_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var containerEnvAliasCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateAlias(client, projectId, envId, container.Id, utils.ContainerType, utils.Key, utils.Alias, utils.ContainerScope)
err = utils.CreateServiceAlias(client, projectId, envId, container.Id, utils.ContainerType, utils.Key, utils.Alias, utils.ContainerScope)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/container_env_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var containerEnvCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

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

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/container_env_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var containerEnvDeleteCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.DeleteVariable(client, container.Id, utils.ContainerType, utils.Key)
err = utils.DeleteServiceVariable(client, container.Id, utils.ContainerType, utils.Key)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/container_env_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var containerEnvListCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

envVars, err := utils.ListEnvironmentVariables(
envVars, err := utils.ListServiceVariables(
client,
container.Id,
utils.ContainerType,
Expand Down
2 changes: 1 addition & 1 deletion cmd/container_env_override_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var containerEnvOverrideCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateOverride(client, projectId, envId, container.Id, utils.ContainerType, utils.Key, utils.Value, utils.ContainerScope)
err = utils.CreateServiceOverride(client, projectId, envId, container.Id, utils.ContainerType, utils.Key, utils.Value, utils.ContainerScope)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/container_env_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var containerEnvUpdateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.UpdateEnvironmentVariable(client, utils.Key, utils.Value, container.Id, utils.ContainerType)
err = utils.UpdateServiceVariable(client, utils.Key, utils.Value, container.Id, utils.ContainerType)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjob_env_alias_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var cronjobEnvAliasCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateAlias(client, projectId, envId, cronjob.CronJobResponse.Id, utils.JobType, utils.Key, utils.Alias, utils.JobScope)
err = utils.CreateServiceAlias(client, projectId, envId, cronjob.CronJobResponse.Id, utils.JobType, utils.Key, utils.Alias, utils.JobScope)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjob_env_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var cronjobEnvCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

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

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjob_env_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var cronjobEnvDeleteCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.DeleteVariable(client, cronjob.CronJobResponse.Id, utils.JobType, utils.Key)
err = utils.DeleteServiceVariable(client, cronjob.CronJobResponse.Id, utils.JobType, utils.Key)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjob_env_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var cronjobEnvListCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

envVars, err := utils.ListEnvironmentVariables(
envVars, err := utils.ListServiceVariables(
client,
cronjob.CronJobResponse.Id,
utils.JobType,
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjob_env_override_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var cronjobEnvOverrideCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateOverride(client, projectId, envId, cronjob.CronJobResponse.Id, utils.JobType, utils.Key, utils.Value, utils.JobScope)
err = utils.CreateServiceOverride(client, projectId, envId, cronjob.CronJobResponse.Id, utils.JobType, utils.Key, utils.Value, utils.JobScope)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjob_env_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var cronjobEnvUpdateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.UpdateEnvironmentVariable(client, utils.Key, utils.Value, cronjob.CronJobResponse.Id, utils.JobType)
err = utils.UpdateServiceVariable(client, utils.Key, utils.Value, cronjob.CronJobResponse.Id, utils.JobType)

if err != nil {
utils.PrintlnError(err)
Expand Down
25 changes: 25 additions & 0 deletions cmd/environment_env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"github.com/spf13/cobra"
"os"

"github.com/qovery/qovery-cli/utils"
)

var environmentEnvCmd = &cobra.Command{
Use: "env",
Short: "Manage environment variables and secrets",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)

if len(args) == 0 {
_ = cmd.Help()
os.Exit(0)
}
},
}

func init() {
environmentCmd.AddCommand(environmentEnvCmd)
}
25 changes: 25 additions & 0 deletions cmd/environment_env_alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"github.com/spf13/cobra"
"os"

"github.com/qovery/qovery-cli/utils"
)

var environmentEnvAliasCmd = &cobra.Command{
Use: "alias",
Short: "Manage environment variable and secret aliases",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)

if len(args) == 0 {
_ = cmd.Help()
os.Exit(0)
}
},
}

func init() {
environmentEnvCmd.AddCommand(environmentEnvAliasCmd)
}
65 changes: 65 additions & 0 deletions cmd/environment_env_alias_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cmd

import (
"context"
"fmt"
"os"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/qovery/qovery-cli/utils"
)

var environmentEnvAliasCreateCmd = &cobra.Command{
Use: "create",
Short: "Create environment variable or secret alias",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)

tokenType, token, err := utils.GetAccessToken()
checkError(err)

client := utils.GetQoveryClient(tokenType, token)

organizationId, _, _, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
checkError(err)

projects, _, err := client.ProjectsAPI.ListProject(context.Background(), organizationId).Execute()
checkError(err)

project := utils.FindByProjectName(projects.GetResults(), projectName)

environments, _, err := client.EnvironmentsAPI.ListEnvironment(context.Background(), project.Id).Execute()
checkError(err)

environment := utils.FindByEnvironmentName(environments.GetResults(), environmentName)

if environment == nil {
utils.PrintlnError(fmt.Errorf("environment %s not found", environmentName))
utils.PrintlnInfo("You can list all environments with: qovery environment list")
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateEnvironmentAlias(client, projectId, environment.Id, utils.Key, utils.Alias, utils.EnvironmentScope)
checkError(err)

utils.Println(fmt.Sprintf("Alias %s has been created", pterm.FgBlue.Sprintf("%s", utils.Alias)))
},
}

func init() {
environmentEnvAliasCmd.AddCommand(environmentEnvAliasCreateCmd)
environmentEnvAliasCreateCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
environmentEnvAliasCreateCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
environmentEnvAliasCreateCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
environmentEnvAliasCreateCmd.Flags().StringVarP(&utils.Key, "key", "k", "", "Environment variable or secret key")
environmentEnvAliasCreateCmd.Flags().StringVarP(&utils.Alias, "alias", "", "", "Environment variable or secret alias")
environmentEnvAliasCreateCmd.Flags().StringVarP(&utils.EnvironmentScope, "scope", "", "ENVIRONMENT", "Scope of this alias <PROJECT|ENVIRONMENT>")

_ = environmentEnvAliasCreateCmd.MarkFlagRequired("project")
_ = environmentEnvAliasCreateCmd.MarkFlagRequired("environment")
_ = environmentEnvAliasCreateCmd.MarkFlagRequired("key")
_ = environmentEnvAliasCreateCmd.MarkFlagRequired("alias")
}
65 changes: 65 additions & 0 deletions cmd/environment_env_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cmd

import (
"context"
"fmt"
"os"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/qovery/qovery-cli/utils"
)

var environmentEnvCreateCmd = &cobra.Command{
Use: "create",
Short: "Create environment variable or secret",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)

tokenType, token, err := utils.GetAccessToken()
checkError(err)

client := utils.GetQoveryClient(tokenType, token)

organizationId, _, _, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
checkError(err)

projects, _, err := client.ProjectsAPI.ListProject(context.Background(), organizationId).Execute()
checkError(err)

project := utils.FindByProjectName(projects.GetResults(), projectName)

environments, _, err := client.EnvironmentsAPI.ListEnvironment(context.Background(), project.Id).Execute()
checkError(err)

environment := utils.FindByEnvironmentName(environments.GetResults(), environmentName)
if environment == nil {
utils.PrintlnError(fmt.Errorf("environment %s not found", environmentName))
utils.PrintlnInfo("You can list all environments with: qovery environment list")
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateEnvironmentVariable(client, projectId, environment.Id, utils.Key, utils.Value, utils.IsSecret)
checkError(err)

utils.Println(fmt.Sprintf("Environment variable %s has been created", pterm.FgBlue.Sprintf("%s", utils.Key)))
},
}

func init() {
environmentEnvCmd.AddCommand(environmentEnvCreateCmd)
environmentEnvCreateCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
environmentEnvCreateCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
environmentEnvCreateCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
environmentEnvCreateCmd.Flags().StringVarP(&utils.Key, "key", "k", "", "Environment variable or secret key")
environmentEnvCreateCmd.Flags().StringVarP(&utils.Value, "value", "v", "", "Environment variable or secret value")
environmentEnvCreateCmd.Flags().StringVarP(&utils.EnvironmentScope, "scope", "", "ENVIRONMENT", "Scope of this env var <PROJECT|ENVIRONMENT>")
environmentEnvCreateCmd.Flags().BoolVarP(&utils.IsSecret, "secret", "", false, "This environment variable is a secret")

_ = environmentEnvCreateCmd.MarkFlagRequired("project")
_ = environmentEnvCreateCmd.MarkFlagRequired("environment")
_ = environmentEnvCreateCmd.MarkFlagRequired("key")
_ = environmentEnvCreateCmd.MarkFlagRequired("value")
}
Loading
Loading