-
Notifications
You must be signed in to change notification settings - Fork 224
/
unset.go
50 lines (39 loc) · 1.25 KB
/
unset.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
package secrets
import (
"context"
"github.com/spf13/cobra"
fly "github.com/superfly/fly-go"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/flyutil"
)
func newUnset() (cmd *cobra.Command) {
const (
long = `Unset one or more encrypted secrets for an application`
short = long
usage = "unset [flags] NAME NAME ..."
)
cmd = command.New(usage, short, long, runUnset, command.RequireSession, command.RequireAppName)
flag.Add(cmd,
sharedFlags,
)
cmd.Args = cobra.MinimumNArgs(1)
return cmd
}
func runUnset(ctx context.Context) (err error) {
client := flyutil.ClientFromContext(ctx)
appName := appconfig.NameFromContext(ctx)
app, err := client.GetAppCompact(ctx, appName)
if err != nil {
return err
}
return UnsetSecretsAndDeploy(ctx, app, flag.Args(ctx), flag.GetBool(ctx, "stage"), flag.GetBool(ctx, "detach"))
}
func UnsetSecretsAndDeploy(ctx context.Context, app *fly.AppCompact, secrets []string, stage bool, detach bool) error {
client := flyutil.ClientFromContext(ctx)
if _, err := client.UnsetSecrets(ctx, app.Name, secrets); err != nil {
return err
}
return DeploySecrets(ctx, app, stage, detach)
}