-
Notifications
You must be signed in to change notification settings - Fork 235
/
detach.go
50 lines (46 loc) · 1.27 KB
/
detach.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 consul
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/command/secrets"
"github.com/superfly/flyctl/internal/flag"
)
func newDetach() *cobra.Command {
const (
short = "Detach Consul cluster from an app"
long = "Detach Consul cluster from an app, and unsetting the " + consulUrlDefaultVariableName + " secret"
usage = "detach"
)
cmd := command.New(usage, short, long, runDetach,
command.RequireSession,
command.RequireAppName,
)
cmd.Args = cobra.NoArgs
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
flag.String{
Name: "variable-name",
Default: consulUrlDefaultVariableName,
Description: "The secret name that will be removed from the app.",
},
)
return cmd
}
func runDetach(ctx context.Context) error {
var (
apiClient = fly.ClientFromContext(ctx)
appName = appconfig.NameFromContext(ctx)
secretName = flag.GetString(ctx, "variable-name")
)
appCompact, err := apiClient.GetAppCompact(ctx, appName)
if err != nil {
return err
}
secretsToUnset := []string{secretName}
err = secrets.UnsetSecretsAndDeploy(ctx, appCompact, secretsToUnset, false, false)
return err
}