fix: generating secrets works again again
continuous-integration/drone/push Build is passing Details

Closes coop-cloud/go-abra#68.
This commit is contained in:
decentral1se 2021-09-07 08:27:36 +02:00
parent b477bf8ece
commit a06870f5cb
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 19 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"os"
"strconv"
abraFormatter "coopcloud.tech/abra/cli/formatter"
@ -19,6 +20,7 @@ import (
var allSecrets bool
var allSecretsFlag = &cli.BoolFlag{
Name: "all",
Aliases: []string{"A"},
Value: false,
Destination: &allSecrets,
Usage: "Generate all secrets",
@ -33,8 +35,14 @@ var appSecretGenerateCommand = &cli.Command{
Action: func(c *cli.Context) error {
app := internal.ValidateApp(c)
if c.Args().Len() == 1 && !allSecrets {
err := errors.New("missing arguments <secret>/<version> or '--all'")
internal.ShowSubcommandHelpAndError(c, err)
}
if c.Args().Get(1) != "" && allSecrets {
internal.ShowSubcommandHelpAndError(c, errors.New("cannot use '<secret> <version>' and '--all' together"))
err := errors.New("cannot use '<secret> <version>' and '--all' together")
internal.ShowSubcommandHelpAndError(c, err)
}
secretsToCreate := make(map[string]string)
@ -44,12 +52,16 @@ var appSecretGenerateCommand = &cli.Command{
} else {
secretName := c.Args().Get(1)
secretVersion := c.Args().Get(2)
matches := false
for sec := range secretEnvVars {
parsed := secret.ParseSecretEnvVarName(sec)
if secretName == parsed {
secretsToCreate[sec] = secretVersion
}
}
if !matches {
logrus.Fatalf("'%s' doesn't exist in the env config?", secretName)
}
}
secretVals, err := secret.GenerateSecrets(secretsToCreate, app.StackName(), app.Server)
@ -65,13 +77,18 @@ var appSecretGenerateCommand = &cli.Command{
}
}
if len(secretVals) == 0 {
logrus.Warn("no secrets generated")
os.Exit(1)
}
tableCol := []string{"Name", "Value"}
table := abraFormatter.CreateTable(tableCol)
for name, val := range secretVals {
table.Append([]string{name, val})
}
table.Render()
logrus.Warn("Warning, these secrets will not be shown again, please take note of them *now*")
logrus.Warn("these secrets are not shown again, please take note of them *now*")
return nil
},