khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame] | 1 | package api |
| 2 | |
| 3 | // keyringRequest is used for performing Keyring operations |
| 4 | type keyringRequest struct { |
| 5 | Key string |
| 6 | } |
| 7 | |
| 8 | // KeyringResponse is returned when listing the gossip encryption keys |
| 9 | type KeyringResponse struct { |
| 10 | // Whether this response is for a WAN ring |
| 11 | WAN bool |
| 12 | |
| 13 | // The datacenter name this request corresponds to |
| 14 | Datacenter string |
| 15 | |
| 16 | // Segment has the network segment this request corresponds to. |
| 17 | Segment string |
| 18 | |
| 19 | // A map of the encryption keys to the number of nodes they're installed on |
| 20 | Keys map[string]int |
| 21 | |
| 22 | // The total number of nodes in this ring |
| 23 | NumNodes int |
| 24 | } |
| 25 | |
| 26 | // KeyringInstall is used to install a new gossip encryption key into the cluster |
| 27 | func (op *Operator) KeyringInstall(key string, q *WriteOptions) error { |
| 28 | r := op.c.newRequest("POST", "/v1/operator/keyring") |
| 29 | r.setWriteOptions(q) |
| 30 | r.obj = keyringRequest{ |
| 31 | Key: key, |
| 32 | } |
| 33 | _, resp, err := requireOK(op.c.doRequest(r)) |
| 34 | if err != nil { |
| 35 | return err |
| 36 | } |
| 37 | resp.Body.Close() |
| 38 | return nil |
| 39 | } |
| 40 | |
| 41 | // KeyringList is used to list the gossip keys installed in the cluster |
| 42 | func (op *Operator) KeyringList(q *QueryOptions) ([]*KeyringResponse, error) { |
| 43 | r := op.c.newRequest("GET", "/v1/operator/keyring") |
| 44 | r.setQueryOptions(q) |
| 45 | _, resp, err := requireOK(op.c.doRequest(r)) |
| 46 | if err != nil { |
| 47 | return nil, err |
| 48 | } |
| 49 | defer resp.Body.Close() |
| 50 | |
| 51 | var out []*KeyringResponse |
| 52 | if err := decodeBody(resp, &out); err != nil { |
| 53 | return nil, err |
| 54 | } |
| 55 | return out, nil |
| 56 | } |
| 57 | |
| 58 | // KeyringRemove is used to remove a gossip encryption key from the cluster |
| 59 | func (op *Operator) KeyringRemove(key string, q *WriteOptions) error { |
| 60 | r := op.c.newRequest("DELETE", "/v1/operator/keyring") |
| 61 | r.setWriteOptions(q) |
| 62 | r.obj = keyringRequest{ |
| 63 | Key: key, |
| 64 | } |
| 65 | _, resp, err := requireOK(op.c.doRequest(r)) |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | resp.Body.Close() |
| 70 | return nil |
| 71 | } |
| 72 | |
| 73 | // KeyringUse is used to change the active gossip encryption key |
| 74 | func (op *Operator) KeyringUse(key string, q *WriteOptions) error { |
| 75 | r := op.c.newRequest("PUT", "/v1/operator/keyring") |
| 76 | r.setWriteOptions(q) |
| 77 | r.obj = keyringRequest{ |
| 78 | Key: key, |
| 79 | } |
| 80 | _, resp, err := requireOK(op.c.doRequest(r)) |
| 81 | if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | resp.Body.Close() |
| 85 | return nil |
| 86 | } |