forked from joeig/go-powerdns
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tsigkeys.go
79 lines (66 loc) · 2.01 KB
/
tsigkeys.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
package powerdns
import (
"fmt"
)
// TSIGKeysService handles communication with the TSIGKeys related methods of the Client API
type TSIGKeysService service
// TSIGKey structure with JSON API metadata
type TSIGKey struct {
Name *string `json:"name,omitempty"`
ID *string `json:"id,omitempty"`
Algorithm *string `json:"algorithm,omitempty"`
Key *string `json:"key,omitempty"`
Type *string `json:"type,omitempty"`
}
// List retrieves a list of TSIGKeys
func (t *TSIGKeysService) List() ([]TSIGKey, error) {
req, err := t.client.newRequest("GET",
fmt.Sprintf("servers/%s/tsigkeys", t.client.VHost), nil, nil)
if err != nil {
return nil, err
}
TSIGKeys := make([]TSIGKey, 0)
_, err = t.client.do(req, &TSIGKeys)
return TSIGKeys, err
}
// Add creates a certain TSIGKey instance
func (t *TSIGKeysService) Add(TSIGKey *TSIGKey) (*TSIGKey, error) {
req, err := t.client.newRequest("POST",
fmt.Sprintf("servers/%s/tsigkeys", t.client.VHost), nil, TSIGKey)
if err != nil {
return nil, err
}
_, err = t.client.do(req, &TSIGKey)
return TSIGKey, err
}
// Replace replaces a certain TSIGKey instance
func (t *TSIGKeysService) Replace(id string, TSIGKey *TSIGKey) (*TSIGKey, error) {
req, err := t.client.newRequest("PUT",
fmt.Sprintf("servers/%s/tsigkeys/%s", t.client.VHost, id), nil, TSIGKey)
if err != nil {
return nil, err
}
_, err = t.client.do(req, &TSIGKey)
return TSIGKey, err
}
// Get returns a certain TSIGKey instance
func (t *TSIGKeysService) Get(id string) (*TSIGKey, error) {
req, err := t.client.newRequest("GET",
fmt.Sprintf("servers/%s/tsigkeys/%s", t.client.VHost, id), nil, nil)
if err != nil {
return nil, err
}
TSIGKey := new(TSIGKey)
_, err = t.client.do(req, &TSIGKey)
return TSIGKey, err
}
// Delete removes a given TSIGKey
func (t *TSIGKeysService) Delete(id string) error {
req, err := t.client.newRequest("DELETE",
fmt.Sprintf("servers/%s/tsigkeys/%s", t.client.VHost, id), nil, nil)
if err != nil {
return err
}
_, err = t.client.do(req, nil)
return err
}