1 package dtl
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/tracing"
14 "net/http"
15 )
16
17
18 type PolicyClient struct {
19 BaseClient
20 }
21
22
23 func NewPolicyClient(subscriptionID string) PolicyClient {
24 return NewPolicyClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29 func NewPolicyClientWithBaseURI(baseURI string, subscriptionID string) PolicyClient {
30 return PolicyClient{NewWithBaseURI(baseURI, subscriptionID)}
31 }
32
33
34
35
36
37
38
39 func (client PolicyClient) CreateOrUpdateResource(ctx context.Context, resourceGroupName string, labName string, policySetName string, name string, policy Policy) (result Policy, err error) {
40 if tracing.IsEnabled() {
41 ctx = tracing.StartSpan(ctx, fqdn+"/PolicyClient.CreateOrUpdateResource")
42 defer func() {
43 sc := -1
44 if result.Response.Response != nil {
45 sc = result.Response.Response.StatusCode
46 }
47 tracing.EndSpan(ctx, sc, err)
48 }()
49 }
50 req, err := client.CreateOrUpdateResourcePreparer(ctx, resourceGroupName, labName, policySetName, name, policy)
51 if err != nil {
52 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "CreateOrUpdateResource", nil, "Failure preparing request")
53 return
54 }
55
56 resp, err := client.CreateOrUpdateResourceSender(req)
57 if err != nil {
58 result.Response = autorest.Response{Response: resp}
59 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "CreateOrUpdateResource", resp, "Failure sending request")
60 return
61 }
62
63 result, err = client.CreateOrUpdateResourceResponder(resp)
64 if err != nil {
65 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "CreateOrUpdateResource", resp, "Failure responding to request")
66 return
67 }
68
69 return
70 }
71
72
73 func (client PolicyClient) CreateOrUpdateResourcePreparer(ctx context.Context, resourceGroupName string, labName string, policySetName string, name string, policy Policy) (*http.Request, error) {
74 pathParameters := map[string]interface{}{
75 "labName": autorest.Encode("path", labName),
76 "name": autorest.Encode("path", name),
77 "policySetName": autorest.Encode("path", policySetName),
78 "resourceGroupName": autorest.Encode("path", resourceGroupName),
79 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
80 }
81
82 const APIVersion = "2015-05-21-preview"
83 queryParameters := map[string]interface{}{
84 "api-version": APIVersion,
85 }
86
87 preparer := autorest.CreatePreparer(
88 autorest.AsContentType("application/json; charset=utf-8"),
89 autorest.AsPut(),
90 autorest.WithBaseURL(client.BaseURI),
91 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}", pathParameters),
92 autorest.WithJSON(policy),
93 autorest.WithQueryParameters(queryParameters))
94 return preparer.Prepare((&http.Request{}).WithContext(ctx))
95 }
96
97
98
99 func (client PolicyClient) CreateOrUpdateResourceSender(req *http.Request) (*http.Response, error) {
100 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
101 }
102
103
104
105 func (client PolicyClient) CreateOrUpdateResourceResponder(resp *http.Response) (result Policy, err error) {
106 err = autorest.Respond(
107 resp,
108 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
109 autorest.ByUnmarshallingJSON(&result),
110 autorest.ByClosing())
111 result.Response = autorest.Response{Response: resp}
112 return
113 }
114
115
116
117
118
119
120
121 func (client PolicyClient) DeleteResource(ctx context.Context, resourceGroupName string, labName string, policySetName string, name string) (result autorest.Response, err error) {
122 if tracing.IsEnabled() {
123 ctx = tracing.StartSpan(ctx, fqdn+"/PolicyClient.DeleteResource")
124 defer func() {
125 sc := -1
126 if result.Response != nil {
127 sc = result.Response.StatusCode
128 }
129 tracing.EndSpan(ctx, sc, err)
130 }()
131 }
132 req, err := client.DeleteResourcePreparer(ctx, resourceGroupName, labName, policySetName, name)
133 if err != nil {
134 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "DeleteResource", nil, "Failure preparing request")
135 return
136 }
137
138 resp, err := client.DeleteResourceSender(req)
139 if err != nil {
140 result.Response = resp
141 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "DeleteResource", resp, "Failure sending request")
142 return
143 }
144
145 result, err = client.DeleteResourceResponder(resp)
146 if err != nil {
147 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "DeleteResource", resp, "Failure responding to request")
148 return
149 }
150
151 return
152 }
153
154
155 func (client PolicyClient) DeleteResourcePreparer(ctx context.Context, resourceGroupName string, labName string, policySetName string, name string) (*http.Request, error) {
156 pathParameters := map[string]interface{}{
157 "labName": autorest.Encode("path", labName),
158 "name": autorest.Encode("path", name),
159 "policySetName": autorest.Encode("path", policySetName),
160 "resourceGroupName": autorest.Encode("path", resourceGroupName),
161 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
162 }
163
164 const APIVersion = "2015-05-21-preview"
165 queryParameters := map[string]interface{}{
166 "api-version": APIVersion,
167 }
168
169 preparer := autorest.CreatePreparer(
170 autorest.AsDelete(),
171 autorest.WithBaseURL(client.BaseURI),
172 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}", pathParameters),
173 autorest.WithQueryParameters(queryParameters))
174 return preparer.Prepare((&http.Request{}).WithContext(ctx))
175 }
176
177
178
179 func (client PolicyClient) DeleteResourceSender(req *http.Request) (*http.Response, error) {
180 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
181 }
182
183
184
185 func (client PolicyClient) DeleteResourceResponder(resp *http.Response) (result autorest.Response, err error) {
186 err = autorest.Respond(
187 resp,
188 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
189 autorest.ByClosing())
190 result.Response = resp
191 return
192 }
193
194
195
196
197
198
199
200 func (client PolicyClient) GetResource(ctx context.Context, resourceGroupName string, labName string, policySetName string, name string) (result Policy, err error) {
201 if tracing.IsEnabled() {
202 ctx = tracing.StartSpan(ctx, fqdn+"/PolicyClient.GetResource")
203 defer func() {
204 sc := -1
205 if result.Response.Response != nil {
206 sc = result.Response.Response.StatusCode
207 }
208 tracing.EndSpan(ctx, sc, err)
209 }()
210 }
211 req, err := client.GetResourcePreparer(ctx, resourceGroupName, labName, policySetName, name)
212 if err != nil {
213 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "GetResource", nil, "Failure preparing request")
214 return
215 }
216
217 resp, err := client.GetResourceSender(req)
218 if err != nil {
219 result.Response = autorest.Response{Response: resp}
220 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "GetResource", resp, "Failure sending request")
221 return
222 }
223
224 result, err = client.GetResourceResponder(resp)
225 if err != nil {
226 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "GetResource", resp, "Failure responding to request")
227 return
228 }
229
230 return
231 }
232
233
234 func (client PolicyClient) GetResourcePreparer(ctx context.Context, resourceGroupName string, labName string, policySetName string, name string) (*http.Request, error) {
235 pathParameters := map[string]interface{}{
236 "labName": autorest.Encode("path", labName),
237 "name": autorest.Encode("path", name),
238 "policySetName": autorest.Encode("path", policySetName),
239 "resourceGroupName": autorest.Encode("path", resourceGroupName),
240 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
241 }
242
243 const APIVersion = "2015-05-21-preview"
244 queryParameters := map[string]interface{}{
245 "api-version": APIVersion,
246 }
247
248 preparer := autorest.CreatePreparer(
249 autorest.AsGet(),
250 autorest.WithBaseURL(client.BaseURI),
251 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}", pathParameters),
252 autorest.WithQueryParameters(queryParameters))
253 return preparer.Prepare((&http.Request{}).WithContext(ctx))
254 }
255
256
257
258 func (client PolicyClient) GetResourceSender(req *http.Request) (*http.Response, error) {
259 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
260 }
261
262
263
264 func (client PolicyClient) GetResourceResponder(resp *http.Response) (result Policy, err error) {
265 err = autorest.Respond(
266 resp,
267 azure.WithErrorUnlessStatusCode(http.StatusOK),
268 autorest.ByUnmarshallingJSON(&result),
269 autorest.ByClosing())
270 result.Response = autorest.Response{Response: resp}
271 return
272 }
273
274
275
276
277
278
279
280 func (client PolicyClient) List(ctx context.Context, resourceGroupName string, labName string, policySetName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationPolicyPage, err error) {
281 if tracing.IsEnabled() {
282 ctx = tracing.StartSpan(ctx, fqdn+"/PolicyClient.List")
283 defer func() {
284 sc := -1
285 if result.rwcp.Response.Response != nil {
286 sc = result.rwcp.Response.Response.StatusCode
287 }
288 tracing.EndSpan(ctx, sc, err)
289 }()
290 }
291 result.fn = client.listNextResults
292 req, err := client.ListPreparer(ctx, resourceGroupName, labName, policySetName, filter, top, orderBy)
293 if err != nil {
294 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "List", nil, "Failure preparing request")
295 return
296 }
297
298 resp, err := client.ListSender(req)
299 if err != nil {
300 result.rwcp.Response = autorest.Response{Response: resp}
301 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "List", resp, "Failure sending request")
302 return
303 }
304
305 result.rwcp, err = client.ListResponder(resp)
306 if err != nil {
307 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "List", resp, "Failure responding to request")
308 return
309 }
310 if result.rwcp.hasNextLink() && result.rwcp.IsEmpty() {
311 err = result.NextWithContext(ctx)
312 return
313 }
314
315 return
316 }
317
318
319 func (client PolicyClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, policySetName string, filter string, top *int32, orderBy string) (*http.Request, error) {
320 pathParameters := map[string]interface{}{
321 "labName": autorest.Encode("path", labName),
322 "policySetName": autorest.Encode("path", policySetName),
323 "resourceGroupName": autorest.Encode("path", resourceGroupName),
324 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
325 }
326
327 const APIVersion = "2015-05-21-preview"
328 queryParameters := map[string]interface{}{
329 "api-version": APIVersion,
330 }
331 if len(filter) > 0 {
332 queryParameters["$filter"] = autorest.Encode("query", filter)
333 }
334 if top != nil {
335 queryParameters["$top"] = autorest.Encode("query", *top)
336 }
337 if len(orderBy) > 0 {
338 queryParameters["$orderBy"] = autorest.Encode("query", orderBy)
339 }
340
341 preparer := autorest.CreatePreparer(
342 autorest.AsGet(),
343 autorest.WithBaseURL(client.BaseURI),
344 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies", pathParameters),
345 autorest.WithQueryParameters(queryParameters))
346 return preparer.Prepare((&http.Request{}).WithContext(ctx))
347 }
348
349
350
351 func (client PolicyClient) ListSender(req *http.Request) (*http.Response, error) {
352 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
353 }
354
355
356
357 func (client PolicyClient) ListResponder(resp *http.Response) (result ResponseWithContinuationPolicy, err error) {
358 err = autorest.Respond(
359 resp,
360 azure.WithErrorUnlessStatusCode(http.StatusOK),
361 autorest.ByUnmarshallingJSON(&result),
362 autorest.ByClosing())
363 result.Response = autorest.Response{Response: resp}
364 return
365 }
366
367
368 func (client PolicyClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationPolicy) (result ResponseWithContinuationPolicy, err error) {
369 req, err := lastResults.responseWithContinuationPolicyPreparer(ctx)
370 if err != nil {
371 return result, autorest.NewErrorWithError(err, "dtl.PolicyClient", "listNextResults", nil, "Failure preparing next results request")
372 }
373 if req == nil {
374 return
375 }
376 resp, err := client.ListSender(req)
377 if err != nil {
378 result.Response = autorest.Response{Response: resp}
379 return result, autorest.NewErrorWithError(err, "dtl.PolicyClient", "listNextResults", resp, "Failure sending next results request")
380 }
381 result, err = client.ListResponder(resp)
382 if err != nil {
383 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "listNextResults", resp, "Failure responding to next results request")
384 }
385 return
386 }
387
388
389 func (client PolicyClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, policySetName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationPolicyIterator, err error) {
390 if tracing.IsEnabled() {
391 ctx = tracing.StartSpan(ctx, fqdn+"/PolicyClient.List")
392 defer func() {
393 sc := -1
394 if result.Response().Response.Response != nil {
395 sc = result.page.Response().Response.Response.StatusCode
396 }
397 tracing.EndSpan(ctx, sc, err)
398 }()
399 }
400 result.page, err = client.List(ctx, resourceGroupName, labName, policySetName, filter, top, orderBy)
401 return
402 }
403
404
405
406
407
408
409
410 func (client PolicyClient) PatchResource(ctx context.Context, resourceGroupName string, labName string, policySetName string, name string, policy Policy) (result Policy, err error) {
411 if tracing.IsEnabled() {
412 ctx = tracing.StartSpan(ctx, fqdn+"/PolicyClient.PatchResource")
413 defer func() {
414 sc := -1
415 if result.Response.Response != nil {
416 sc = result.Response.Response.StatusCode
417 }
418 tracing.EndSpan(ctx, sc, err)
419 }()
420 }
421 req, err := client.PatchResourcePreparer(ctx, resourceGroupName, labName, policySetName, name, policy)
422 if err != nil {
423 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "PatchResource", nil, "Failure preparing request")
424 return
425 }
426
427 resp, err := client.PatchResourceSender(req)
428 if err != nil {
429 result.Response = autorest.Response{Response: resp}
430 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "PatchResource", resp, "Failure sending request")
431 return
432 }
433
434 result, err = client.PatchResourceResponder(resp)
435 if err != nil {
436 err = autorest.NewErrorWithError(err, "dtl.PolicyClient", "PatchResource", resp, "Failure responding to request")
437 return
438 }
439
440 return
441 }
442
443
444 func (client PolicyClient) PatchResourcePreparer(ctx context.Context, resourceGroupName string, labName string, policySetName string, name string, policy Policy) (*http.Request, error) {
445 pathParameters := map[string]interface{}{
446 "labName": autorest.Encode("path", labName),
447 "name": autorest.Encode("path", name),
448 "policySetName": autorest.Encode("path", policySetName),
449 "resourceGroupName": autorest.Encode("path", resourceGroupName),
450 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
451 }
452
453 const APIVersion = "2015-05-21-preview"
454 queryParameters := map[string]interface{}{
455 "api-version": APIVersion,
456 }
457
458 preparer := autorest.CreatePreparer(
459 autorest.AsContentType("application/json; charset=utf-8"),
460 autorest.AsPatch(),
461 autorest.WithBaseURL(client.BaseURI),
462 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}", pathParameters),
463 autorest.WithJSON(policy),
464 autorest.WithQueryParameters(queryParameters))
465 return preparer.Prepare((&http.Request{}).WithContext(ctx))
466 }
467
468
469
470 func (client PolicyClient) PatchResourceSender(req *http.Request) (*http.Response, error) {
471 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
472 }
473
474
475
476 func (client PolicyClient) PatchResourceResponder(resp *http.Response) (result Policy, err error) {
477 err = autorest.Respond(
478 resp,
479 azure.WithErrorUnlessStatusCode(http.StatusOK),
480 autorest.ByUnmarshallingJSON(&result),
481 autorest.ByClosing())
482 result.Response = autorest.Response{Response: resp}
483 return
484 }
485
View as plain text