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