-
Notifications
You must be signed in to change notification settings - Fork 5
/
sshkeys.go
92 lines (82 loc) · 2.25 KB
/
sshkeys.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package oneandone
import (
"net/http"
)
type SSHKeyRequest struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
PublicKey string `json:"public_key,omitempty"`
}
type SSHKey struct {
Identity
descField
State string `json:"state,omitempty"`
Servers *[]SSHServer `json:"servers,omitempty"`
Md5 string `json:"md5,omitempty"`
PublicKey string `json:"public_key,omitempty"`
CreationDate string `json:"creation_date,omitempty"`
ApiPtr
}
type SSHServer struct {
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
func (api *API) ListSSHKeys(args ...interface{}) ([]SSHKey, error) {
url, err := processQueryParams(createUrl(api, sshkeyPathSegment), args...)
if err != nil {
return nil, err
}
result := []SSHKey{}
err = api.Client.Get(url, &result, http.StatusOK)
if err != nil {
return nil, err
}
for index := range result {
result[index].api = api
}
return result, nil
}
func (api *API) GetSSHKey(id string) (*SSHKey, error) {
result := new(SSHKey)
url := createUrl(api, sshkeyPathSegment, id)
err := api.Client.Get(url, &result, http.StatusOK)
if err != nil {
return nil, err
}
result.api = api
return result, nil
}
func (api *API) CreateSSHKey(request *SSHKeyRequest) (string, *SSHKey, error) {
result := new(SSHKey)
url := createUrl(api, sshkeyPathSegment)
err := api.Client.Post(url, request, &result, http.StatusCreated)
if err != nil {
return "", nil, err
}
result.api = api
return result.Id, result, nil
}
func (api *API) DeleteSSHKey(id string) (*SSHKey, error) {
result := new(SSHKey)
url := createUrl(api, sshkeyPathSegment, id)
err := api.Client.Delete(url, nil, &result, http.StatusOK)
if err != nil {
return nil, err
}
result.api = api
return result, nil
}
func (api *API) RenameSSHKey(id string, new_name string, new_desc string) (*SSHKey, error) {
data := struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
}{Name: new_name, Description: new_desc}
result := new(SSHKey)
url := createUrl(api, sshkeyPathSegment, id)
err := api.Client.Put(url, &data, &result, http.StatusOK)
if err != nil {
return nil, err
}
result.api = api
return result, nil
}