1 package costmanagement
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 ExportsClient struct {
20 BaseClient
21 }
22
23
24 func NewExportsClient(subscriptionID string) ExportsClient {
25 return NewExportsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewExportsClientWithBaseURI(baseURI string, subscriptionID string) ExportsClient {
31 return ExportsClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 func (client ExportsClient) CreateOrUpdate(ctx context.Context, scope string, exportName string, parameters Export) (result Export, err error) {
54 if tracing.IsEnabled() {
55 ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.CreateOrUpdate")
56 defer func() {
57 sc := -1
58 if result.Response.Response != nil {
59 sc = result.Response.Response.StatusCode
60 }
61 tracing.EndSpan(ctx, sc, err)
62 }()
63 }
64 if err := validation.Validate([]validation.Validation{
65 {TargetValue: parameters,
66 Constraints: []validation.Constraint{{Target: "parameters.ExportProperties", Name: validation.Null, Rule: false,
67 Chain: []validation.Constraint{{Target: "parameters.ExportProperties.Schedule", Name: validation.Null, Rule: false,
68 Chain: []validation.Constraint{{Target: "parameters.ExportProperties.Schedule.RecurrencePeriod", Name: validation.Null, Rule: false,
69 Chain: []validation.Constraint{{Target: "parameters.ExportProperties.Schedule.RecurrencePeriod.From", Name: validation.Null, Rule: true, Chain: nil}}},
70 }},
71 }}}}}); err != nil {
72 return result, validation.NewError("costmanagement.ExportsClient", "CreateOrUpdate", err.Error())
73 }
74
75 req, err := client.CreateOrUpdatePreparer(ctx, scope, exportName, parameters)
76 if err != nil {
77 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "CreateOrUpdate", nil, "Failure preparing request")
78 return
79 }
80
81 resp, err := client.CreateOrUpdateSender(req)
82 if err != nil {
83 result.Response = autorest.Response{Response: resp}
84 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "CreateOrUpdate", resp, "Failure sending request")
85 return
86 }
87
88 result, err = client.CreateOrUpdateResponder(resp)
89 if err != nil {
90 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "CreateOrUpdate", resp, "Failure responding to request")
91 return
92 }
93
94 return
95 }
96
97
98 func (client ExportsClient) CreateOrUpdatePreparer(ctx context.Context, scope string, exportName string, parameters Export) (*http.Request, error) {
99 pathParameters := map[string]interface{}{
100 "exportName": autorest.Encode("path", exportName),
101 "scope": scope,
102 }
103
104 const APIVersion = "2020-06-01"
105 queryParameters := map[string]interface{}{
106 "api-version": APIVersion,
107 }
108
109 preparer := autorest.CreatePreparer(
110 autorest.AsContentType("application/json; charset=utf-8"),
111 autorest.AsPut(),
112 autorest.WithBaseURL(client.BaseURI),
113 autorest.WithPathParameters("/{scope}/providers/Microsoft.CostManagement/exports/{exportName}", pathParameters),
114 autorest.WithJSON(parameters),
115 autorest.WithQueryParameters(queryParameters))
116 return preparer.Prepare((&http.Request{}).WithContext(ctx))
117 }
118
119
120
121 func (client ExportsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
122 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
123 }
124
125
126
127 func (client ExportsClient) CreateOrUpdateResponder(resp *http.Response) (result Export, err error) {
128 err = autorest.Respond(
129 resp,
130 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
131 autorest.ByUnmarshallingJSON(&result),
132 autorest.ByClosing())
133 result.Response = autorest.Response{Response: resp}
134 return
135 }
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154 func (client ExportsClient) Delete(ctx context.Context, scope string, exportName string) (result autorest.Response, err error) {
155 if tracing.IsEnabled() {
156 ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.Delete")
157 defer func() {
158 sc := -1
159 if result.Response != nil {
160 sc = result.Response.StatusCode
161 }
162 tracing.EndSpan(ctx, sc, err)
163 }()
164 }
165 req, err := client.DeletePreparer(ctx, scope, exportName)
166 if err != nil {
167 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "Delete", nil, "Failure preparing request")
168 return
169 }
170
171 resp, err := client.DeleteSender(req)
172 if err != nil {
173 result.Response = resp
174 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "Delete", resp, "Failure sending request")
175 return
176 }
177
178 result, err = client.DeleteResponder(resp)
179 if err != nil {
180 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "Delete", resp, "Failure responding to request")
181 return
182 }
183
184 return
185 }
186
187
188 func (client ExportsClient) DeletePreparer(ctx context.Context, scope string, exportName string) (*http.Request, error) {
189 pathParameters := map[string]interface{}{
190 "exportName": autorest.Encode("path", exportName),
191 "scope": scope,
192 }
193
194 const APIVersion = "2020-06-01"
195 queryParameters := map[string]interface{}{
196 "api-version": APIVersion,
197 }
198
199 preparer := autorest.CreatePreparer(
200 autorest.AsDelete(),
201 autorest.WithBaseURL(client.BaseURI),
202 autorest.WithPathParameters("/{scope}/providers/Microsoft.CostManagement/exports/{exportName}", pathParameters),
203 autorest.WithQueryParameters(queryParameters))
204 return preparer.Prepare((&http.Request{}).WithContext(ctx))
205 }
206
207
208
209 func (client ExportsClient) DeleteSender(req *http.Request) (*http.Response, error) {
210 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
211 }
212
213
214
215 func (client ExportsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
216 err = autorest.Respond(
217 resp,
218 azure.WithErrorUnlessStatusCode(http.StatusOK),
219 autorest.ByClosing())
220 result.Response = resp
221 return
222 }
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241 func (client ExportsClient) Execute(ctx context.Context, scope string, exportName string) (result autorest.Response, err error) {
242 if tracing.IsEnabled() {
243 ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.Execute")
244 defer func() {
245 sc := -1
246 if result.Response != nil {
247 sc = result.Response.StatusCode
248 }
249 tracing.EndSpan(ctx, sc, err)
250 }()
251 }
252 req, err := client.ExecutePreparer(ctx, scope, exportName)
253 if err != nil {
254 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "Execute", nil, "Failure preparing request")
255 return
256 }
257
258 resp, err := client.ExecuteSender(req)
259 if err != nil {
260 result.Response = resp
261 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "Execute", resp, "Failure sending request")
262 return
263 }
264
265 result, err = client.ExecuteResponder(resp)
266 if err != nil {
267 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "Execute", resp, "Failure responding to request")
268 return
269 }
270
271 return
272 }
273
274
275 func (client ExportsClient) ExecutePreparer(ctx context.Context, scope string, exportName string) (*http.Request, error) {
276 pathParameters := map[string]interface{}{
277 "exportName": autorest.Encode("path", exportName),
278 "scope": scope,
279 }
280
281 const APIVersion = "2020-06-01"
282 queryParameters := map[string]interface{}{
283 "api-version": APIVersion,
284 }
285
286 preparer := autorest.CreatePreparer(
287 autorest.AsPost(),
288 autorest.WithBaseURL(client.BaseURI),
289 autorest.WithPathParameters("/{scope}/providers/Microsoft.CostManagement/exports/{exportName}/run", pathParameters),
290 autorest.WithQueryParameters(queryParameters))
291 return preparer.Prepare((&http.Request{}).WithContext(ctx))
292 }
293
294
295
296 func (client ExportsClient) ExecuteSender(req *http.Request) (*http.Response, error) {
297 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
298 }
299
300
301
302 func (client ExportsClient) ExecuteResponder(resp *http.Response) (result autorest.Response, err error) {
303 err = autorest.Respond(
304 resp,
305 azure.WithErrorUnlessStatusCode(http.StatusOK),
306 autorest.ByClosing())
307 result.Response = resp
308 return
309 }
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330 func (client ExportsClient) Get(ctx context.Context, scope string, exportName string, expand string) (result Export, err error) {
331 if tracing.IsEnabled() {
332 ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.Get")
333 defer func() {
334 sc := -1
335 if result.Response.Response != nil {
336 sc = result.Response.Response.StatusCode
337 }
338 tracing.EndSpan(ctx, sc, err)
339 }()
340 }
341 req, err := client.GetPreparer(ctx, scope, exportName, expand)
342 if err != nil {
343 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "Get", nil, "Failure preparing request")
344 return
345 }
346
347 resp, err := client.GetSender(req)
348 if err != nil {
349 result.Response = autorest.Response{Response: resp}
350 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "Get", resp, "Failure sending request")
351 return
352 }
353
354 result, err = client.GetResponder(resp)
355 if err != nil {
356 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "Get", resp, "Failure responding to request")
357 return
358 }
359
360 return
361 }
362
363
364 func (client ExportsClient) GetPreparer(ctx context.Context, scope string, exportName string, expand string) (*http.Request, error) {
365 pathParameters := map[string]interface{}{
366 "exportName": autorest.Encode("path", exportName),
367 "scope": scope,
368 }
369
370 const APIVersion = "2020-06-01"
371 queryParameters := map[string]interface{}{
372 "api-version": APIVersion,
373 }
374 if len(expand) > 0 {
375 queryParameters["$expand"] = autorest.Encode("query", expand)
376 }
377
378 preparer := autorest.CreatePreparer(
379 autorest.AsGet(),
380 autorest.WithBaseURL(client.BaseURI),
381 autorest.WithPathParameters("/{scope}/providers/Microsoft.CostManagement/exports/{exportName}", pathParameters),
382 autorest.WithQueryParameters(queryParameters))
383 return preparer.Prepare((&http.Request{}).WithContext(ctx))
384 }
385
386
387
388 func (client ExportsClient) GetSender(req *http.Request) (*http.Response, error) {
389 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
390 }
391
392
393
394 func (client ExportsClient) GetResponder(resp *http.Response) (result Export, err error) {
395 err = autorest.Respond(
396 resp,
397 azure.WithErrorUnlessStatusCode(http.StatusOK),
398 autorest.ByUnmarshallingJSON(&result),
399 autorest.ByClosing())
400 result.Response = autorest.Response{Response: resp}
401 return
402 }
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421 func (client ExportsClient) GetExecutionHistory(ctx context.Context, scope string, exportName string) (result ExportExecutionListResult, err error) {
422 if tracing.IsEnabled() {
423 ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.GetExecutionHistory")
424 defer func() {
425 sc := -1
426 if result.Response.Response != nil {
427 sc = result.Response.Response.StatusCode
428 }
429 tracing.EndSpan(ctx, sc, err)
430 }()
431 }
432 req, err := client.GetExecutionHistoryPreparer(ctx, scope, exportName)
433 if err != nil {
434 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "GetExecutionHistory", nil, "Failure preparing request")
435 return
436 }
437
438 resp, err := client.GetExecutionHistorySender(req)
439 if err != nil {
440 result.Response = autorest.Response{Response: resp}
441 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "GetExecutionHistory", resp, "Failure sending request")
442 return
443 }
444
445 result, err = client.GetExecutionHistoryResponder(resp)
446 if err != nil {
447 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "GetExecutionHistory", resp, "Failure responding to request")
448 return
449 }
450
451 return
452 }
453
454
455 func (client ExportsClient) GetExecutionHistoryPreparer(ctx context.Context, scope string, exportName string) (*http.Request, error) {
456 pathParameters := map[string]interface{}{
457 "exportName": autorest.Encode("path", exportName),
458 "scope": scope,
459 }
460
461 const APIVersion = "2020-06-01"
462 queryParameters := map[string]interface{}{
463 "api-version": APIVersion,
464 }
465
466 preparer := autorest.CreatePreparer(
467 autorest.AsGet(),
468 autorest.WithBaseURL(client.BaseURI),
469 autorest.WithPathParameters("/{scope}/providers/Microsoft.CostManagement/exports/{exportName}/runHistory", pathParameters),
470 autorest.WithQueryParameters(queryParameters))
471 return preparer.Prepare((&http.Request{}).WithContext(ctx))
472 }
473
474
475
476 func (client ExportsClient) GetExecutionHistorySender(req *http.Request) (*http.Response, error) {
477 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
478 }
479
480
481
482 func (client ExportsClient) GetExecutionHistoryResponder(resp *http.Response) (result ExportExecutionListResult, err error) {
483 err = autorest.Respond(
484 resp,
485 azure.WithErrorUnlessStatusCode(http.StatusOK),
486 autorest.ByUnmarshallingJSON(&result),
487 autorest.ByClosing())
488 result.Response = autorest.Response{Response: resp}
489 return
490 }
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510 func (client ExportsClient) List(ctx context.Context, scope string, expand string) (result ExportListResult, err error) {
511 if tracing.IsEnabled() {
512 ctx = tracing.StartSpan(ctx, fqdn+"/ExportsClient.List")
513 defer func() {
514 sc := -1
515 if result.Response.Response != nil {
516 sc = result.Response.Response.StatusCode
517 }
518 tracing.EndSpan(ctx, sc, err)
519 }()
520 }
521 req, err := client.ListPreparer(ctx, scope, expand)
522 if err != nil {
523 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "List", nil, "Failure preparing request")
524 return
525 }
526
527 resp, err := client.ListSender(req)
528 if err != nil {
529 result.Response = autorest.Response{Response: resp}
530 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "List", resp, "Failure sending request")
531 return
532 }
533
534 result, err = client.ListResponder(resp)
535 if err != nil {
536 err = autorest.NewErrorWithError(err, "costmanagement.ExportsClient", "List", resp, "Failure responding to request")
537 return
538 }
539
540 return
541 }
542
543
544 func (client ExportsClient) ListPreparer(ctx context.Context, scope string, expand string) (*http.Request, error) {
545 pathParameters := map[string]interface{}{
546 "scope": scope,
547 }
548
549 const APIVersion = "2020-06-01"
550 queryParameters := map[string]interface{}{
551 "api-version": APIVersion,
552 }
553 if len(expand) > 0 {
554 queryParameters["$expand"] = autorest.Encode("query", expand)
555 }
556
557 preparer := autorest.CreatePreparer(
558 autorest.AsGet(),
559 autorest.WithBaseURL(client.BaseURI),
560 autorest.WithPathParameters("/{scope}/providers/Microsoft.CostManagement/exports", pathParameters),
561 autorest.WithQueryParameters(queryParameters))
562 return preparer.Prepare((&http.Request{}).WithContext(ctx))
563 }
564
565
566
567 func (client ExportsClient) ListSender(req *http.Request) (*http.Response, error) {
568 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
569 }
570
571
572
573 func (client ExportsClient) ListResponder(resp *http.Response) (result ExportListResult, err error) {
574 err = autorest.Respond(
575 resp,
576 azure.WithErrorUnlessStatusCode(http.StatusOK),
577 autorest.ByUnmarshallingJSON(&result),
578 autorest.ByClosing())
579 result.Response = autorest.Response{Response: resp}
580 return
581 }
582
View as plain text