1package apimanagement
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// APIOperationPolicyClient is the apiManagement Client
30type APIOperationPolicyClient struct {
31	BaseClient
32}
33
34// NewAPIOperationPolicyClient creates an instance of the APIOperationPolicyClient client.
35func NewAPIOperationPolicyClient(subscriptionID string) APIOperationPolicyClient {
36	return NewAPIOperationPolicyClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewAPIOperationPolicyClientWithBaseURI creates an instance of the APIOperationPolicyClient client.
40func NewAPIOperationPolicyClientWithBaseURI(baseURI string, subscriptionID string) APIOperationPolicyClient {
41	return APIOperationPolicyClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate creates or updates policy configuration for the API Operation level.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// serviceName - the name of the API Management service.
48// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
49// revision has ;rev=n as a suffix where n is the revision number.
50// operationID - operation identifier within an API. Must be unique in the current API Management service
51// instance.
52// parameters - the policy contents to apply.
53// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
54func (client APIOperationPolicyClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string, parameters PolicyContract, ifMatch string) (result PolicyContract, err error) {
55	if tracing.IsEnabled() {
56		ctx = tracing.StartSpan(ctx, fqdn+"/APIOperationPolicyClient.CreateOrUpdate")
57		defer func() {
58			sc := -1
59			if result.Response.Response != nil {
60				sc = result.Response.Response.StatusCode
61			}
62			tracing.EndSpan(ctx, sc, err)
63		}()
64	}
65	if err := validation.Validate([]validation.Validation{
66		{TargetValue: serviceName,
67			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
68				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
69				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
70		{TargetValue: apiid,
71			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
72				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
73				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
74		{TargetValue: operationID,
75			Constraints: []validation.Constraint{{Target: "operationID", Name: validation.MaxLength, Rule: 80, Chain: nil},
76				{Target: "operationID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
77		{TargetValue: parameters,
78			Constraints: []validation.Constraint{{Target: "parameters.PolicyContractProperties", Name: validation.Null, Rule: false,
79				Chain: []validation.Constraint{{Target: "parameters.PolicyContractProperties.Value", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
80		return result, validation.NewError("apimanagement.APIOperationPolicyClient", "CreateOrUpdate", err.Error())
81	}
82
83	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, operationID, parameters, ifMatch)
84	if err != nil {
85		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "CreateOrUpdate", nil, "Failure preparing request")
86		return
87	}
88
89	resp, err := client.CreateOrUpdateSender(req)
90	if err != nil {
91		result.Response = autorest.Response{Response: resp}
92		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "CreateOrUpdate", resp, "Failure sending request")
93		return
94	}
95
96	result, err = client.CreateOrUpdateResponder(resp)
97	if err != nil {
98		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "CreateOrUpdate", resp, "Failure responding to request")
99	}
100
101	return
102}
103
104// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
105func (client APIOperationPolicyClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string, parameters PolicyContract, ifMatch string) (*http.Request, error) {
106	pathParameters := map[string]interface{}{
107		"apiId":             autorest.Encode("path", apiid),
108		"operationId":       autorest.Encode("path", operationID),
109		"policyId":          autorest.Encode("path", "policy"),
110		"resourceGroupName": autorest.Encode("path", resourceGroupName),
111		"serviceName":       autorest.Encode("path", serviceName),
112		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
113	}
114
115	const APIVersion = "2019-01-01"
116	queryParameters := map[string]interface{}{
117		"api-version": APIVersion,
118	}
119
120	preparer := autorest.CreatePreparer(
121		autorest.AsContentType("application/json; charset=utf-8"),
122		autorest.AsPut(),
123		autorest.WithBaseURL(client.BaseURI),
124		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/policies/{policyId}", pathParameters),
125		autorest.WithJSON(parameters),
126		autorest.WithQueryParameters(queryParameters))
127	if len(ifMatch) > 0 {
128		preparer = autorest.DecoratePreparer(preparer,
129			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
130	}
131	return preparer.Prepare((&http.Request{}).WithContext(ctx))
132}
133
134// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
135// http.Response Body if it receives an error.
136func (client APIOperationPolicyClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
137	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
138	return autorest.SendWithSender(client, req, sd...)
139}
140
141// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
142// closes the http.Response Body.
143func (client APIOperationPolicyClient) CreateOrUpdateResponder(resp *http.Response) (result PolicyContract, err error) {
144	err = autorest.Respond(
145		resp,
146		client.ByInspecting(),
147		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
148		autorest.ByUnmarshallingJSON(&result),
149		autorest.ByClosing())
150	result.Response = autorest.Response{Response: resp}
151	return
152}
153
154// Delete deletes the policy configuration at the Api Operation.
155// Parameters:
156// resourceGroupName - the name of the resource group.
157// serviceName - the name of the API Management service.
158// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
159// revision has ;rev=n as a suffix where n is the revision number.
160// operationID - operation identifier within an API. Must be unique in the current API Management service
161// instance.
162// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
163// request or it should be * for unconditional update.
164func (client APIOperationPolicyClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string, ifMatch string) (result autorest.Response, err error) {
165	if tracing.IsEnabled() {
166		ctx = tracing.StartSpan(ctx, fqdn+"/APIOperationPolicyClient.Delete")
167		defer func() {
168			sc := -1
169			if result.Response != nil {
170				sc = result.Response.StatusCode
171			}
172			tracing.EndSpan(ctx, sc, err)
173		}()
174	}
175	if err := validation.Validate([]validation.Validation{
176		{TargetValue: serviceName,
177			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
178				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
179				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
180		{TargetValue: apiid,
181			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
182				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
183				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
184		{TargetValue: operationID,
185			Constraints: []validation.Constraint{{Target: "operationID", Name: validation.MaxLength, Rule: 80, Chain: nil},
186				{Target: "operationID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
187		return result, validation.NewError("apimanagement.APIOperationPolicyClient", "Delete", err.Error())
188	}
189
190	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, apiid, operationID, ifMatch)
191	if err != nil {
192		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "Delete", nil, "Failure preparing request")
193		return
194	}
195
196	resp, err := client.DeleteSender(req)
197	if err != nil {
198		result.Response = resp
199		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "Delete", resp, "Failure sending request")
200		return
201	}
202
203	result, err = client.DeleteResponder(resp)
204	if err != nil {
205		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "Delete", resp, "Failure responding to request")
206	}
207
208	return
209}
210
211// DeletePreparer prepares the Delete request.
212func (client APIOperationPolicyClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string, ifMatch string) (*http.Request, error) {
213	pathParameters := map[string]interface{}{
214		"apiId":             autorest.Encode("path", apiid),
215		"operationId":       autorest.Encode("path", operationID),
216		"policyId":          autorest.Encode("path", "policy"),
217		"resourceGroupName": autorest.Encode("path", resourceGroupName),
218		"serviceName":       autorest.Encode("path", serviceName),
219		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
220	}
221
222	const APIVersion = "2019-01-01"
223	queryParameters := map[string]interface{}{
224		"api-version": APIVersion,
225	}
226
227	preparer := autorest.CreatePreparer(
228		autorest.AsDelete(),
229		autorest.WithBaseURL(client.BaseURI),
230		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/policies/{policyId}", pathParameters),
231		autorest.WithQueryParameters(queryParameters),
232		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
233	return preparer.Prepare((&http.Request{}).WithContext(ctx))
234}
235
236// DeleteSender sends the Delete request. The method will close the
237// http.Response Body if it receives an error.
238func (client APIOperationPolicyClient) DeleteSender(req *http.Request) (*http.Response, error) {
239	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
240	return autorest.SendWithSender(client, req, sd...)
241}
242
243// DeleteResponder handles the response to the Delete request. The method always
244// closes the http.Response Body.
245func (client APIOperationPolicyClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
246	err = autorest.Respond(
247		resp,
248		client.ByInspecting(),
249		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
250		autorest.ByClosing())
251	result.Response = resp
252	return
253}
254
255// Get get the policy configuration at the API Operation level.
256// Parameters:
257// resourceGroupName - the name of the resource group.
258// serviceName - the name of the API Management service.
259// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
260// revision has ;rev=n as a suffix where n is the revision number.
261// operationID - operation identifier within an API. Must be unique in the current API Management service
262// instance.
263// formatParameter - policy Export Format.
264func (client APIOperationPolicyClient) Get(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string, formatParameter PolicyExportFormat) (result PolicyContract, err error) {
265	if tracing.IsEnabled() {
266		ctx = tracing.StartSpan(ctx, fqdn+"/APIOperationPolicyClient.Get")
267		defer func() {
268			sc := -1
269			if result.Response.Response != nil {
270				sc = result.Response.Response.StatusCode
271			}
272			tracing.EndSpan(ctx, sc, err)
273		}()
274	}
275	if err := validation.Validate([]validation.Validation{
276		{TargetValue: serviceName,
277			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
278				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
279				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
280		{TargetValue: apiid,
281			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
282				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
283				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
284		{TargetValue: operationID,
285			Constraints: []validation.Constraint{{Target: "operationID", Name: validation.MaxLength, Rule: 80, Chain: nil},
286				{Target: "operationID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
287		return result, validation.NewError("apimanagement.APIOperationPolicyClient", "Get", err.Error())
288	}
289
290	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, apiid, operationID, formatParameter)
291	if err != nil {
292		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "Get", nil, "Failure preparing request")
293		return
294	}
295
296	resp, err := client.GetSender(req)
297	if err != nil {
298		result.Response = autorest.Response{Response: resp}
299		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "Get", resp, "Failure sending request")
300		return
301	}
302
303	result, err = client.GetResponder(resp)
304	if err != nil {
305		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "Get", resp, "Failure responding to request")
306	}
307
308	return
309}
310
311// GetPreparer prepares the Get request.
312func (client APIOperationPolicyClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string, formatParameter PolicyExportFormat) (*http.Request, error) {
313	pathParameters := map[string]interface{}{
314		"apiId":             autorest.Encode("path", apiid),
315		"operationId":       autorest.Encode("path", operationID),
316		"policyId":          autorest.Encode("path", "policy"),
317		"resourceGroupName": autorest.Encode("path", resourceGroupName),
318		"serviceName":       autorest.Encode("path", serviceName),
319		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
320	}
321
322	const APIVersion = "2019-01-01"
323	queryParameters := map[string]interface{}{
324		"api-version": APIVersion,
325	}
326	if len(string(formatParameter)) > 0 {
327		queryParameters["format"] = autorest.Encode("query", formatParameter)
328	} else {
329		queryParameters["format"] = autorest.Encode("query", "xml")
330	}
331
332	preparer := autorest.CreatePreparer(
333		autorest.AsGet(),
334		autorest.WithBaseURL(client.BaseURI),
335		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/policies/{policyId}", pathParameters),
336		autorest.WithQueryParameters(queryParameters))
337	return preparer.Prepare((&http.Request{}).WithContext(ctx))
338}
339
340// GetSender sends the Get request. The method will close the
341// http.Response Body if it receives an error.
342func (client APIOperationPolicyClient) GetSender(req *http.Request) (*http.Response, error) {
343	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
344	return autorest.SendWithSender(client, req, sd...)
345}
346
347// GetResponder handles the response to the Get request. The method always
348// closes the http.Response Body.
349func (client APIOperationPolicyClient) GetResponder(resp *http.Response) (result PolicyContract, err error) {
350	err = autorest.Respond(
351		resp,
352		client.ByInspecting(),
353		azure.WithErrorUnlessStatusCode(http.StatusOK),
354		autorest.ByUnmarshallingJSON(&result),
355		autorest.ByClosing())
356	result.Response = autorest.Response{Response: resp}
357	return
358}
359
360// GetEntityTag gets the entity state (Etag) version of the API operation policy specified by its identifier.
361// Parameters:
362// resourceGroupName - the name of the resource group.
363// serviceName - the name of the API Management service.
364// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
365// revision has ;rev=n as a suffix where n is the revision number.
366// operationID - operation identifier within an API. Must be unique in the current API Management service
367// instance.
368func (client APIOperationPolicyClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string) (result autorest.Response, err error) {
369	if tracing.IsEnabled() {
370		ctx = tracing.StartSpan(ctx, fqdn+"/APIOperationPolicyClient.GetEntityTag")
371		defer func() {
372			sc := -1
373			if result.Response != nil {
374				sc = result.Response.StatusCode
375			}
376			tracing.EndSpan(ctx, sc, err)
377		}()
378	}
379	if err := validation.Validate([]validation.Validation{
380		{TargetValue: serviceName,
381			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
382				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
383				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
384		{TargetValue: apiid,
385			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
386				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
387				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
388		{TargetValue: operationID,
389			Constraints: []validation.Constraint{{Target: "operationID", Name: validation.MaxLength, Rule: 80, Chain: nil},
390				{Target: "operationID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
391		return result, validation.NewError("apimanagement.APIOperationPolicyClient", "GetEntityTag", err.Error())
392	}
393
394	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, apiid, operationID)
395	if err != nil {
396		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "GetEntityTag", nil, "Failure preparing request")
397		return
398	}
399
400	resp, err := client.GetEntityTagSender(req)
401	if err != nil {
402		result.Response = resp
403		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "GetEntityTag", resp, "Failure sending request")
404		return
405	}
406
407	result, err = client.GetEntityTagResponder(resp)
408	if err != nil {
409		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "GetEntityTag", resp, "Failure responding to request")
410	}
411
412	return
413}
414
415// GetEntityTagPreparer prepares the GetEntityTag request.
416func (client APIOperationPolicyClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string) (*http.Request, error) {
417	pathParameters := map[string]interface{}{
418		"apiId":             autorest.Encode("path", apiid),
419		"operationId":       autorest.Encode("path", operationID),
420		"policyId":          autorest.Encode("path", "policy"),
421		"resourceGroupName": autorest.Encode("path", resourceGroupName),
422		"serviceName":       autorest.Encode("path", serviceName),
423		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
424	}
425
426	const APIVersion = "2019-01-01"
427	queryParameters := map[string]interface{}{
428		"api-version": APIVersion,
429	}
430
431	preparer := autorest.CreatePreparer(
432		autorest.AsHead(),
433		autorest.WithBaseURL(client.BaseURI),
434		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/policies/{policyId}", pathParameters),
435		autorest.WithQueryParameters(queryParameters))
436	return preparer.Prepare((&http.Request{}).WithContext(ctx))
437}
438
439// GetEntityTagSender sends the GetEntityTag request. The method will close the
440// http.Response Body if it receives an error.
441func (client APIOperationPolicyClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
442	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
443	return autorest.SendWithSender(client, req, sd...)
444}
445
446// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
447// closes the http.Response Body.
448func (client APIOperationPolicyClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
449	err = autorest.Respond(
450		resp,
451		client.ByInspecting(),
452		azure.WithErrorUnlessStatusCode(http.StatusOK),
453		autorest.ByClosing())
454	result.Response = resp
455	return
456}
457
458// ListByOperation get the list of policy configuration at the API Operation level.
459// Parameters:
460// resourceGroupName - the name of the resource group.
461// serviceName - the name of the API Management service.
462// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
463// revision has ;rev=n as a suffix where n is the revision number.
464// operationID - operation identifier within an API. Must be unique in the current API Management service
465// instance.
466func (client APIOperationPolicyClient) ListByOperation(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string) (result PolicyCollection, err error) {
467	if tracing.IsEnabled() {
468		ctx = tracing.StartSpan(ctx, fqdn+"/APIOperationPolicyClient.ListByOperation")
469		defer func() {
470			sc := -1
471			if result.Response.Response != nil {
472				sc = result.Response.Response.StatusCode
473			}
474			tracing.EndSpan(ctx, sc, err)
475		}()
476	}
477	if err := validation.Validate([]validation.Validation{
478		{TargetValue: serviceName,
479			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
480				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
481				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
482		{TargetValue: apiid,
483			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
484				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
485				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
486		{TargetValue: operationID,
487			Constraints: []validation.Constraint{{Target: "operationID", Name: validation.MaxLength, Rule: 80, Chain: nil},
488				{Target: "operationID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
489		return result, validation.NewError("apimanagement.APIOperationPolicyClient", "ListByOperation", err.Error())
490	}
491
492	req, err := client.ListByOperationPreparer(ctx, resourceGroupName, serviceName, apiid, operationID)
493	if err != nil {
494		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "ListByOperation", nil, "Failure preparing request")
495		return
496	}
497
498	resp, err := client.ListByOperationSender(req)
499	if err != nil {
500		result.Response = autorest.Response{Response: resp}
501		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "ListByOperation", resp, "Failure sending request")
502		return
503	}
504
505	result, err = client.ListByOperationResponder(resp)
506	if err != nil {
507		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "ListByOperation", resp, "Failure responding to request")
508	}
509
510	return
511}
512
513// ListByOperationPreparer prepares the ListByOperation request.
514func (client APIOperationPolicyClient) ListByOperationPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string) (*http.Request, error) {
515	pathParameters := map[string]interface{}{
516		"apiId":             autorest.Encode("path", apiid),
517		"operationId":       autorest.Encode("path", operationID),
518		"resourceGroupName": autorest.Encode("path", resourceGroupName),
519		"serviceName":       autorest.Encode("path", serviceName),
520		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
521	}
522
523	const APIVersion = "2019-01-01"
524	queryParameters := map[string]interface{}{
525		"api-version": APIVersion,
526	}
527
528	preparer := autorest.CreatePreparer(
529		autorest.AsGet(),
530		autorest.WithBaseURL(client.BaseURI),
531		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/policies", pathParameters),
532		autorest.WithQueryParameters(queryParameters))
533	return preparer.Prepare((&http.Request{}).WithContext(ctx))
534}
535
536// ListByOperationSender sends the ListByOperation request. The method will close the
537// http.Response Body if it receives an error.
538func (client APIOperationPolicyClient) ListByOperationSender(req *http.Request) (*http.Response, error) {
539	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
540	return autorest.SendWithSender(client, req, sd...)
541}
542
543// ListByOperationResponder handles the response to the ListByOperation request. The method always
544// closes the http.Response Body.
545func (client APIOperationPolicyClient) ListByOperationResponder(resp *http.Response) (result PolicyCollection, err error) {
546	err = autorest.Respond(
547		resp,
548		client.ByInspecting(),
549		azure.WithErrorUnlessStatusCode(http.StatusOK),
550		autorest.ByUnmarshallingJSON(&result),
551		autorest.ByClosing())
552	result.Response = autorest.Response{Response: resp}
553	return
554}
555