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 using a custom
40// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
41// stack).
42func NewAPIOperationPolicyClientWithBaseURI(baseURI string, subscriptionID string) APIOperationPolicyClient {
43	return APIOperationPolicyClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// CreateOrUpdate creates or updates policy configuration for the API Operation level.
47// Parameters:
48// resourceGroupName - the name of the resource group.
49// serviceName - the name of the API Management service.
50// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
51// revision has ;rev=n as a suffix where n is the revision number.
52// operationID - operation identifier within an API. Must be unique in the current API Management service
53// instance.
54// parameters - the policy contents to apply.
55// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
56func (client APIOperationPolicyClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string, parameters PolicyContract, ifMatch string) (result PolicyContract, err error) {
57	if tracing.IsEnabled() {
58		ctx = tracing.StartSpan(ctx, fqdn+"/APIOperationPolicyClient.CreateOrUpdate")
59		defer func() {
60			sc := -1
61			if result.Response.Response != nil {
62				sc = result.Response.Response.StatusCode
63			}
64			tracing.EndSpan(ctx, sc, err)
65		}()
66	}
67	if err := validation.Validate([]validation.Validation{
68		{TargetValue: serviceName,
69			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
70				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
71				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
72		{TargetValue: apiid,
73			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
74				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
75				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
76		{TargetValue: operationID,
77			Constraints: []validation.Constraint{{Target: "operationID", Name: validation.MaxLength, Rule: 80, Chain: nil},
78				{Target: "operationID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
79		{TargetValue: parameters,
80			Constraints: []validation.Constraint{{Target: "parameters.PolicyContractProperties", Name: validation.Null, Rule: false,
81				Chain: []validation.Constraint{{Target: "parameters.PolicyContractProperties.Value", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
82		return result, validation.NewError("apimanagement.APIOperationPolicyClient", "CreateOrUpdate", err.Error())
83	}
84
85	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, apiid, operationID, parameters, ifMatch)
86	if err != nil {
87		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "CreateOrUpdate", nil, "Failure preparing request")
88		return
89	}
90
91	resp, err := client.CreateOrUpdateSender(req)
92	if err != nil {
93		result.Response = autorest.Response{Response: resp}
94		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "CreateOrUpdate", resp, "Failure sending request")
95		return
96	}
97
98	result, err = client.CreateOrUpdateResponder(resp)
99	if err != nil {
100		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "CreateOrUpdate", resp, "Failure responding to request")
101		return
102	}
103
104	return
105}
106
107// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
108func (client APIOperationPolicyClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string, parameters PolicyContract, ifMatch string) (*http.Request, error) {
109	pathParameters := map[string]interface{}{
110		"apiId":             autorest.Encode("path", apiid),
111		"operationId":       autorest.Encode("path", operationID),
112		"policyId":          autorest.Encode("path", "policy"),
113		"resourceGroupName": autorest.Encode("path", resourceGroupName),
114		"serviceName":       autorest.Encode("path", serviceName),
115		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
116	}
117
118	const APIVersion = "2020-12-01"
119	queryParameters := map[string]interface{}{
120		"api-version": APIVersion,
121	}
122
123	preparer := autorest.CreatePreparer(
124		autorest.AsContentType("application/json; charset=utf-8"),
125		autorest.AsPut(),
126		autorest.WithBaseURL(client.BaseURI),
127		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/policies/{policyId}", pathParameters),
128		autorest.WithJSON(parameters),
129		autorest.WithQueryParameters(queryParameters))
130	if len(ifMatch) > 0 {
131		preparer = autorest.DecoratePreparer(preparer,
132			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
133	}
134	return preparer.Prepare((&http.Request{}).WithContext(ctx))
135}
136
137// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
138// http.Response Body if it receives an error.
139func (client APIOperationPolicyClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
140	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
141}
142
143// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
144// closes the http.Response Body.
145func (client APIOperationPolicyClient) CreateOrUpdateResponder(resp *http.Response) (result PolicyContract, err error) {
146	err = autorest.Respond(
147		resp,
148		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
149		autorest.ByUnmarshallingJSON(&result),
150		autorest.ByClosing())
151	result.Response = autorest.Response{Response: resp}
152	return
153}
154
155// Delete deletes the policy configuration at the Api Operation.
156// Parameters:
157// resourceGroupName - the name of the resource group.
158// serviceName - the name of the API Management service.
159// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
160// revision has ;rev=n as a suffix where n is the revision number.
161// operationID - operation identifier within an API. Must be unique in the current API Management service
162// instance.
163// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
164// request or it should be * for unconditional update.
165func (client APIOperationPolicyClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string, ifMatch string) (result autorest.Response, err error) {
166	if tracing.IsEnabled() {
167		ctx = tracing.StartSpan(ctx, fqdn+"/APIOperationPolicyClient.Delete")
168		defer func() {
169			sc := -1
170			if result.Response != nil {
171				sc = result.Response.StatusCode
172			}
173			tracing.EndSpan(ctx, sc, err)
174		}()
175	}
176	if err := validation.Validate([]validation.Validation{
177		{TargetValue: serviceName,
178			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
179				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
180				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
181		{TargetValue: apiid,
182			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
183				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
184				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
185		{TargetValue: operationID,
186			Constraints: []validation.Constraint{{Target: "operationID", Name: validation.MaxLength, Rule: 80, Chain: nil},
187				{Target: "operationID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
188		return result, validation.NewError("apimanagement.APIOperationPolicyClient", "Delete", err.Error())
189	}
190
191	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, apiid, operationID, ifMatch)
192	if err != nil {
193		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "Delete", nil, "Failure preparing request")
194		return
195	}
196
197	resp, err := client.DeleteSender(req)
198	if err != nil {
199		result.Response = resp
200		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "Delete", resp, "Failure sending request")
201		return
202	}
203
204	result, err = client.DeleteResponder(resp)
205	if err != nil {
206		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "Delete", resp, "Failure responding to request")
207		return
208	}
209
210	return
211}
212
213// DeletePreparer prepares the Delete request.
214func (client APIOperationPolicyClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string, ifMatch string) (*http.Request, error) {
215	pathParameters := map[string]interface{}{
216		"apiId":             autorest.Encode("path", apiid),
217		"operationId":       autorest.Encode("path", operationID),
218		"policyId":          autorest.Encode("path", "policy"),
219		"resourceGroupName": autorest.Encode("path", resourceGroupName),
220		"serviceName":       autorest.Encode("path", serviceName),
221		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
222	}
223
224	const APIVersion = "2020-12-01"
225	queryParameters := map[string]interface{}{
226		"api-version": APIVersion,
227	}
228
229	preparer := autorest.CreatePreparer(
230		autorest.AsDelete(),
231		autorest.WithBaseURL(client.BaseURI),
232		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/policies/{policyId}", pathParameters),
233		autorest.WithQueryParameters(queryParameters),
234		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
235	return preparer.Prepare((&http.Request{}).WithContext(ctx))
236}
237
238// DeleteSender sends the Delete request. The method will close the
239// http.Response Body if it receives an error.
240func (client APIOperationPolicyClient) DeleteSender(req *http.Request) (*http.Response, error) {
241	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
242}
243
244// DeleteResponder handles the response to the Delete request. The method always
245// closes the http.Response Body.
246func (client APIOperationPolicyClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
247	err = autorest.Respond(
248		resp,
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		return
307	}
308
309	return
310}
311
312// GetPreparer prepares the Get request.
313func (client APIOperationPolicyClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string, formatParameter PolicyExportFormat) (*http.Request, error) {
314	pathParameters := map[string]interface{}{
315		"apiId":             autorest.Encode("path", apiid),
316		"operationId":       autorest.Encode("path", operationID),
317		"policyId":          autorest.Encode("path", "policy"),
318		"resourceGroupName": autorest.Encode("path", resourceGroupName),
319		"serviceName":       autorest.Encode("path", serviceName),
320		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
321	}
322
323	const APIVersion = "2020-12-01"
324	queryParameters := map[string]interface{}{
325		"api-version": APIVersion,
326	}
327	if len(string(formatParameter)) > 0 {
328		queryParameters["format"] = autorest.Encode("query", formatParameter)
329	} else {
330		queryParameters["format"] = autorest.Encode("query", "xml")
331	}
332
333	preparer := autorest.CreatePreparer(
334		autorest.AsGet(),
335		autorest.WithBaseURL(client.BaseURI),
336		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/policies/{policyId}", pathParameters),
337		autorest.WithQueryParameters(queryParameters))
338	return preparer.Prepare((&http.Request{}).WithContext(ctx))
339}
340
341// GetSender sends the Get request. The method will close the
342// http.Response Body if it receives an error.
343func (client APIOperationPolicyClient) GetSender(req *http.Request) (*http.Response, error) {
344	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
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		azure.WithErrorUnlessStatusCode(http.StatusOK),
353		autorest.ByUnmarshallingJSON(&result),
354		autorest.ByClosing())
355	result.Response = autorest.Response{Response: resp}
356	return
357}
358
359// GetEntityTag gets the entity state (Etag) version of the API operation policy specified by its identifier.
360// Parameters:
361// resourceGroupName - the name of the resource group.
362// serviceName - the name of the API Management service.
363// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
364// revision has ;rev=n as a suffix where n is the revision number.
365// operationID - operation identifier within an API. Must be unique in the current API Management service
366// instance.
367func (client APIOperationPolicyClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string) (result autorest.Response, err error) {
368	if tracing.IsEnabled() {
369		ctx = tracing.StartSpan(ctx, fqdn+"/APIOperationPolicyClient.GetEntityTag")
370		defer func() {
371			sc := -1
372			if result.Response != nil {
373				sc = result.Response.StatusCode
374			}
375			tracing.EndSpan(ctx, sc, err)
376		}()
377	}
378	if err := validation.Validate([]validation.Validation{
379		{TargetValue: serviceName,
380			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
381				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
382				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
383		{TargetValue: apiid,
384			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
385				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
386				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
387		{TargetValue: operationID,
388			Constraints: []validation.Constraint{{Target: "operationID", Name: validation.MaxLength, Rule: 80, Chain: nil},
389				{Target: "operationID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
390		return result, validation.NewError("apimanagement.APIOperationPolicyClient", "GetEntityTag", err.Error())
391	}
392
393	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, apiid, operationID)
394	if err != nil {
395		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "GetEntityTag", nil, "Failure preparing request")
396		return
397	}
398
399	resp, err := client.GetEntityTagSender(req)
400	if err != nil {
401		result.Response = resp
402		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "GetEntityTag", resp, "Failure sending request")
403		return
404	}
405
406	result, err = client.GetEntityTagResponder(resp)
407	if err != nil {
408		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "GetEntityTag", resp, "Failure responding to request")
409		return
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 = "2020-12-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	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
443}
444
445// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
446// closes the http.Response Body.
447func (client APIOperationPolicyClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
448	err = autorest.Respond(
449		resp,
450		azure.WithErrorUnlessStatusCode(http.StatusOK),
451		autorest.ByClosing())
452	result.Response = resp
453	return
454}
455
456// ListByOperation get the list of policy configuration at the API Operation level.
457// Parameters:
458// resourceGroupName - the name of the resource group.
459// serviceName - the name of the API Management service.
460// apiid - API revision identifier. Must be unique in the current API Management service instance. Non-current
461// revision has ;rev=n as a suffix where n is the revision number.
462// operationID - operation identifier within an API. Must be unique in the current API Management service
463// instance.
464func (client APIOperationPolicyClient) ListByOperation(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string) (result PolicyCollection, err error) {
465	if tracing.IsEnabled() {
466		ctx = tracing.StartSpan(ctx, fqdn+"/APIOperationPolicyClient.ListByOperation")
467		defer func() {
468			sc := -1
469			if result.Response.Response != nil {
470				sc = result.Response.Response.StatusCode
471			}
472			tracing.EndSpan(ctx, sc, err)
473		}()
474	}
475	if err := validation.Validate([]validation.Validation{
476		{TargetValue: serviceName,
477			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
478				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
479				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
480		{TargetValue: apiid,
481			Constraints: []validation.Constraint{{Target: "apiid", Name: validation.MaxLength, Rule: 256, Chain: nil},
482				{Target: "apiid", Name: validation.MinLength, Rule: 1, Chain: nil},
483				{Target: "apiid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
484		{TargetValue: operationID,
485			Constraints: []validation.Constraint{{Target: "operationID", Name: validation.MaxLength, Rule: 80, Chain: nil},
486				{Target: "operationID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
487		return result, validation.NewError("apimanagement.APIOperationPolicyClient", "ListByOperation", err.Error())
488	}
489
490	req, err := client.ListByOperationPreparer(ctx, resourceGroupName, serviceName, apiid, operationID)
491	if err != nil {
492		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "ListByOperation", nil, "Failure preparing request")
493		return
494	}
495
496	resp, err := client.ListByOperationSender(req)
497	if err != nil {
498		result.Response = autorest.Response{Response: resp}
499		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "ListByOperation", resp, "Failure sending request")
500		return
501	}
502
503	result, err = client.ListByOperationResponder(resp)
504	if err != nil {
505		err = autorest.NewErrorWithError(err, "apimanagement.APIOperationPolicyClient", "ListByOperation", resp, "Failure responding to request")
506		return
507	}
508
509	return
510}
511
512// ListByOperationPreparer prepares the ListByOperation request.
513func (client APIOperationPolicyClient) ListByOperationPreparer(ctx context.Context, resourceGroupName string, serviceName string, apiid string, operationID string) (*http.Request, error) {
514	pathParameters := map[string]interface{}{
515		"apiId":             autorest.Encode("path", apiid),
516		"operationId":       autorest.Encode("path", operationID),
517		"resourceGroupName": autorest.Encode("path", resourceGroupName),
518		"serviceName":       autorest.Encode("path", serviceName),
519		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
520	}
521
522	const APIVersion = "2020-12-01"
523	queryParameters := map[string]interface{}{
524		"api-version": APIVersion,
525	}
526
527	preparer := autorest.CreatePreparer(
528		autorest.AsGet(),
529		autorest.WithBaseURL(client.BaseURI),
530		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/operations/{operationId}/policies", pathParameters),
531		autorest.WithQueryParameters(queryParameters))
532	return preparer.Prepare((&http.Request{}).WithContext(ctx))
533}
534
535// ListByOperationSender sends the ListByOperation request. The method will close the
536// http.Response Body if it receives an error.
537func (client APIOperationPolicyClient) ListByOperationSender(req *http.Request) (*http.Response, error) {
538	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
539}
540
541// ListByOperationResponder handles the response to the ListByOperation request. The method always
542// closes the http.Response Body.
543func (client APIOperationPolicyClient) ListByOperationResponder(resp *http.Response) (result PolicyCollection, err error) {
544	err = autorest.Respond(
545		resp,
546		azure.WithErrorUnlessStatusCode(http.StatusOK),
547		autorest.ByUnmarshallingJSON(&result),
548		autorest.ByClosing())
549	result.Response = autorest.Response{Response: resp}
550	return
551}
552