-
Notifications
You must be signed in to change notification settings - Fork 29
/
tsigkeys.go
82 lines (68 loc) · 2.3 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
80
81
82
package powerdns
import (
"context"
"fmt"
"net/http"
)
// TSIGKeysService handles communication with the tsigs 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(ctx context.Context) ([]TSIGKey, error) {
req, err := t.client.newRequest(ctx, http.MethodGet, 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
}
// Get returns a certain TSIGKeys
func (t *TSIGKeysService) Get(ctx context.Context, id string) (*TSIGKey, error) {
req, err := t.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("servers/%s/tsigkeys/%s", t.client.VHost, id), nil, nil)
if err != nil {
return nil, err
}
tsigkey := TSIGKey{}
_, err = t.client.do(req, &tsigkey)
return &tsigkey, err
}
// Create a new TSIG Key setting empty string for key will generate it
func (t *TSIGKeysService) Create(ctx context.Context, name, algorithm, key string) (*TSIGKey, error) {
reqTsigkey := TSIGKey{
Name: &name,
Algorithm: &algorithm,
Key: &key,
}
req, err := t.client.newRequest(ctx, http.MethodPost, fmt.Sprintf("servers/%s/tsigkeys", t.client.VHost), nil, reqTsigkey)
if err != nil {
return nil, err
}
respTsigkey := TSIGKey{}
_, err = t.client.do(req, &respTsigkey)
return &respTsigkey, err
}
func (t *TSIGKeysService) Change(ctx context.Context, id string, newKey TSIGKey) (*TSIGKey, error) {
req, err := t.client.newRequest(ctx, http.MethodPut, fmt.Sprintf("servers/%s/tsigkeys/%s", t.client.VHost, id), nil, newKey)
if err != nil {
return nil, err
}
responseKey := TSIGKey{}
_, err = t.client.do(req, &responseKey)
return &responseKey, err
}
func (t *TSIGKeysService) Delete(ctx context.Context, id string) error {
req, err := t.client.newRequest(ctx, http.MethodDelete, 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
}