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