cisco/sdk/ssh.go -rw-r--r-- 747 bytes View raw
                                                                                
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
package cisco

import (
	"encoding/json"
	"time"
)

type SSHKey struct {
	Key         string    `json:"key"`
	Fingerprint string    `json:"fingerprint"`
	Created     time.Time `json:"created"`
}

type SSHKeyAdd struct {
	Key string `json:"key"`
}

func AddSSHKey(key string) error {
	_, err := SendRequest(SSHKeyAddRoute, Request{
		Data: &SSHKeyAdd{
			Key: key,
		},
	})
	return err
}

func ListSSHKey() ([]SSHKey, error) {
	var result []SSHKey

	data, err := SendRequest(SSHKeyListRoute, Request{})

	if err != nil {
		return nil, err
	}

	err = json.Unmarshal(data.([]byte), &result)
	return result, err
}

func DeleteSSHKey(fingerprint string) error {
	_, err := SendRequest(SSHKeyDeleteRoute, Request{
		Arg: fingerprint,
	})

	return err
}