-
Notifications
You must be signed in to change notification settings - Fork 23
/
env.go
103 lines (87 loc) · 2.66 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package help
import (
"github.com/spf13/cobra"
. "github.com/alcionai/corso/src/cli/print"
)
// AddCommands attaches all `corso env * *` commands to the parent.
func AddCommands(cmd *cobra.Command) {
cmd.AddCommand(envCmd())
}
// The env command: purely a help display.
// `corso env [--help]`
func envCmd() *cobra.Command {
envCmd := &cobra.Command{
Use: "env",
Short: "env var guide",
Long: `A guide to using environment variables in Corso.`,
RunE: handleEnvCmd,
Args: cobra.NoArgs,
}
envCmd.SetHelpFunc(envGuide)
return envCmd
}
// Handler for flat calls to `corso env`.
// Produces the same output as `corso env --help`.
func handleEnvCmd(cmd *cobra.Command, args []string) error {
return cmd.Help()
}
type envVar struct {
category string
name string
description string
}
// interface compliance check
var _ Printable = &envVar{}
// no modifications needed, just passthrough.
func (ev envVar) MinimumPrintable() any {
return ev
}
func (ev envVar) Headers(bool) []string {
// NOTE: skipID does not make sense in this context
return []string{ev.category, " "}
}
func (ev envVar) Values(bool) []string {
return []string{ev.name, ev.description}
}
// headers
const (
corso = "Corso"
azure = "Azure AD App Credentials"
aws = "AWS Credentials"
)
var (
corsoEVs = []envVar{
{corso, "CORSO_PASSPHRASE", "Passphrase to protect encrypted repository contents. " +
"It is impossible to use the repository or recover any backups without this key."},
}
azureEVs = []envVar{
{azure, "AZURE_CLIENT_ID", "Client ID for your Azure AD application used to access your M365 tenant."},
{azure, "AZURE_TENANT_ID", "ID for the M365 tenant where the Azure AD application is registered."},
{azure, "AZURE_CLIENT_SECRET", "Azure secret for your Azure AD application used to access your M365 tenant."},
}
awsEVs = []envVar{
{aws, "AWS_ACCESS_KEY_ID", "Access key for an IAM user or role for accessing an S3 bucket."},
{aws, "AWS_SECRET_ACCESS_KEY", "Secret key associated with the access key."},
{aws, "AWS_SESSION_TOKEN", "Session token required when using temporary credentials."},
}
)
func toPrintable(evs []envVar) []Printable {
ps := []Printable{}
for _, ev := range evs {
ps = append(ps, ev)
}
return ps
}
// envGuide outputs a help menu for setting env vars in Corso.
func envGuide(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
Info(ctx,
"\n--- Environment Variable Guide ---\n",
"As a best practice, Corso retrieves credentials and sensitive information from environment variables.\n ",
"\n")
Table(ctx, toPrintable(corsoEVs))
Info(ctx, "\n")
Table(ctx, toPrintable(azureEVs))
Info(ctx, "\n")
Table(ctx, toPrintable(awsEVs))
}