client.go raw
1 /*
2 * Copyright 2022 Baidu, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11 * either express or implied. See the License for the specific language governing permissions
12 * and limitations under the License.
13 */
14 package dns
15
16 import (
17 "github.com/baidubce/bce-sdk-go/auth"
18 "github.com/baidubce/bce-sdk-go/bce"
19 )
20
21 const (
22 DEFAULT_SERVICE_DOMAIN = "http://dns.baidubce.com"
23 DEFAULT_MAX_PARALLEL = 10
24 MULTIPART_ALIGN = 1 << 20 // 1MB
25 MIN_MULTIPART_SIZE = 1 << 20 // 1MB
26 DEFAULT_MULTIPART_SIZE = 12 * (1 << 20) // 12MB
27 MAX_PART_NUMBER = 10000
28 )
29
30 // Client of bcd service is a kind of BceClient, so derived from BceClient
31 type Client struct {
32 *bce.BceClient
33
34 // Fileds that used in parallel operation for BOS service
35 MaxParallel int64
36 MultipartSize int64
37 }
38
39 // NewClient make the bcd service client with default configuration.
40 // Use `cli.Config.xxx` to access the config or change it to non-default value.
41 func NewClient(ak, sk, endpoint string) (*Client, error) {
42 var credentials *auth.BceCredentials
43 var err error
44 if len(ak) == 0 && len(sk) == 0 { // to support public-read-write request
45 credentials, err = nil, nil
46 } else {
47 credentials, err = auth.NewBceCredentials(ak, sk)
48 if err != nil {
49 return nil, err
50 }
51 }
52 if len(endpoint) == 0 {
53 endpoint = DEFAULT_SERVICE_DOMAIN
54 }
55 defaultSignOptions := &auth.SignOptions{
56 HeadersToSign: auth.DEFAULT_HEADERS_TO_SIGN,
57 ExpireSeconds: auth.DEFAULT_EXPIRE_SECONDS}
58 defaultConf := &bce.BceClientConfiguration{
59 Endpoint: endpoint,
60 Region: bce.DEFAULT_REGION,
61 UserAgent: bce.DEFAULT_USER_AGENT,
62 Credentials: credentials,
63 SignOption: defaultSignOptions,
64 Retry: bce.DEFAULT_RETRY_POLICY,
65 ConnectionTimeoutInMillis: bce.DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS}
66 v1Signer := &auth.BceV1Signer{}
67
68 client := &Client{bce.NewBceClient(defaultConf, v1Signer),
69 DEFAULT_MAX_PARALLEL, DEFAULT_MULTIPART_SIZE}
70 return client, nil
71 }
72
73 // AddLineGroup -
74 //
75 // PARAMS:
76 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串。
77 // - body: body参数
78 // RETURNS:
79 // - error: the return error if any occurs
80 func (c *Client) AddLineGroup(body *AddLineGroupRequest, clientToken string) error {
81 return AddLineGroup(c, body, clientToken)
82 }
83
84 // CreatePaidZone -
85 //
86 // PARAMS:
87 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串。
88 // - body: body参数
89 // RETURNS:
90 // - error: the return error if any occurs
91 func (c *Client) CreatePaidZone(body *CreatePaidZoneRequest, clientToken string) error {
92 return CreatePaidZone(c, body, clientToken)
93 }
94
95 // CreateRecord -
96 //
97 // PARAMS:
98 // - zoneName: 域名名称。
99 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串。
100 // - body: body参数
101 // RETURNS:
102 // - error: the return error if any occurs
103 func (c *Client) CreateRecord(zoneName string, body *CreateRecordRequest, clientToken string) error {
104 return CreateRecord(c, zoneName, body, clientToken)
105 }
106
107 // CreateZone -
108 //
109 // PARAMS:
110 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串
111 // - body: body参数
112 // RETURNS:
113 // - error: the return error if any occurs
114 func (c *Client) CreateZone(body *CreateZoneRequest, clientToken string) error {
115 return CreateZone(c, body, clientToken)
116 }
117
118 // DeleteLineGroup -
119 //
120 // PARAMS:
121 // - lineId: 线路组id。
122 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串。
123 // RETURNS:
124 // - error: the return error if any occurs
125 func (c *Client) DeleteLineGroup(lineId string, clientToken string) error {
126 return DeleteLineGroup(c, lineId, clientToken)
127 }
128
129 // DeleteRecord -
130 //
131 // PARAMS:
132 // - zoneName: 域名名称。
133 // - recordId: 解析记录id。
134 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串。
135 // - body: body参数
136 // RETURNS:
137 // - error: the return error if any occurs
138 func (c *Client) DeleteRecord(zoneName string, recordId string, clientToken string) error {
139 return DeleteRecord(c, zoneName, recordId, clientToken)
140 }
141
142 // DeleteZone -
143 //
144 // PARAMS:
145 // - zoneName: 域名的名称。
146 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串。
147 // - body: body参数
148 // RETURNS:
149 // - error: the return error if any occurs
150 func (c *Client) DeleteZone(zoneName string, clientToken string) error {
151 return DeleteZone(c, zoneName, clientToken)
152 }
153
154 // ListLineGroup -
155 //
156 // PARAMS:
157 // - marker: 批量获取列表的查询的起始位置,是一个由系统生成的字符串。
158 // - maxKeys: 每页包含的最大数量,最大数量通常不超过1000,缺省值为1000。
159 // - body: body参数
160 // RETURNS:
161 // - *ListLineGroupResponse:
162 // - error: the return error if any occurs
163 func (c *Client) ListLineGroup(body *ListLineGroupRequest) (*ListLineGroupResponse, error) {
164 return ListLineGroup(c, body.Marker, body.MaxKeys)
165 }
166
167 // ListRecord -
168 //
169 // PARAMS:
170 // - zoneName: 域名的名称。
171 // - rr: 主机记录,例如“www”。
172 // - id: 解析记录id。
173 // - marker: 批量获取列表的查询的起始位置,是一个由系统生成的字符串。
174 // - maxKeys: 每页包含的最大数量,最大数量通常不超过1000。缺省值为1000。
175 // - body: body参数
176 // RETURNS:
177 // - *ListRecordResponse:
178 // - error: the return error if any occurs
179 func (c *Client) ListRecord(zoneName string, request *ListRecordRequest) (*ListRecordResponse, error) {
180 return ListRecord(c, zoneName, request.Rr, request.Id, request.Marker, request.MaxKeys)
181 }
182
183 // ListZone -
184 //
185 // PARAMS:
186 // - name: 域名的名称,支持模糊搜索。
187 // - marker: 批量获取列表的查询的起始位置,是一个由系统生成的字符串
188 // - maxKeys: 每页包含的最大数量,最大数量通常不超过1000。缺省值为1000
189 // - body: body参数
190 // RETURNS:
191 // - *ListZoneResponse:
192 // - error: the return error if any occurs
193 func (c *Client) ListZone(body *ListZoneRequest) (
194 *ListZoneResponse, error) {
195 return ListZone(c, body, body.Name, body.Marker, body.MaxKeys)
196 }
197
198 // RenewZone -
199 //
200 // PARAMS:
201 // - name: 续费的域名。
202 // - body: body参数
203 // RETURNS:
204 // - error: the return error if any occurs
205 func (c *Client) RenewZone(name string, body *RenewZoneRequest, clientToken string) error {
206 return RenewZone(c, name, body, clientToken)
207 }
208
209 // UpdateLineGroup -
210 //
211 // PARAMS:
212 // - lineId: 线路组id。
213 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串。
214 // - body: body参数
215 // RETURNS:
216 // - error: the return error if any occurs
217 func (c *Client) UpdateLineGroup(lineId string, body *UpdateLineGroupRequest,
218 clientToken string) error {
219 return UpdateLineGroup(c, lineId, body, clientToken)
220 }
221
222 // UpdateRecord -
223 //
224 // PARAMS:
225 // - zoneName: 域名名称。
226 // - recordId: 解析记录id。
227 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串。
228 // - body: body参数
229 // RETURNS:
230 // - error: the return error if any occurs
231 func (c *Client) UpdateRecord(zoneName string, recordId string, body *UpdateRecordRequest,
232 clientToken string) error {
233 return UpdateRecord(c, zoneName, recordId, body, clientToken)
234 }
235
236 // UpdateRecordDisable -
237 //
238 // PARAMS:
239 // - zoneName: 域名名称。
240 // - recordId: 解析记录id。
241 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串。
242 // - body: body参数
243 // RETURNS:
244 // - error: the return error if any occurs
245 func (c *Client) UpdateRecordDisable(zoneName string, recordId string, clientToken string) error {
246 return UpdateRecordDisable(c, zoneName, recordId, clientToken)
247 }
248
249 // UpdateRecordEnable -
250 //
251 // PARAMS:
252 // - zoneName: 域名名称。
253 // - recordId: 解析记录id。
254 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串。
255 // - body: body参数
256 // RETURNS:
257 // - error: the return error if any occurs
258 func (c *Client) UpdateRecordEnable(zoneName string, recordId string, clientToken string) error {
259 return UpdateRecordEnable(c, zoneName, recordId, clientToken)
260 }
261
262 // UpgradeZone -
263 //
264 // PARAMS:
265 // - clientToken: 幂等性Token,是一个长度不超过64位的ASCII字符串。
266 // - body: body参数
267 // RETURNS:
268 // - error: the return error if any occurs
269 func (c *Client) UpgradeZone(body *UpgradeZoneRequest, clientToken string) error {
270 return UpgradeZone(c, body, clientToken)
271 }
272