-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathkeys.go
More file actions
52 lines (39 loc) · 1.06 KB
/
keys.go
File metadata and controls
52 lines (39 loc) · 1.06 KB
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
package keys
import (
"encoding/json"
"fmt"
"github.com/deis/deis/client/controller/api"
"github.com/deis/deis/client/controller/client"
)
// List keys on a controller.
func List(c *client.Client, results int) ([]api.Key, int, error) {
body, count, err := c.LimitedRequest("/v1/keys/", results)
if err != nil {
return []api.Key{}, -1, err
}
var keys []api.Key
if err = json.Unmarshal([]byte(body), &keys); err != nil {
return []api.Key{}, -1, err
}
return keys, count, nil
}
// New creates a new key.
func New(c *client.Client, id string, pubKey string) (api.Key, error) {
req := api.KeyCreateRequest{ID: id, Public: pubKey}
body, err := json.Marshal(req)
resBody, err := c.BasicRequest("POST", "/v1/keys/", body)
if err != nil {
return api.Key{}, err
}
key := api.Key{}
if err = json.Unmarshal([]byte(resBody), &key); err != nil {
return api.Key{}, err
}
return key, nil
}
// Delete a key.
func Delete(c *client.Client, keyID string) error {
u := fmt.Sprintf("/v1/keys/%s", keyID)
_, err := c.BasicRequest("DELETE", u, nil)
return err
}