-
Notifications
You must be signed in to change notification settings - Fork 20
/
config_show.go
77 lines (65 loc) · 2.29 KB
/
config_show.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
package cmd
import (
"fmt"
"strings"
"github.com/spf13/cobra"
)
type configShowOutput struct {
Name string `json:"name"`
APIKey string `json:"api_key"`
APISecret string `json:"api_secret"`
DefaultZone string `json:"default_zone"`
DefaultTemplate string `json:"default_template,omitempty"`
ComputeAPIEndpoint string `json:"compute_api_endpoint,omitempty"`
StorageAPIEndpoint string `json:"storage_api_endpoint,omitempty"`
DNSAPIEndpoint string `json:"dns_api_endpoint,omitempty" outputLabel:"DNS API Endpoint"`
ConfigFile string `json:"config_file" outputLabel:"Configuration File"`
ClientTimeout int `json:"client_timeout" outputLabel:"API Timeout (in minutes)"`
}
func (o *configShowOutput) Type() string { return "Account" }
func (o *configShowOutput) toJSON() { outputJSON(o) }
func (o *configShowOutput) toText() { outputText(o) }
func (o *configShowOutput) toTable() { outputTable(o) }
func init() {
configCmd.AddCommand(&cobra.Command{
Use: "show NAME",
Short: "Show an account details",
Long: fmt.Sprintf(`This command shows an Exoscale account details.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&configShowOutput{}), ", ")),
Aliases: gShowAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if gAllAccount == nil {
return fmt.Errorf("no accounts configured")
}
name := gCurrentAccount.AccountName()
if len(args) > 0 {
name = args[0]
}
return output(showConfig(name))
},
})
}
func showConfig(name string) (outputter, error) {
account := getAccountByName(name)
if account == nil {
return nil, fmt.Errorf("account %q was not found", name)
}
secret := strings.Repeat("×", len(account.Key))
if len(account.SecretCommand) > 0 {
secret = strings.Join(account.SecretCommand, " ")
}
out := configShowOutput{
Name: account.Name,
ConfigFile: gConfigFilePath,
APIKey: account.Key,
APISecret: secret,
DefaultZone: account.DefaultZone,
DefaultTemplate: account.DefaultTemplate,
ComputeAPIEndpoint: account.Endpoint,
StorageAPIEndpoint: account.SosEndpoint,
DNSAPIEndpoint: account.DNSEndpoint,
ClientTimeout: account.ClientTimeout,
}
return &out, nil
}