Skip to content

Commit

Permalink
feat: add support for helm env (#230)
Browse files Browse the repository at this point in the history
* feat: add helm env list

* feat: add helm env create

* feat: add helm env delete

* feat add helm create alias

* feat add helm create override
  • Loading branch information
pggb25 authored Dec 27, 2023
1 parent 660229e commit ffa9e28
Show file tree
Hide file tree
Showing 29 changed files with 635 additions and 717 deletions.
17 changes: 2 additions & 15 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)
_, projectId, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

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

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

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

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

err = utils.CreateEnvironmentVariable(client, projectId, envId, application.Id, utils.Key, utils.Value, utils.ApplicationScope)
err = utils.CreateEnvironmentVariable(client, 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/application_env_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var applicationEnvDeleteCmd = &cobra.Command{
}

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

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

err = utils.DeleteByKey(client, projectId, envId, application.Id, utils.ApplicationType, utils.Key)
err = utils.DeleteVariable(client, application.Id, utils.ApplicationType, utils.Key)

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

envVars, _, err := client.ApplicationEnvironmentVariableAPI.ListApplicationEnvironmentVariable(
context.Background(),
envVars, err := utils.ListEnvironmentVariables(
client,
application.Id,
).Execute()

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

secrets, _, err := client.ApplicationSecretAPI.ListApplicationSecrets(
context.Background(),
application.Id,
).Execute()
utils.ApplicationType,
)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -74,18 +64,12 @@ var applicationEnvListCmd = &cobra.Command{
envVarLines := utils.NewEnvVarLines()
var variables []utils.EnvVarLineOutput

for _, envVar := range envVars.GetResults() {
for _, envVar := range envVars {
s := utils.FromEnvironmentVariableToEnvVarLineOutput(envVar)
variables = append(variables, s)
envVarLines.Add(s)
}

for _, secret := range secrets.GetResults() {
s := utils.FromSecretToEnvVarLineOutput(secret)
variables = append(variables, s)
envVarLines.Add(s)
}

if jsonFlag {
utils.Println(utils.GetEnvVarJsonOutput(variables))
return
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")
}
17 changes: 2 additions & 15 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)
_, projectId, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

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

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

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

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

err = utils.CreateEnvironmentVariable(client, projectId, envId, container.Id, utils.Key, utils.Value, utils.ContainerScope)
err = utils.CreateEnvironmentVariable(client, 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/container_env_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var containerEnvDeleteCmd = &cobra.Command{
}

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

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

err = utils.DeleteByKey(client, projectId, envId, container.Id, utils.ContainerType, utils.Key)
err = utils.DeleteVariable(client, container.Id, utils.ContainerType, utils.Key)

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

envVars, _, err := client.ContainerEnvironmentVariableAPI.ListContainerEnvironmentVariable(
context.Background(),
envVars, err := utils.ListEnvironmentVariables(
client,
container.Id,
).Execute()

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

secrets, _, err := client.ContainerSecretAPI.ListContainerSecrets(
context.Background(),
container.Id,
).Execute()
utils.ContainerType,
)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -74,18 +64,12 @@ var containerEnvListCmd = &cobra.Command{
envVarLines := utils.NewEnvVarLines()
var variables []utils.EnvVarLineOutput

for _, envVar := range envVars.GetResults() {
for _, envVar := range envVars {
s := utils.FromEnvironmentVariableToEnvVarLineOutput(envVar)
variables = append(variables, s)
envVarLines.Add(s)
}

for _, secret := range secrets.GetResults() {
s := utils.FromSecretToEnvVarLineOutput(secret)
variables = append(variables, s)
envVarLines.Add(s)
}

if jsonFlag {
utils.Println(utils.GetEnvVarJsonOutput(variables))
return
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")
}
2 changes: 1 addition & 1 deletion cmd/cronjob_env_alias_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var cronjobEnvAliasCreateCmd = &cobra.Command{
}

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

if err != nil {
utils.PrintlnError(err)
Expand Down
17 changes: 2 additions & 15 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)
_, projectId, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)

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

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

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

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

err = utils.CreateEnvironmentVariable(client, projectId, envId, cronjob.CronJobResponse.Id, utils.Key, utils.Value, utils.JobScope)
err = utils.CreateEnvironmentVariable(client, 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/cronjob_env_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var cronjobEnvDeleteCmd = &cobra.Command{
}

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

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

err = utils.DeleteByKey(client, projectId, envId, cronjob.CronJobResponse.Id, utils.JobType, utils.Key)
err = utils.DeleteVariable(client, cronjob.CronJobResponse.Id, utils.JobType, utils.Key)

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

envVars, _, err := client.JobEnvironmentVariableAPI.ListJobEnvironmentVariable(
context.Background(),
envVars, err := utils.ListEnvironmentVariables(
client,
cronjob.CronJobResponse.Id,
).Execute()

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

secrets, _, err := client.JobSecretAPI.ListJobSecrets(
context.Background(),
cronjob.CronJobResponse.Id,
).Execute()
utils.JobType,
)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -74,18 +64,12 @@ var cronjobEnvListCmd = &cobra.Command{
envVarLines := utils.NewEnvVarLines()
var variables []utils.EnvVarLineOutput

for _, envVar := range envVars.GetResults() {
for _, envVar := range envVars {
s := utils.FromEnvironmentVariableToEnvVarLineOutput(envVar)
variables = append(variables, s)
envVarLines.Add(s)
}

for _, secret := range secrets.GetResults() {
s := utils.FromSecretToEnvVarLineOutput(secret)
variables = append(variables, s)
envVarLines.Add(s)
}

if jsonFlag {
utils.Println(utils.GetEnvVarJsonOutput(variables))
return
Expand Down
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.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 helmEnvCmd = &cobra.Command{
Use: "env",
Short: "Manage helm 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() {
helmCmd.AddCommand(helmEnvCmd)
}
24 changes: 24 additions & 0 deletions cmd/helm_env_alias.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 helmEnvAliasCmd = &cobra.Command{
Use: "alias",
Short: "Manage helm 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() {
helmEnvCmd.AddCommand(helmEnvAliasCmd)
}
Loading

0 comments on commit ffa9e28

Please sign in to comment.