...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package remotecmd
18
19 import (
20 "encoding/json"
21 "fmt"
22 "io/ioutil"
23
24 "github.com/sassoftware/relic/cmdline/shared"
25
26 "github.com/spf13/cobra"
27 )
28
29 var ListKeysCmd = &cobra.Command{
30 Use: "list-keys",
31 Short: "List keys available on the remote server",
32 RunE: listKeysCmd,
33 }
34
35 func init() {
36 RemoteCmd.AddCommand(ListKeysCmd)
37 }
38
39 func listKeysCmd(cmd *cobra.Command, args []string) error {
40 var keyList []string
41 response, err := CallRemote("list_keys", "GET", nil, nil)
42 if err != nil {
43 return shared.Fail(err)
44 }
45 resbytes, err := ioutil.ReadAll(response.Body)
46 if err != nil {
47 return shared.Fail(err)
48 }
49 response.Body.Close()
50 err = json.Unmarshal(resbytes, &keyList)
51 if err != nil {
52 return shared.Fail(err)
53 }
54 for _, key := range keyList {
55 fmt.Println(key)
56 }
57 return nil
58 }
59
View as plain text