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// AuthorizationServerClient is the apiManagement Client
30type AuthorizationServerClient struct {
31	BaseClient
32}
33
34// NewAuthorizationServerClient creates an instance of the AuthorizationServerClient client.
35func NewAuthorizationServerClient(subscriptionID string) AuthorizationServerClient {
36	return NewAuthorizationServerClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewAuthorizationServerClientWithBaseURI creates an instance of the AuthorizationServerClient 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 NewAuthorizationServerClientWithBaseURI(baseURI string, subscriptionID string) AuthorizationServerClient {
43	return AuthorizationServerClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// CreateOrUpdate creates new authorization server or updates an existing authorization server.
47// Parameters:
48// resourceGroupName - the name of the resource group.
49// serviceName - the name of the API Management service.
50// authsid - identifier of the authorization server.
51// parameters - create or update parameters.
52// ifMatch - eTag of the Entity. Not required when creating an entity, but required when updating an entity.
53func (client AuthorizationServerClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, authsid string, parameters AuthorizationServerContract, ifMatch string) (result AuthorizationServerContract, err error) {
54	if tracing.IsEnabled() {
55		ctx = tracing.StartSpan(ctx, fqdn+"/AuthorizationServerClient.CreateOrUpdate")
56		defer func() {
57			sc := -1
58			if result.Response.Response != nil {
59				sc = result.Response.Response.StatusCode
60			}
61			tracing.EndSpan(ctx, sc, err)
62		}()
63	}
64	if err := validation.Validate([]validation.Validation{
65		{TargetValue: serviceName,
66			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
67				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
68				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
69		{TargetValue: authsid,
70			Constraints: []validation.Constraint{{Target: "authsid", Name: validation.MaxLength, Rule: 80, Chain: nil},
71				{Target: "authsid", Name: validation.MinLength, Rule: 1, Chain: nil},
72				{Target: "authsid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
73		{TargetValue: parameters,
74			Constraints: []validation.Constraint{{Target: "parameters.AuthorizationServerContractProperties", Name: validation.Null, Rule: false,
75				Chain: []validation.Constraint{{Target: "parameters.AuthorizationServerContractProperties.DisplayName", Name: validation.Null, Rule: true,
76					Chain: []validation.Constraint{{Target: "parameters.AuthorizationServerContractProperties.DisplayName", Name: validation.MaxLength, Rule: 50, Chain: nil},
77						{Target: "parameters.AuthorizationServerContractProperties.DisplayName", Name: validation.MinLength, Rule: 1, Chain: nil},
78					}},
79					{Target: "parameters.AuthorizationServerContractProperties.ClientRegistrationEndpoint", Name: validation.Null, Rule: true, Chain: nil},
80					{Target: "parameters.AuthorizationServerContractProperties.AuthorizationEndpoint", Name: validation.Null, Rule: true, Chain: nil},
81					{Target: "parameters.AuthorizationServerContractProperties.GrantTypes", Name: validation.Null, Rule: true, Chain: nil},
82					{Target: "parameters.AuthorizationServerContractProperties.ClientID", Name: validation.Null, Rule: true, Chain: nil},
83				}}}}}); err != nil {
84		return result, validation.NewError("apimanagement.AuthorizationServerClient", "CreateOrUpdate", err.Error())
85	}
86
87	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, authsid, parameters, ifMatch)
88	if err != nil {
89		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "CreateOrUpdate", nil, "Failure preparing request")
90		return
91	}
92
93	resp, err := client.CreateOrUpdateSender(req)
94	if err != nil {
95		result.Response = autorest.Response{Response: resp}
96		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "CreateOrUpdate", resp, "Failure sending request")
97		return
98	}
99
100	result, err = client.CreateOrUpdateResponder(resp)
101	if err != nil {
102		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "CreateOrUpdate", resp, "Failure responding to request")
103		return
104	}
105
106	return
107}
108
109// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
110func (client AuthorizationServerClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, authsid string, parameters AuthorizationServerContract, ifMatch string) (*http.Request, error) {
111	pathParameters := map[string]interface{}{
112		"authsid":           autorest.Encode("path", authsid),
113		"resourceGroupName": autorest.Encode("path", resourceGroupName),
114		"serviceName":       autorest.Encode("path", serviceName),
115		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
116	}
117
118	const APIVersion = "2019-12-01-preview"
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}/authorizationServers/{authsid}", 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 AuthorizationServerClient) 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 AuthorizationServerClient) CreateOrUpdateResponder(resp *http.Response) (result AuthorizationServerContract, 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 specific authorization server instance.
156// Parameters:
157// resourceGroupName - the name of the resource group.
158// serviceName - the name of the API Management service.
159// authsid - identifier of the authorization server.
160// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
161// request or it should be * for unconditional update.
162func (client AuthorizationServerClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, authsid string, ifMatch string) (result autorest.Response, err error) {
163	if tracing.IsEnabled() {
164		ctx = tracing.StartSpan(ctx, fqdn+"/AuthorizationServerClient.Delete")
165		defer func() {
166			sc := -1
167			if result.Response != nil {
168				sc = result.Response.StatusCode
169			}
170			tracing.EndSpan(ctx, sc, err)
171		}()
172	}
173	if err := validation.Validate([]validation.Validation{
174		{TargetValue: serviceName,
175			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
176				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
177				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
178		{TargetValue: authsid,
179			Constraints: []validation.Constraint{{Target: "authsid", Name: validation.MaxLength, Rule: 80, Chain: nil},
180				{Target: "authsid", Name: validation.MinLength, Rule: 1, Chain: nil},
181				{Target: "authsid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
182		return result, validation.NewError("apimanagement.AuthorizationServerClient", "Delete", err.Error())
183	}
184
185	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, authsid, ifMatch)
186	if err != nil {
187		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "Delete", nil, "Failure preparing request")
188		return
189	}
190
191	resp, err := client.DeleteSender(req)
192	if err != nil {
193		result.Response = resp
194		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "Delete", resp, "Failure sending request")
195		return
196	}
197
198	result, err = client.DeleteResponder(resp)
199	if err != nil {
200		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "Delete", resp, "Failure responding to request")
201		return
202	}
203
204	return
205}
206
207// DeletePreparer prepares the Delete request.
208func (client AuthorizationServerClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, authsid string, ifMatch string) (*http.Request, error) {
209	pathParameters := map[string]interface{}{
210		"authsid":           autorest.Encode("path", authsid),
211		"resourceGroupName": autorest.Encode("path", resourceGroupName),
212		"serviceName":       autorest.Encode("path", serviceName),
213		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
214	}
215
216	const APIVersion = "2019-12-01-preview"
217	queryParameters := map[string]interface{}{
218		"api-version": APIVersion,
219	}
220
221	preparer := autorest.CreatePreparer(
222		autorest.AsDelete(),
223		autorest.WithBaseURL(client.BaseURI),
224		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/authorizationServers/{authsid}", pathParameters),
225		autorest.WithQueryParameters(queryParameters),
226		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
227	return preparer.Prepare((&http.Request{}).WithContext(ctx))
228}
229
230// DeleteSender sends the Delete request. The method will close the
231// http.Response Body if it receives an error.
232func (client AuthorizationServerClient) DeleteSender(req *http.Request) (*http.Response, error) {
233	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
234}
235
236// DeleteResponder handles the response to the Delete request. The method always
237// closes the http.Response Body.
238func (client AuthorizationServerClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
239	err = autorest.Respond(
240		resp,
241		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
242		autorest.ByClosing())
243	result.Response = resp
244	return
245}
246
247// Get gets the details of the authorization server specified by its identifier.
248// Parameters:
249// resourceGroupName - the name of the resource group.
250// serviceName - the name of the API Management service.
251// authsid - identifier of the authorization server.
252func (client AuthorizationServerClient) Get(ctx context.Context, resourceGroupName string, serviceName string, authsid string) (result AuthorizationServerContract, err error) {
253	if tracing.IsEnabled() {
254		ctx = tracing.StartSpan(ctx, fqdn+"/AuthorizationServerClient.Get")
255		defer func() {
256			sc := -1
257			if result.Response.Response != nil {
258				sc = result.Response.Response.StatusCode
259			}
260			tracing.EndSpan(ctx, sc, err)
261		}()
262	}
263	if err := validation.Validate([]validation.Validation{
264		{TargetValue: serviceName,
265			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
266				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
267				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
268		{TargetValue: authsid,
269			Constraints: []validation.Constraint{{Target: "authsid", Name: validation.MaxLength, Rule: 80, Chain: nil},
270				{Target: "authsid", Name: validation.MinLength, Rule: 1, Chain: nil},
271				{Target: "authsid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
272		return result, validation.NewError("apimanagement.AuthorizationServerClient", "Get", err.Error())
273	}
274
275	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, authsid)
276	if err != nil {
277		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "Get", nil, "Failure preparing request")
278		return
279	}
280
281	resp, err := client.GetSender(req)
282	if err != nil {
283		result.Response = autorest.Response{Response: resp}
284		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "Get", resp, "Failure sending request")
285		return
286	}
287
288	result, err = client.GetResponder(resp)
289	if err != nil {
290		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "Get", resp, "Failure responding to request")
291		return
292	}
293
294	return
295}
296
297// GetPreparer prepares the Get request.
298func (client AuthorizationServerClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, authsid string) (*http.Request, error) {
299	pathParameters := map[string]interface{}{
300		"authsid":           autorest.Encode("path", authsid),
301		"resourceGroupName": autorest.Encode("path", resourceGroupName),
302		"serviceName":       autorest.Encode("path", serviceName),
303		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
304	}
305
306	const APIVersion = "2019-12-01-preview"
307	queryParameters := map[string]interface{}{
308		"api-version": APIVersion,
309	}
310
311	preparer := autorest.CreatePreparer(
312		autorest.AsGet(),
313		autorest.WithBaseURL(client.BaseURI),
314		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/authorizationServers/{authsid}", pathParameters),
315		autorest.WithQueryParameters(queryParameters))
316	return preparer.Prepare((&http.Request{}).WithContext(ctx))
317}
318
319// GetSender sends the Get request. The method will close the
320// http.Response Body if it receives an error.
321func (client AuthorizationServerClient) GetSender(req *http.Request) (*http.Response, error) {
322	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
323}
324
325// GetResponder handles the response to the Get request. The method always
326// closes the http.Response Body.
327func (client AuthorizationServerClient) GetResponder(resp *http.Response) (result AuthorizationServerContract, err error) {
328	err = autorest.Respond(
329		resp,
330		azure.WithErrorUnlessStatusCode(http.StatusOK),
331		autorest.ByUnmarshallingJSON(&result),
332		autorest.ByClosing())
333	result.Response = autorest.Response{Response: resp}
334	return
335}
336
337// GetEntityTag gets the entity state (Etag) version of the authorizationServer specified by its identifier.
338// Parameters:
339// resourceGroupName - the name of the resource group.
340// serviceName - the name of the API Management service.
341// authsid - identifier of the authorization server.
342func (client AuthorizationServerClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, authsid string) (result autorest.Response, err error) {
343	if tracing.IsEnabled() {
344		ctx = tracing.StartSpan(ctx, fqdn+"/AuthorizationServerClient.GetEntityTag")
345		defer func() {
346			sc := -1
347			if result.Response != nil {
348				sc = result.Response.StatusCode
349			}
350			tracing.EndSpan(ctx, sc, err)
351		}()
352	}
353	if err := validation.Validate([]validation.Validation{
354		{TargetValue: serviceName,
355			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
356				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
357				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
358		{TargetValue: authsid,
359			Constraints: []validation.Constraint{{Target: "authsid", Name: validation.MaxLength, Rule: 80, Chain: nil},
360				{Target: "authsid", Name: validation.MinLength, Rule: 1, Chain: nil},
361				{Target: "authsid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
362		return result, validation.NewError("apimanagement.AuthorizationServerClient", "GetEntityTag", err.Error())
363	}
364
365	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, authsid)
366	if err != nil {
367		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "GetEntityTag", nil, "Failure preparing request")
368		return
369	}
370
371	resp, err := client.GetEntityTagSender(req)
372	if err != nil {
373		result.Response = resp
374		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "GetEntityTag", resp, "Failure sending request")
375		return
376	}
377
378	result, err = client.GetEntityTagResponder(resp)
379	if err != nil {
380		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "GetEntityTag", resp, "Failure responding to request")
381		return
382	}
383
384	return
385}
386
387// GetEntityTagPreparer prepares the GetEntityTag request.
388func (client AuthorizationServerClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, authsid string) (*http.Request, error) {
389	pathParameters := map[string]interface{}{
390		"authsid":           autorest.Encode("path", authsid),
391		"resourceGroupName": autorest.Encode("path", resourceGroupName),
392		"serviceName":       autorest.Encode("path", serviceName),
393		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
394	}
395
396	const APIVersion = "2019-12-01-preview"
397	queryParameters := map[string]interface{}{
398		"api-version": APIVersion,
399	}
400
401	preparer := autorest.CreatePreparer(
402		autorest.AsHead(),
403		autorest.WithBaseURL(client.BaseURI),
404		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/authorizationServers/{authsid}", pathParameters),
405		autorest.WithQueryParameters(queryParameters))
406	return preparer.Prepare((&http.Request{}).WithContext(ctx))
407}
408
409// GetEntityTagSender sends the GetEntityTag request. The method will close the
410// http.Response Body if it receives an error.
411func (client AuthorizationServerClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
412	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
413}
414
415// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
416// closes the http.Response Body.
417func (client AuthorizationServerClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
418	err = autorest.Respond(
419		resp,
420		azure.WithErrorUnlessStatusCode(http.StatusOK),
421		autorest.ByClosing())
422	result.Response = resp
423	return
424}
425
426// ListByService lists a collection of authorization servers defined within a service instance.
427// Parameters:
428// resourceGroupName - the name of the resource group.
429// serviceName - the name of the API Management service.
430// filter - |   Field     |     Usage     |     Supported operators     |     Supported functions
431// |</br>|-------------|-------------|-------------|-------------|</br>| name | filter | ge, le, eq, ne, gt, lt
432// | substringof, contains, startswith, endswith | </br>| displayName | filter | ge, le, eq, ne, gt, lt |
433// substringof, contains, startswith, endswith | </br>
434// top - number of records to return.
435// skip - number of records to skip.
436func (client AuthorizationServerClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result AuthorizationServerCollectionPage, err error) {
437	if tracing.IsEnabled() {
438		ctx = tracing.StartSpan(ctx, fqdn+"/AuthorizationServerClient.ListByService")
439		defer func() {
440			sc := -1
441			if result.asc.Response.Response != nil {
442				sc = result.asc.Response.Response.StatusCode
443			}
444			tracing.EndSpan(ctx, sc, err)
445		}()
446	}
447	if err := validation.Validate([]validation.Validation{
448		{TargetValue: serviceName,
449			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
450				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
451				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
452		{TargetValue: top,
453			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
454				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}}}}},
455		{TargetValue: skip,
456			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
457				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil {
458		return result, validation.NewError("apimanagement.AuthorizationServerClient", "ListByService", err.Error())
459	}
460
461	result.fn = client.listByServiceNextResults
462	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
463	if err != nil {
464		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "ListByService", nil, "Failure preparing request")
465		return
466	}
467
468	resp, err := client.ListByServiceSender(req)
469	if err != nil {
470		result.asc.Response = autorest.Response{Response: resp}
471		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "ListByService", resp, "Failure sending request")
472		return
473	}
474
475	result.asc, err = client.ListByServiceResponder(resp)
476	if err != nil {
477		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "ListByService", resp, "Failure responding to request")
478		return
479	}
480	if result.asc.hasNextLink() && result.asc.IsEmpty() {
481		err = result.NextWithContext(ctx)
482		return
483	}
484
485	return
486}
487
488// ListByServicePreparer prepares the ListByService request.
489func (client AuthorizationServerClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
490	pathParameters := map[string]interface{}{
491		"resourceGroupName": autorest.Encode("path", resourceGroupName),
492		"serviceName":       autorest.Encode("path", serviceName),
493		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
494	}
495
496	const APIVersion = "2019-12-01-preview"
497	queryParameters := map[string]interface{}{
498		"api-version": APIVersion,
499	}
500	if len(filter) > 0 {
501		queryParameters["$filter"] = autorest.Encode("query", filter)
502	}
503	if top != nil {
504		queryParameters["$top"] = autorest.Encode("query", *top)
505	}
506	if skip != nil {
507		queryParameters["$skip"] = autorest.Encode("query", *skip)
508	}
509
510	preparer := autorest.CreatePreparer(
511		autorest.AsGet(),
512		autorest.WithBaseURL(client.BaseURI),
513		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/authorizationServers", pathParameters),
514		autorest.WithQueryParameters(queryParameters))
515	return preparer.Prepare((&http.Request{}).WithContext(ctx))
516}
517
518// ListByServiceSender sends the ListByService request. The method will close the
519// http.Response Body if it receives an error.
520func (client AuthorizationServerClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
521	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
522}
523
524// ListByServiceResponder handles the response to the ListByService request. The method always
525// closes the http.Response Body.
526func (client AuthorizationServerClient) ListByServiceResponder(resp *http.Response) (result AuthorizationServerCollection, err error) {
527	err = autorest.Respond(
528		resp,
529		azure.WithErrorUnlessStatusCode(http.StatusOK),
530		autorest.ByUnmarshallingJSON(&result),
531		autorest.ByClosing())
532	result.Response = autorest.Response{Response: resp}
533	return
534}
535
536// listByServiceNextResults retrieves the next set of results, if any.
537func (client AuthorizationServerClient) listByServiceNextResults(ctx context.Context, lastResults AuthorizationServerCollection) (result AuthorizationServerCollection, err error) {
538	req, err := lastResults.authorizationServerCollectionPreparer(ctx)
539	if err != nil {
540		return result, autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "listByServiceNextResults", nil, "Failure preparing next results request")
541	}
542	if req == nil {
543		return
544	}
545	resp, err := client.ListByServiceSender(req)
546	if err != nil {
547		result.Response = autorest.Response{Response: resp}
548		return result, autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "listByServiceNextResults", resp, "Failure sending next results request")
549	}
550	result, err = client.ListByServiceResponder(resp)
551	if err != nil {
552		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "listByServiceNextResults", resp, "Failure responding to next results request")
553	}
554	return
555}
556
557// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
558func (client AuthorizationServerClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result AuthorizationServerCollectionIterator, err error) {
559	if tracing.IsEnabled() {
560		ctx = tracing.StartSpan(ctx, fqdn+"/AuthorizationServerClient.ListByService")
561		defer func() {
562			sc := -1
563			if result.Response().Response.Response != nil {
564				sc = result.page.Response().Response.Response.StatusCode
565			}
566			tracing.EndSpan(ctx, sc, err)
567		}()
568	}
569	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip)
570	return
571}
572
573// ListSecrets gets the client secret details of the authorization server.
574// Parameters:
575// resourceGroupName - the name of the resource group.
576// serviceName - the name of the API Management service.
577// authsid - identifier of the authorization server.
578func (client AuthorizationServerClient) ListSecrets(ctx context.Context, resourceGroupName string, serviceName string, authsid string) (result ClientSecretContract, err error) {
579	if tracing.IsEnabled() {
580		ctx = tracing.StartSpan(ctx, fqdn+"/AuthorizationServerClient.ListSecrets")
581		defer func() {
582			sc := -1
583			if result.Response.Response != nil {
584				sc = result.Response.Response.StatusCode
585			}
586			tracing.EndSpan(ctx, sc, err)
587		}()
588	}
589	if err := validation.Validate([]validation.Validation{
590		{TargetValue: serviceName,
591			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
592				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
593				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
594		{TargetValue: authsid,
595			Constraints: []validation.Constraint{{Target: "authsid", Name: validation.MaxLength, Rule: 80, Chain: nil},
596				{Target: "authsid", Name: validation.MinLength, Rule: 1, Chain: nil},
597				{Target: "authsid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
598		return result, validation.NewError("apimanagement.AuthorizationServerClient", "ListSecrets", err.Error())
599	}
600
601	req, err := client.ListSecretsPreparer(ctx, resourceGroupName, serviceName, authsid)
602	if err != nil {
603		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "ListSecrets", nil, "Failure preparing request")
604		return
605	}
606
607	resp, err := client.ListSecretsSender(req)
608	if err != nil {
609		result.Response = autorest.Response{Response: resp}
610		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "ListSecrets", resp, "Failure sending request")
611		return
612	}
613
614	result, err = client.ListSecretsResponder(resp)
615	if err != nil {
616		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "ListSecrets", resp, "Failure responding to request")
617		return
618	}
619
620	return
621}
622
623// ListSecretsPreparer prepares the ListSecrets request.
624func (client AuthorizationServerClient) ListSecretsPreparer(ctx context.Context, resourceGroupName string, serviceName string, authsid string) (*http.Request, error) {
625	pathParameters := map[string]interface{}{
626		"authsid":           autorest.Encode("path", authsid),
627		"resourceGroupName": autorest.Encode("path", resourceGroupName),
628		"serviceName":       autorest.Encode("path", serviceName),
629		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
630	}
631
632	const APIVersion = "2019-12-01-preview"
633	queryParameters := map[string]interface{}{
634		"api-version": APIVersion,
635	}
636
637	preparer := autorest.CreatePreparer(
638		autorest.AsPost(),
639		autorest.WithBaseURL(client.BaseURI),
640		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/authorizationServers/{authsid}/listSecrets", pathParameters),
641		autorest.WithQueryParameters(queryParameters))
642	return preparer.Prepare((&http.Request{}).WithContext(ctx))
643}
644
645// ListSecretsSender sends the ListSecrets request. The method will close the
646// http.Response Body if it receives an error.
647func (client AuthorizationServerClient) ListSecretsSender(req *http.Request) (*http.Response, error) {
648	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
649}
650
651// ListSecretsResponder handles the response to the ListSecrets request. The method always
652// closes the http.Response Body.
653func (client AuthorizationServerClient) ListSecretsResponder(resp *http.Response) (result ClientSecretContract, err error) {
654	err = autorest.Respond(
655		resp,
656		azure.WithErrorUnlessStatusCode(http.StatusOK),
657		autorest.ByUnmarshallingJSON(&result),
658		autorest.ByClosing())
659	result.Response = autorest.Response{Response: resp}
660	return
661}
662
663// Update updates the details of the authorization server specified by its identifier.
664// Parameters:
665// resourceGroupName - the name of the resource group.
666// serviceName - the name of the API Management service.
667// authsid - identifier of the authorization server.
668// parameters - oAuth2 Server settings Update parameters.
669// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET
670// request or it should be * for unconditional update.
671func (client AuthorizationServerClient) Update(ctx context.Context, resourceGroupName string, serviceName string, authsid string, parameters AuthorizationServerUpdateContract, ifMatch string) (result autorest.Response, err error) {
672	if tracing.IsEnabled() {
673		ctx = tracing.StartSpan(ctx, fqdn+"/AuthorizationServerClient.Update")
674		defer func() {
675			sc := -1
676			if result.Response != nil {
677				sc = result.Response.StatusCode
678			}
679			tracing.EndSpan(ctx, sc, err)
680		}()
681	}
682	if err := validation.Validate([]validation.Validation{
683		{TargetValue: serviceName,
684			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
685				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
686				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
687		{TargetValue: authsid,
688			Constraints: []validation.Constraint{{Target: "authsid", Name: validation.MaxLength, Rule: 80, Chain: nil},
689				{Target: "authsid", Name: validation.MinLength, Rule: 1, Chain: nil},
690				{Target: "authsid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
691		return result, validation.NewError("apimanagement.AuthorizationServerClient", "Update", err.Error())
692	}
693
694	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, authsid, parameters, ifMatch)
695	if err != nil {
696		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "Update", nil, "Failure preparing request")
697		return
698	}
699
700	resp, err := client.UpdateSender(req)
701	if err != nil {
702		result.Response = resp
703		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "Update", resp, "Failure sending request")
704		return
705	}
706
707	result, err = client.UpdateResponder(resp)
708	if err != nil {
709		err = autorest.NewErrorWithError(err, "apimanagement.AuthorizationServerClient", "Update", resp, "Failure responding to request")
710		return
711	}
712
713	return
714}
715
716// UpdatePreparer prepares the Update request.
717func (client AuthorizationServerClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, authsid string, parameters AuthorizationServerUpdateContract, ifMatch string) (*http.Request, error) {
718	pathParameters := map[string]interface{}{
719		"authsid":           autorest.Encode("path", authsid),
720		"resourceGroupName": autorest.Encode("path", resourceGroupName),
721		"serviceName":       autorest.Encode("path", serviceName),
722		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
723	}
724
725	const APIVersion = "2019-12-01-preview"
726	queryParameters := map[string]interface{}{
727		"api-version": APIVersion,
728	}
729
730	preparer := autorest.CreatePreparer(
731		autorest.AsContentType("application/json; charset=utf-8"),
732		autorest.AsPatch(),
733		autorest.WithBaseURL(client.BaseURI),
734		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/authorizationServers/{authsid}", pathParameters),
735		autorest.WithJSON(parameters),
736		autorest.WithQueryParameters(queryParameters),
737		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
738	return preparer.Prepare((&http.Request{}).WithContext(ctx))
739}
740
741// UpdateSender sends the Update request. The method will close the
742// http.Response Body if it receives an error.
743func (client AuthorizationServerClient) UpdateSender(req *http.Request) (*http.Response, error) {
744	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
745}
746
747// UpdateResponder handles the response to the Update request. The method always
748// closes the http.Response Body.
749func (client AuthorizationServerClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
750	err = autorest.Respond(
751		resp,
752		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
753		autorest.ByClosing())
754	result.Response = resp
755	return
756}
757