-
Notifications
You must be signed in to change notification settings - Fork 1
/
account_settings.go
127 lines (100 loc) · 2.87 KB
/
account_settings.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2019 nic.at GmbH. All rights reserved.
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package rc0go
import "encoding/json"
type AccSettingsService service
type GlobalSetting struct {
Secondaries []string `json:"secondaries"`
TSIGOut string `json:"tsigout"`
}
// Get global account settings. Value will be empty if an individual setting is not configured.
//
// rcode0 API doc: https://my.rcodezero.at/api-doc/#api-account-settings-settings-get
func (s *AccSettingsService) Get() (*GlobalSetting, error) {
resp, err := s.client.NewRequest().
Get(
s.client.BaseURL.String() +
s.client.APIVersion +
RC0AccSettings,
)
if err != nil {
return nil, err
}
var settings *GlobalSetting
err = json.Unmarshal(resp.Body(), &settings)
if err != nil {
return nil, err
}
return settings, nil
}
// Configures the account setting “secondaries”.
// Those secondaries will receive notifies and may transfer out all zones under the management of the account
//
// rcode0 API doc: https://my.rcodezero.at/api-doc/#api-account-settings-set-secondaries-put
func (s *AccSettingsService) SetSecondaries(secondaries []string) (*StatusResponse, error) {
resp, err := s.client.NewRequest().
SetBody(
map[string]interface{}{
"secondaries": secondaries,
}).
Put(
s.client.BaseURL.String() +
s.client.APIVersion +
RC0AccSecondaries,
)
if err != nil {
return nil, err
}
return s.client.ResponseToRC0StatusResponse(resp)
}
// Removes the configured secondaries
//
// rcode0 API doc: https://my.rcodezero.at/api-doc/#api-account-settings-set-secondaries-delete
func (s *AccSettingsService) RemoveSecondaries() (*StatusResponse, error) {
resp, err := s.client.NewRequest().
Delete(
s.client.BaseURL.String() +
s.client.APIVersion +
RC0AccSecondaries,
)
if err != nil {
return nil, err
}
return s.client.ResponseToRC0StatusResponse(resp)
}
// Configures the TSIG key used for outbound zone transfers
//
// rcode0 API doc: https://my.rcodezero.at/api-doc/#api-account-settings-settings-tsigout-put
func (s *AccSettingsService) SetTSIG(tsigkey string) (*StatusResponse, error) {
resp, err := s.client.NewRequest().
SetBody(
map[string]interface{}{
"tsigkey": tsigkey,
}).
Put(
s.client.BaseURL.String() +
s.client.APIVersion +
RC0AccTsigout,
)
if err != nil {
return nil, err
}
return s.client.ResponseToRC0StatusResponse(resp)
}
// Removes the configured TSIG key
//
// rcode0 API doc: https://my.rcodezero.at/api-doc/#api-account-settings-settings-tsigout-delete
func (s *AccSettingsService) RemoveTSIG() (*StatusResponse, error) {
resp, err := s.client.NewRequest().
Delete(
s.client.BaseURL.String() +
s.client.APIVersion +
RC0AccTsigout,
)
if err != nil {
return nil, err
}
return s.client.ResponseToRC0StatusResponse(resp)
}