-
Notifications
You must be signed in to change notification settings - Fork 11
/
key_pairs.go
94 lines (84 loc) · 2.4 KB
/
key_pairs.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
93
94
package morpheus
import (
"fmt"
)
var (
// KeyPairsPath is the API endpoint for key pairs
KeyPairsPath = "/api/key-pairs"
)
// KeyPair structures for use in request and response payloads
type KeyPair struct {
ID int64 `json:"id"`
Name string `json:"name"`
AccountId int64 `json:"accountId"`
PublicKey string `json:"publicKey"`
HasPrivateKey bool `json:"hasPrivateKey"`
PrivateKeyHash string `json:"privateKeyHash"`
Fingerprint string `json:"fingerprint"`
PrivateKey string `json:"privateKey"`
DateCreated string `json:"dateCreated"`
LastUpdated string `json:"lastUpdated"`
}
// ListKeyPairsResult structure parses the list key pairs response payload
type ListKeyPairsResult struct {
KeyPairs *[]KeyPair `json:"keyPairs"`
Meta *MetaResult `json:"meta"`
}
// GetKeyPairResult structure parses the get key pair response payload
type GetKeyPairResult struct {
KeyPair *KeyPair `json:"keyPair"`
}
type CreateKeyPairResult struct {
Success bool `json:"success"`
Message string `json:"msg"`
Errors map[string]string `json:"errors"`
KeyPair *KeyPair `json:"keyPair"`
}
type UpdateKeyPairResult struct {
CreateKeyPairResult
}
type DeleteKeyPairResult struct {
DeleteResult
}
func (client *Client) ListKeyPairs() (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: KeyPairsPath,
Result: &ListKeyPairsResult{},
})
}
func (client *Client) GetKeyPair(id int64) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: fmt.Sprintf("%s/%d", KeyPairsPath, id),
Result: &GetKeyPairResult{},
})
}
func (client *Client) CreateKeyPair(req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "POST",
Path: KeyPairsPath,
QueryParams: req.QueryParams,
Body: req.Body,
Result: &CreateKeyPairResult{},
})
}
func (client *Client) DeleteKeyPair(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "DELETE",
Path: fmt.Sprintf("%s/%d", KeyPairsPath, id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &DeleteKeyPairResult{},
})
}
func (client *Client) GetKeyPairByName(name string) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
QueryParams: map[string]string{
"name": name,
},
Path: KeyPairsPath,
Result: &ListKeyPairsResult{},
})
}