Skip to content

Commit

Permalink
feat: add helm env list
Browse files Browse the repository at this point in the history
  • Loading branch information
pggb25 committed Dec 22, 2023
1 parent 6eb3515 commit b1c791b
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 114 deletions.
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
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
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
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)
}
105 changes: 105 additions & 0 deletions cmd/helm_env_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package cmd

import (
"context"
"fmt"
"os"

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

var helmEnvListCmd = &cobra.Command{
Use: "list",
Short: "List helm environment variables",
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)

_, _, 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
}

envVars, err := utils.ListEnvironmentVariables(
client,
helm.Id,
utils.HelmType,
)

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

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

envVarLines := utils.NewEnvVarLines()
var variables []utils.EnvVarLineOutput

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

if jsonFlag {
utils.Println(utils.GetEnvVarJsonOutput(variables))
return
}

err = utils.PrintTable(envVarLines.Header(utils.PrettyPrint), envVarLines.Lines(utils.ShowValues, utils.PrettyPrint))

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

func init() {
helmEnvCmd.AddCommand(helmEnvListCmd)
helmEnvListCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
helmEnvListCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
helmEnvListCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
helmEnvListCmd.Flags().StringVarP(&helmName, "helm", "n", "", "helm Name")
helmEnvListCmd.Flags().BoolVarP(&utils.ShowValues, "show-values", "", false, "Show env var values")
helmEnvListCmd.Flags().BoolVarP(&utils.PrettyPrint, "pretty-print", "", false, "Pretty print output")
helmEnvListCmd.Flags().BoolVarP(&jsonFlag, "json", "", false, "JSON output")

_ = helmEnvListCmd.MarkFlagRequired("helm")
}
26 changes: 5 additions & 21 deletions cmd/lifecycle_env_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,11 @@ var lifecycleEnvListCmd = &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,
lifecycle.LifecycleJobResponse.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(),
lifecycle.LifecycleJobResponse.Id,
).Execute()
utils.JobType,
)

if err != nil {
utils.PrintlnError(err)
Expand All @@ -74,18 +64,12 @@ var lifecycleEnvListCmd = &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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/posthog/posthog-go v0.0.0-20221221115252-24dfed35d71a
github.com/pterm/pterm v0.12.55
github.com/qovery/qovery-client-go v0.0.0-20231219130711-1b52194296f5
github.com/qovery/qovery-client-go v0.0.0-20231222093609-d7ae5a912bea
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ github.com/qovery/qovery-client-go v0.0.0-20231218142939-5f77c5a27bb7 h1:FukfJyZ
github.com/qovery/qovery-client-go v0.0.0-20231218142939-5f77c5a27bb7/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o=
github.com/qovery/qovery-client-go v0.0.0-20231219130711-1b52194296f5 h1:uTmfOdyWH7/Ldf/LT3X/P0OlBg9J8Pe9PWR8MbdaWao=
github.com/qovery/qovery-client-go v0.0.0-20231219130711-1b52194296f5/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o=
github.com/qovery/qovery-client-go v0.0.0-20231222093609-d7ae5a912bea h1:/MLgKpXXPqTJBclZ1kFbC42BXQjl77+COijlmiFpnBg=
github.com/qovery/qovery-client-go v0.0.0-20231222093609-d7ae5a912bea/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand Down
Loading

0 comments on commit b1c791b

Please sign in to comment.