-
Notifications
You must be signed in to change notification settings - Fork 248
/
Copy pathenv.go
65 lines (56 loc) · 1.77 KB
/
env.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
package config
import (
"context"
"github.com/samber/lo"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/flaps"
"github.com/superfly/flyctl/internal/appconfig"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/render"
"github.com/superfly/flyctl/iostreams"
)
func newEnv() (cmd *cobra.Command) {
const (
short = "Display an app's runtime environment variables"
long = `Display an app's runtime environment variables. It displays a section for
secrets and another for config file defined environment variables.`
)
cmd = command.New("env", short, long, runEnv,
command.RequireSession,
command.RequireAppName,
)
cmd.Args = cobra.NoArgs
flag.Add(cmd, flag.App(), flag.AppConfig())
return
}
func runEnv(ctx context.Context) error {
apiClient := client.FromContext(ctx).API()
appName := appconfig.NameFromContext(ctx)
io := iostreams.FromContext(ctx)
secrets, err := apiClient.GetAppSecrets(ctx, appName)
if err != nil {
return err
}
secretRows := lo.Map(secrets, func(s api.Secret, _ int) []string {
return []string{s.Name, s.Digest, s.CreatedAt.Format("2006-01-02T15:04:05")}
})
if err := render.Table(io.Out, "Secrets", secretRows, "Name", "Digest", "Created At"); err != nil {
return err
}
flapsClient, err := flaps.NewFromAppName(ctx, appName)
if err != nil {
return err
}
ctx = flaps.NewContext(ctx, flapsClient)
cfg, err := appconfig.FromRemoteApp(ctx, appName)
if err != nil {
return err
}
envRows := lo.Map(lo.Entries(cfg.Env), func(e lo.Entry[string, string], _ int) []string {
return []string{e.Key, e.Value}
})
return render.Table(io.Out, "Environment Variables", envRows, "Name", "Value")
}