Skip to content

Commit

Permalink
tidy env set output and backwards compatibility for linked app deploys (
Browse files Browse the repository at this point in the history
  • Loading branch information
ianedwards authored Mar 13, 2024
1 parent 69a8835 commit 7f7bd45
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
3 changes: 2 additions & 1 deletion api/server/handlers/environment_groups/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
44 changes: 40 additions & 4 deletions cli/cmd/commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 7f7bd45

Please sign in to comment.