1 package storagetables
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 type ServiceClient struct {
20 BaseClient
21 }
22
23
24 func NewServiceClient(URL string) ServiceClient {
25 return ServiceClient{New(URL)}
26 }
27
28
29
30
31
32
33
34 func (client ServiceClient) GetProperties(ctx context.Context, timeout *int32, requestID string) (result TableServiceProperties, err error) {
35 if tracing.IsEnabled() {
36 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.GetProperties")
37 defer func() {
38 sc := -1
39 if result.Response.Response != nil {
40 sc = result.Response.Response.StatusCode
41 }
42 tracing.EndSpan(ctx, sc, err)
43 }()
44 }
45 if err := validation.Validate([]validation.Validation{
46 {TargetValue: timeout,
47 Constraints: []validation.Constraint{{Target: "timeout", Name: validation.Null, Rule: false,
48 Chain: []validation.Constraint{{Target: "timeout", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
49 return result, validation.NewError("storagetables.ServiceClient", "GetProperties", err.Error())
50 }
51
52 req, err := client.GetPropertiesPreparer(ctx, timeout, requestID)
53 if err != nil {
54 err = autorest.NewErrorWithError(err, "storagetables.ServiceClient", "GetProperties", nil, "Failure preparing request")
55 return
56 }
57
58 resp, err := client.GetPropertiesSender(req)
59 if err != nil {
60 result.Response = autorest.Response{Response: resp}
61 err = autorest.NewErrorWithError(err, "storagetables.ServiceClient", "GetProperties", resp, "Failure sending request")
62 return
63 }
64
65 result, err = client.GetPropertiesResponder(resp)
66 if err != nil {
67 err = autorest.NewErrorWithError(err, "storagetables.ServiceClient", "GetProperties", resp, "Failure responding to request")
68 return
69 }
70
71 return
72 }
73
74
75 func (client ServiceClient) GetPropertiesPreparer(ctx context.Context, timeout *int32, requestID string) (*http.Request, error) {
76 urlParameters := map[string]interface{}{
77 "url": client.URL,
78 }
79
80 queryParameters := map[string]interface{}{
81 "comp": autorest.Encode("query", "properties"),
82 "restype": autorest.Encode("query", "service"),
83 }
84 if timeout != nil {
85 queryParameters["timeout"] = autorest.Encode("query", *timeout)
86 }
87
88 preparer := autorest.CreatePreparer(
89 autorest.AsGet(),
90 autorest.WithCustomBaseURL("{url}", urlParameters),
91 autorest.WithPath("/"),
92 autorest.WithQueryParameters(queryParameters),
93 autorest.WithHeader("x-ms-version", "2019-02-02"))
94 if len(requestID) > 0 {
95 preparer = autorest.DecoratePreparer(preparer,
96 autorest.WithHeader("x-ms-client-request-id", autorest.String(requestID)))
97 }
98 return preparer.Prepare((&http.Request{}).WithContext(ctx))
99 }
100
101
102
103 func (client ServiceClient) GetPropertiesSender(req *http.Request) (*http.Response, error) {
104 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
105 }
106
107
108
109 func (client ServiceClient) GetPropertiesResponder(resp *http.Response) (result TableServiceProperties, err error) {
110 err = autorest.Respond(
111 resp,
112 azure.WithErrorUnlessStatusCode(http.StatusOK),
113 autorest.ByUnmarshallingJSON(&result),
114 autorest.ByClosing())
115 result.Response = autorest.Response{Response: resp}
116 return
117 }
118
119
120
121
122
123
124
125 func (client ServiceClient) GetStatistics(ctx context.Context, timeout *int32, requestID string) (result TableServiceStats, err error) {
126 if tracing.IsEnabled() {
127 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.GetStatistics")
128 defer func() {
129 sc := -1
130 if result.Response.Response != nil {
131 sc = result.Response.Response.StatusCode
132 }
133 tracing.EndSpan(ctx, sc, err)
134 }()
135 }
136 if err := validation.Validate([]validation.Validation{
137 {TargetValue: timeout,
138 Constraints: []validation.Constraint{{Target: "timeout", Name: validation.Null, Rule: false,
139 Chain: []validation.Constraint{{Target: "timeout", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
140 return result, validation.NewError("storagetables.ServiceClient", "GetStatistics", err.Error())
141 }
142
143 req, err := client.GetStatisticsPreparer(ctx, timeout, requestID)
144 if err != nil {
145 err = autorest.NewErrorWithError(err, "storagetables.ServiceClient", "GetStatistics", nil, "Failure preparing request")
146 return
147 }
148
149 resp, err := client.GetStatisticsSender(req)
150 if err != nil {
151 result.Response = autorest.Response{Response: resp}
152 err = autorest.NewErrorWithError(err, "storagetables.ServiceClient", "GetStatistics", resp, "Failure sending request")
153 return
154 }
155
156 result, err = client.GetStatisticsResponder(resp)
157 if err != nil {
158 err = autorest.NewErrorWithError(err, "storagetables.ServiceClient", "GetStatistics", resp, "Failure responding to request")
159 return
160 }
161
162 return
163 }
164
165
166 func (client ServiceClient) GetStatisticsPreparer(ctx context.Context, timeout *int32, requestID string) (*http.Request, error) {
167 urlParameters := map[string]interface{}{
168 "url": client.URL,
169 }
170
171 queryParameters := map[string]interface{}{
172 "comp": autorest.Encode("query", "stats"),
173 "restype": autorest.Encode("query", "service"),
174 }
175 if timeout != nil {
176 queryParameters["timeout"] = autorest.Encode("query", *timeout)
177 }
178
179 preparer := autorest.CreatePreparer(
180 autorest.AsGet(),
181 autorest.WithCustomBaseURL("{url}", urlParameters),
182 autorest.WithPath("/"),
183 autorest.WithQueryParameters(queryParameters),
184 autorest.WithHeader("x-ms-version", "2019-02-02"))
185 if len(requestID) > 0 {
186 preparer = autorest.DecoratePreparer(preparer,
187 autorest.WithHeader("x-ms-client-request-id", autorest.String(requestID)))
188 }
189 return preparer.Prepare((&http.Request{}).WithContext(ctx))
190 }
191
192
193
194 func (client ServiceClient) GetStatisticsSender(req *http.Request) (*http.Response, error) {
195 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
196 }
197
198
199
200 func (client ServiceClient) GetStatisticsResponder(resp *http.Response) (result TableServiceStats, err error) {
201 err = autorest.Respond(
202 resp,
203 azure.WithErrorUnlessStatusCode(http.StatusOK),
204 autorest.ByUnmarshallingJSON(&result),
205 autorest.ByClosing())
206 result.Response = autorest.Response{Response: resp}
207 return
208 }
209
210
211
212
213
214
215
216
217 func (client ServiceClient) SetProperties(ctx context.Context, tableServiceProperties TableServiceProperties, timeout *int32, requestID string) (result autorest.Response, err error) {
218 if tracing.IsEnabled() {
219 ctx = tracing.StartSpan(ctx, fqdn+"/ServiceClient.SetProperties")
220 defer func() {
221 sc := -1
222 if result.Response != nil {
223 sc = result.Response.StatusCode
224 }
225 tracing.EndSpan(ctx, sc, err)
226 }()
227 }
228 if err := validation.Validate([]validation.Validation{
229 {TargetValue: tableServiceProperties,
230 Constraints: []validation.Constraint{{Target: "tableServiceProperties.Logging", Name: validation.Null, Rule: false,
231 Chain: []validation.Constraint{{Target: "tableServiceProperties.Logging.Version", Name: validation.Null, Rule: true, Chain: nil},
232 {Target: "tableServiceProperties.Logging.Delete", Name: validation.Null, Rule: true, Chain: nil},
233 {Target: "tableServiceProperties.Logging.Read", Name: validation.Null, Rule: true, Chain: nil},
234 {Target: "tableServiceProperties.Logging.Write", Name: validation.Null, Rule: true, Chain: nil},
235 {Target: "tableServiceProperties.Logging.RetentionPolicy", Name: validation.Null, Rule: true,
236 Chain: []validation.Constraint{{Target: "tableServiceProperties.Logging.RetentionPolicy.Enabled", Name: validation.Null, Rule: true, Chain: nil},
237 {Target: "tableServiceProperties.Logging.RetentionPolicy.Days", Name: validation.Null, Rule: false,
238 Chain: []validation.Constraint{{Target: "tableServiceProperties.Logging.RetentionPolicy.Days", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}},
239 }},
240 }},
241 {Target: "tableServiceProperties.HourMetrics", Name: validation.Null, Rule: false,
242 Chain: []validation.Constraint{{Target: "tableServiceProperties.HourMetrics.Enabled", Name: validation.Null, Rule: true, Chain: nil},
243 {Target: "tableServiceProperties.HourMetrics.RetentionPolicy", Name: validation.Null, Rule: false,
244 Chain: []validation.Constraint{{Target: "tableServiceProperties.HourMetrics.RetentionPolicy.Enabled", Name: validation.Null, Rule: true, Chain: nil},
245 {Target: "tableServiceProperties.HourMetrics.RetentionPolicy.Days", Name: validation.Null, Rule: false,
246 Chain: []validation.Constraint{{Target: "tableServiceProperties.HourMetrics.RetentionPolicy.Days", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}},
247 }},
248 }},
249 {Target: "tableServiceProperties.MinuteMetrics", Name: validation.Null, Rule: false,
250 Chain: []validation.Constraint{{Target: "tableServiceProperties.MinuteMetrics.Enabled", Name: validation.Null, Rule: true, Chain: nil},
251 {Target: "tableServiceProperties.MinuteMetrics.RetentionPolicy", Name: validation.Null, Rule: false,
252 Chain: []validation.Constraint{{Target: "tableServiceProperties.MinuteMetrics.RetentionPolicy.Enabled", Name: validation.Null, Rule: true, Chain: nil},
253 {Target: "tableServiceProperties.MinuteMetrics.RetentionPolicy.Days", Name: validation.Null, Rule: false,
254 Chain: []validation.Constraint{{Target: "tableServiceProperties.MinuteMetrics.RetentionPolicy.Days", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}},
255 }},
256 }}}},
257 {TargetValue: timeout,
258 Constraints: []validation.Constraint{{Target: "timeout", Name: validation.Null, Rule: false,
259 Chain: []validation.Constraint{{Target: "timeout", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
260 return result, validation.NewError("storagetables.ServiceClient", "SetProperties", err.Error())
261 }
262
263 req, err := client.SetPropertiesPreparer(ctx, tableServiceProperties, timeout, requestID)
264 if err != nil {
265 err = autorest.NewErrorWithError(err, "storagetables.ServiceClient", "SetProperties", nil, "Failure preparing request")
266 return
267 }
268
269 resp, err := client.SetPropertiesSender(req)
270 if err != nil {
271 result.Response = resp
272 err = autorest.NewErrorWithError(err, "storagetables.ServiceClient", "SetProperties", resp, "Failure sending request")
273 return
274 }
275
276 result, err = client.SetPropertiesResponder(resp)
277 if err != nil {
278 err = autorest.NewErrorWithError(err, "storagetables.ServiceClient", "SetProperties", resp, "Failure responding to request")
279 return
280 }
281
282 return
283 }
284
285
286 func (client ServiceClient) SetPropertiesPreparer(ctx context.Context, tableServiceProperties TableServiceProperties, timeout *int32, requestID string) (*http.Request, error) {
287 urlParameters := map[string]interface{}{
288 "url": client.URL,
289 }
290
291 queryParameters := map[string]interface{}{
292 "comp": autorest.Encode("query", "properties"),
293 "restype": autorest.Encode("query", "service"),
294 }
295 if timeout != nil {
296 queryParameters["timeout"] = autorest.Encode("query", *timeout)
297 }
298
299 preparer := autorest.CreatePreparer(
300 autorest.AsContentType("application/xml; charset=utf-8"),
301 autorest.AsPut(),
302 autorest.WithCustomBaseURL("{url}", urlParameters),
303 autorest.WithPath("/"),
304 autorest.WithJSON(tableServiceProperties),
305 autorest.WithQueryParameters(queryParameters),
306 autorest.WithHeader("x-ms-version", "2019-02-02"))
307 if len(requestID) > 0 {
308 preparer = autorest.DecoratePreparer(preparer,
309 autorest.WithHeader("x-ms-client-request-id", autorest.String(requestID)))
310 }
311 return preparer.Prepare((&http.Request{}).WithContext(ctx))
312 }
313
314
315
316 func (client ServiceClient) SetPropertiesSender(req *http.Request) (*http.Response, error) {
317 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
318 }
319
320
321
322 func (client ServiceClient) SetPropertiesResponder(resp *http.Response) (result autorest.Response, err error) {
323 err = autorest.Respond(
324 resp,
325 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
326 autorest.ByClosing())
327 result.Response = resp
328 return
329 }
330
View as plain text