-
Notifications
You must be signed in to change notification settings - Fork 20
/
iam_apikey_show.go
54 lines (44 loc) · 1.21 KB
/
iam_apikey_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
package cmd
import (
"fmt"
"strings"
"github.com/spf13/cobra"
)
type apiKeyShowItemOutput struct {
Name string `json:"name"`
Key string `json:"key"`
Operations []string `json:"operations,omitempty"`
Resources []string `json:"resources,omitempty"`
Type string `json:"type"`
}
func (o *apiKeyShowItemOutput) toJSON() { outputJSON(o) }
func (o *apiKeyShowItemOutput) toText() { outputText(o) }
func (o *apiKeyShowItemOutput) toTable() { outputTable(o) }
var apiKeyShowCmd = &cobra.Command{
Use: "show KEY|NAME",
Short: "Show API key",
Long: fmt.Sprintf(`This command shows an API key details.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&apiKeyShowItemOutput{}), ", ")),
Aliases: gShowAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return cmd.Usage()
}
apiKey, err := getAPIKeyByName(args[0])
if err != nil {
return err
}
o := apiKeyShowItemOutput{
Name: apiKey.Name,
Key: apiKey.Key,
Operations: apiKey.Operations,
Resources: apiKey.Resources,
Type: string(apiKey.Type),
}
return output(&o, err)
},
}
func init() {
apiKeyCmd.AddCommand(apiKeyShowCmd)
}