forked from joeig/go-powerdns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cryptokeys.go
61 lines (51 loc) · 1.9 KB
/
cryptokeys.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
package powerdns
import (
"fmt"
"strconv"
)
// CryptokeysService handles communication with the cryptokeys related methods of the Client API
type CryptokeysService service
// Cryptokey structure with JSON API metadata
type Cryptokey struct {
Type *string `json:"type,omitempty"`
ID *uint64 `json:"id,omitempty"`
KeyType *string `json:"keytype,omitempty"`
Active *bool `json:"active,omitempty"`
DNSkey *string `json:"dnskey,omitempty"`
DS []string `json:"ds,omitempty"`
Privatekey *string `json:"privatekey,omitempty"`
Algorithm *string `json:"algorithm,omitempty"`
Bits *uint64 `json:"bits,omitempty"`
}
func cryptokeyIDToString(id uint64) string {
return strconv.FormatUint(id, 10)
}
// List retrieves a list of Cryptokeys that belong to a Zone
func (c *CryptokeysService) List(domain string) ([]Cryptokey, error) {
req, err := c.client.newRequest("GET", fmt.Sprintf("servers/%s/zones/%s/cryptokeys", c.client.VHost, trimDomain(domain)), nil, nil)
if err != nil {
return nil, err
}
cryptokeys := make([]Cryptokey, 0)
_, err = c.client.do(req, &cryptokeys)
return cryptokeys, err
}
// Get returns a certain Cryptokey instance of a given Zone
func (c *CryptokeysService) Get(domain string, id uint64) (*Cryptokey, error) {
req, err := c.client.newRequest("GET", fmt.Sprintf("servers/%s/zones/%s/cryptokeys/%s", c.client.VHost, trimDomain(domain), cryptokeyIDToString(id)), nil, nil)
if err != nil {
return nil, err
}
cryptokey := new(Cryptokey)
_, err = c.client.do(req, &cryptokey)
return cryptokey, err
}
// Delete removes a given Cryptokey
func (c *CryptokeysService) Delete(domain string, id uint64) error {
req, err := c.client.newRequest("DELETE", fmt.Sprintf("servers/%s/zones/%s/cryptokeys/%s", c.client.VHost, trimDomain(domain), cryptokeyIDToString(id)), nil, nil)
if err != nil {
return err
}
_, err = c.client.do(req, nil)
return err
}