-
Notifications
You must be signed in to change notification settings - Fork 223
/
set.go
71 lines (58 loc) · 1.58 KB
/
set.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package secrets
import (
"context"
"errors"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/helpers"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/cmdutil"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
)
func newSet() (cmd *cobra.Command) {
const (
long = `Set one or more encrypted secrets for an application`
short = long
usage = "set [flags] NAME=VALUE NAME=VALUE ..."
)
cmd = command.New(usage, short, long, runSet, command.RequireSession, command.RequireAppName)
flag.Add(cmd,
sharedFlags,
)
cmd.Args = cobra.MinimumNArgs(1)
return cmd
}
func runSet(ctx context.Context) (err error) {
client := client.FromContext(ctx).API()
appName := appconfig.NameFromContext(ctx)
app, err := client.GetAppCompact(ctx, appName)
if err != nil {
return err
}
secrets, err := cmdutil.ParseKVStringsToMap(flag.Args(ctx))
if err != nil {
return fmt.Errorf("could not parse secrets: %w", err)
}
for k, v := range secrets {
if v == "-" {
if !helpers.HasPipedStdin() {
return fmt.Errorf("secret `%s` expects standard input but none provided", k)
}
inval, err := helpers.ReadStdin(64 * 1024)
if err != nil {
return fmt.Errorf("error reading stdin for '%s': %s", k, err)
}
secrets[k] = inval
}
}
if len(secrets) < 1 {
return errors.New("requires at least one SECRET=VALUE pair")
}
release, err := client.SetSecrets(ctx, appName, secrets)
if err != nil {
return err
}
return deployForSecrets(ctx, app, release)
}