Skip to content

Commit

Permalink
feat add helm create override
Browse files Browse the repository at this point in the history
  • Loading branch information
pggb25 committed Dec 27, 2023
1 parent bed182e commit 0a781c5
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 178 deletions.
1 change: 0 additions & 1 deletion cmd/application_env_alias_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ 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)

if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/application_env_override_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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.CreateOverride(client, projectId, envId, application.Id, utils.ApplicationType, utils.Key, utils.Value, utils.ApplicationScope)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -73,4 +73,5 @@ func init() {

_ = applicationEnvOverrideCreateCmd.MarkFlagRequired("key")
_ = applicationEnvOverrideCreateCmd.MarkFlagRequired("application")
_ = applicationEnvOverrideCreateCmd.MarkFlagRequired("value")
}
2 changes: 1 addition & 1 deletion cmd/container_env_alias_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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.CreateAlias(client, projectId, envId, container.Id, utils.ContainerType, utils.Key, utils.Alias, utils.ContainerScope)

if err != nil {
utils.PrintlnError(err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/container_env_override_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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.CreateOverride(client, projectId, envId, container.Id, utils.ContainerType, utils.Key, utils.Value, utils.ContainerScope)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -73,4 +73,5 @@ func init() {

_ = containerEnvOverrideCreateCmd.MarkFlagRequired("key")
_ = containerEnvOverrideCreateCmd.MarkFlagRequired("container")
_ = containerEnvOverrideCreateCmd.MarkFlagRequired("value")
}
3 changes: 2 additions & 1 deletion cmd/cronjob_env_override_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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.CreateOverride(client, projectId, envId, cronjob.CronJobResponse.Id, utils.JobType, utils.Key, utils.Value, utils.JobScope)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -73,4 +73,5 @@ func init() {

_ = cronjobEnvOverrideCreateCmd.MarkFlagRequired("key")
_ = cronjobEnvOverrideCreateCmd.MarkFlagRequired("cronjob")
_ = cronjobEnvOverrideCreateCmd.MarkFlagRequired("value")
}
24 changes: 24 additions & 0 deletions cmd/helm_env_override.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"github.com/qovery/qovery-cli/utils"
"github.com/spf13/cobra"
"os"
)

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

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

func init() {
helmEnvCmd.AddCommand(helmEnvOverrideCmd)
}
76 changes: 76 additions & 0 deletions cmd/helm_env_override_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package cmd

import (
"context"
"fmt"
"os"

"github.com/pterm/pterm"
"github.com/qovery/qovery-cli/utils"
"github.com/spf13/cobra"
)

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

tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

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

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

helms, _, err := client.HelmsAPI.ListHelms(context.Background(), envId).Execute()

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

helm := utils.FindByHelmName(helms.GetResults(), helmName)

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

err = utils.CreateOverride(client, projectId, envId, helm.Id, utils.HelmType, utils.Key, utils.Value, utils.HelmScope)

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

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

func init() {
helmEnvOverrideCmd.AddCommand(helmEnvOverrideCreateCmd)
helmEnvOverrideCreateCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
helmEnvOverrideCreateCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
helmEnvOverrideCreateCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
helmEnvOverrideCreateCmd.Flags().StringVarP(&helmName, "helm", "n", "", "helm Name")
helmEnvOverrideCreateCmd.Flags().StringVarP(&utils.Key, "key", "k", "", "Environment variable or secret key")
helmEnvOverrideCreateCmd.Flags().StringVarP(&utils.Value, "value", "", "", "Environment variable or secret value")
helmEnvOverrideCreateCmd.Flags().StringVarP(&utils.HelmScope, "scope", "", "HELM", "Scope of this alias <PROJECT|ENVIRONMENT|HELM>")

_ = helmEnvOverrideCreateCmd.MarkFlagRequired("key")
_ = helmEnvOverrideCreateCmd.MarkFlagRequired("helm")
}
3 changes: 2 additions & 1 deletion cmd/lifecycle_env_override_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var lifecycleEnvOverrideCreateCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

err = utils.CreateOverride(client, projectId, envId, lifecycle.LifecycleJobResponse.Id, utils.JobType, utils.Key, &utils.Value, utils.JobScope)
err = utils.CreateOverride(client, projectId, envId, lifecycle.LifecycleJobResponse.Id, utils.JobType, utils.Key, utils.Value, utils.JobScope)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -73,4 +73,5 @@ func init() {

_ = lifecycleEnvOverrideCreateCmd.MarkFlagRequired("key")
_ = lifecycleEnvOverrideCreateCmd.MarkFlagRequired("lifecycle")
_ = lifecycleEnvOverrideCreateCmd.MarkFlagRequired("value")
}
Loading

0 comments on commit 0a781c5

Please sign in to comment.