-
Notifications
You must be signed in to change notification settings - Fork 20
/
iam_apikey_list.go
55 lines (44 loc) · 1.21 KB
/
iam_apikey_list.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
package cmd
import (
"fmt"
"strings"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
type apiKeyItem struct {
Key string `json:"key"`
Name string `json:"name"`
Type string `json:"type"`
}
type apiKeyListItemOutput []apiKeyItem
func (o *apiKeyListItemOutput) toJSON() { outputJSON(o) }
func (o *apiKeyListItemOutput) toText() { outputText(o) }
func (o *apiKeyListItemOutput) toTable() { outputTable(o) }
// apiKeyListCmd represents the API keys listing command
var apiKeyListCmd = &cobra.Command{
Use: "list",
Short: "List API keys",
Long: fmt.Sprintf(`This command lists existing API keys.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&apiKeyListItemOutput{}), ", ")),
Aliases: gListAlias,
RunE: func(cmd *cobra.Command, args []string) error {
resp, err := cs.RequestWithContext(gContext, &egoscale.ListAPIKeys{})
if err != nil {
return err
}
r := resp.(*egoscale.ListAPIKeysResponse)
o := make(apiKeyListItemOutput, 0, r.Count)
for _, i := range r.APIKeys {
o = append(o, apiKeyItem{
Name: i.Name,
Key: i.Key,
Type: string(i.Type),
})
}
return output(&o, err)
},
}
func init() {
apiKeyCmd.AddCommand(apiKeyListCmd)
}