From 7f7bd450dd012fbe907b31d2f5810e9a69b1d19d Mon Sep 17 00:00:00 2001 From: ianedwards Date: Wed, 13 Mar 2024 15:13:16 -0400 Subject: [PATCH] tidy env set output and backwards compatibility for linked app deploys (#4406) --- .../handlers/environment_groups/create.go | 3 +- cli/cmd/commands/env.go | 44 +++++++++++++++++-- go.mod | 2 +- go.sum | 4 +- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/api/server/handlers/environment_groups/create.go b/api/server/handlers/environment_groups/create.go index 096892bdd0..9bf66c76f2 100644 --- a/api/server/handlers/environment_groups/create.go +++ b/api/server/handlers/environment_groups/create.go @@ -120,7 +120,8 @@ func (c *UpdateEnvironmentGroupHandler) ServeHTTP(w http.ResponseWriter, r *http Variables: request.Deletions.Variables, Secrets: request.Deletions.Secrets, }, - IsEnvOverride: request.IsEnvOverride, + IsEnvOverride: request.IsEnvOverride, + SkipAppAutoDeploy: true, // switch to false once CCP changes are in, so as to not miss any redeploys })) if err != nil { err := telemetry.Error(ctx, span, err, "unable to create environment group") diff --git a/cli/cmd/commands/env.go b/cli/cmd/commands/env.go index 82b805e638..05f2d01bd2 100644 --- a/cli/cmd/commands/env.go +++ b/cli/cmd/commands/env.go @@ -4,7 +4,9 @@ import ( "context" "fmt" "os" + "time" + "github.com/briandowns/spinner" "github.com/fatih/color" api "github.com/porter-dev/porter/api/client" "github.com/porter-dev/porter/api/server/handlers/environment_groups" @@ -179,9 +181,13 @@ func setEnv(ctx context.Context, user *types.GetAuthenticatedUserResponse, clien Secrets: secrets, } + s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) + s.Color("cyan") // nolint:errcheck,gosec + if appName != "" { - color.New(color.FgGreen).Printf("Setting environment variables for app %s...\n", appName) // nolint:errcheck,gosec + s.Suffix = fmt.Sprintf(" Setting environment variables for app %s...", appName) + s.Start() _, err := client.UpdateApp(ctx, api.UpdateAppInput{ ProjectID: cliConf.Project, ClusterID: cliConf.Cluster, @@ -193,11 +199,15 @@ func setEnv(ctx context.Context, user *types.GetAuthenticatedUserResponse, clien if err != nil { return fmt.Errorf("could not set app env variables: %w", err) } + s.Stop() + + color.New(color.FgGreen).Printf("Updated environment variable keys in app %s:\n", appName) // nolint:errcheck,gosec } if envGroupName != "" { - color.New(color.FgGreen).Printf("Setting environment variables for environment group %s...\n", envGroupName) // nolint:errcheck,gosec + s.Suffix = fmt.Sprintf(" Setting environment variables for environment group %s...", envGroupName) + s.Start() err := client.UpdateEnvGroup(ctx, api.UpdateEnvGroupInput{ ProjectID: cliConf.Project, ClusterID: cliConf.Cluster, @@ -208,6 +218,16 @@ func setEnv(ctx context.Context, user *types.GetAuthenticatedUserResponse, clien if err != nil { return fmt.Errorf("could not set env group env variables: %w", err) } + s.Stop() + + color.New(color.FgGreen).Printf("Updated keys in environment group %s:\n", envGroupName) // nolint:errcheck,gosec + } + + for k, v := range envVars.Variables { + color.New(color.FgBlue).Printf("%s=%s\n", k, v) // nolint:errcheck,gosec + } + for k := range envVars.Secrets { + color.New(color.FgBlue).Printf("%s=********\n", k) // nolint:errcheck,gosec } return nil @@ -231,9 +251,13 @@ func unsetEnv(ctx context.Context, user *types.GetAuthenticatedUserResponse, cli Secrets: secrets, } + s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) + s.Color("cyan") // nolint:errcheck,gosec + if appName != "" { - color.New(color.FgGreen).Printf("Unsetting environment variables for app %s...\n", appName) // nolint:errcheck,gosec + s.Suffix = fmt.Sprintf(" Unsetting environment variables for app %s...", appName) + s.Start() _, err := client.UpdateApp(ctx, api.UpdateAppInput{ ProjectID: cliConf.Project, ClusterID: cliConf.Cluster, @@ -249,10 +273,13 @@ func unsetEnv(ctx context.Context, user *types.GetAuthenticatedUserResponse, cli if err != nil { return fmt.Errorf("could not unset app env variables: %w", err) } + s.Stop() + + color.New(color.FgGreen).Printf("Unset environment variable keys in app %s:\n", appName) // nolint:errcheck,gosec } if envGroupName != "" { - color.New(color.FgGreen).Printf("Unsetting environment variables for environment group %s...\n", envGroupName) // nolint:errcheck,gosec + s.Suffix = fmt.Sprintf(" Unsetting environment variables for environment group %s...", envGroupName) err := client.UpdateEnvGroup(ctx, api.UpdateEnvGroupInput{ ProjectID: cliConf.Project, @@ -266,6 +293,15 @@ func unsetEnv(ctx context.Context, user *types.GetAuthenticatedUserResponse, cli if err != nil { return fmt.Errorf("could not unset env group env variables: %w", err) } + + color.New(color.FgGreen).Printf("Unset the keys in environment group %s:\n", envGroupName) // nolint:errcheck,gosec + } + + for _, v := range envVarDeletions.Variables { + color.New(color.FgBlue).Printf("%s\n", v) // nolint:errcheck,gosec + } + for _, v := range envVarDeletions.Secrets { + color.New(color.FgBlue).Printf("%s\n", v) // nolint:errcheck,gosec } return nil diff --git a/go.mod b/go.mod index e25c31432c..0ee926993e 100644 --- a/go.mod +++ b/go.mod @@ -83,7 +83,7 @@ require ( github.com/matryer/is v1.4.0 github.com/nats-io/nats.go v1.24.0 github.com/open-policy-agent/opa v0.44.0 - github.com/porter-dev/api-contracts v0.2.122 + github.com/porter-dev/api-contracts v0.2.123 github.com/riandyrn/otelchi v0.5.1 github.com/santhosh-tekuri/jsonschema/v5 v5.0.1 github.com/stefanmcshane/helm v0.0.0-20221213002717-88a4a2c6e77d diff --git a/go.sum b/go.sum index a68ae67d34..c1de171761 100644 --- a/go.sum +++ b/go.sum @@ -1523,8 +1523,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw= -github.com/porter-dev/api-contracts v0.2.122 h1:Qy7SZzcXSvIuUGq6MB99qt8eTwtMQzlqZQMdCxE8ZCs= -github.com/porter-dev/api-contracts v0.2.122/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8= +github.com/porter-dev/api-contracts v0.2.123 h1:bDtyC2ueirKmu9NN1YEClv2qVrMjvu913HGibG7ISRQ= +github.com/porter-dev/api-contracts v0.2.123/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8= github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M= github.com/porter-dev/switchboard v0.0.3/go.mod h1:xSPzqSFMQ6OSbp42fhCi4AbGbQbsm6nRvOkrblFeXU4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=