Skip to content

Commit

Permalink
allow build args that contain equals, reuse helper with secrets (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldwan committed May 6, 2021
1 parent 331368b commit 764377e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
24 changes: 10 additions & 14 deletions cmd/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/superfly/flyctl/cmdctx"
"github.com/superfly/flyctl/internal/client"
"github.com/superfly/flyctl/internal/cmdutil"

"github.com/superfly/flyctl/docstrings"

Expand Down Expand Up @@ -75,27 +76,22 @@ func runSetSecrets(cc *cmdctx.CmdContext) error {
return err
}

secrets := make(map[string]string)
secrets, err := cmdutil.ParseKVStringsToMap(cc.Args)
if err != nil {
return err
}

for _, pair := range cc.Args {
parts := strings.SplitN(pair, "=", 2)
if len(parts) != 2 {
return fmt.Errorf("Secrets must be provided as NAME=VALUE pairs (%s is invalid)", pair)
}
key := parts[0]
value := parts[1]
if value == "-" {
for k, v := range secrets {
if v == "-" {
if !helpers.HasPipedStdin() {
return fmt.Errorf("Secret `%s` expects standard input but none provided", parts[0])
return fmt.Errorf("Secret `%s` expects standard input but none provided", k)
}
inval, err := helpers.ReadStdin(4 * 1024)
if err != nil {
return fmt.Errorf("Error reading stdin for '%s': %s", parts[0], err)
return fmt.Errorf("Error reading stdin for '%s': %s", k, err)
}
value = inval
secrets[k] = inval
}

secrets[key] = value
}

if len(secrets) < 1 {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmdutil/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func ParseKVStringsToMap(args []string) (map[string]string, error) {
out := make(map[string]string, len(args))

for _, arg := range args {
parts := strings.Split(arg, "=")
parts := strings.SplitN(arg, "=", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("'%s': must be in the format NAME=VALUE", arg)
}
Expand Down

0 comments on commit 764377e

Please sign in to comment.