1// +build go1.13 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// Code generated by Microsoft (R) AutoRest Code Generator. 6// Changes may cause incorrect behavior and will be lost if the code is regenerated. 7 8package armapimanagement 9 10import ( 11 "context" 12 "errors" 13 "fmt" 14 "github.com/Azure/azure-sdk-for-go/sdk/armcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 16 "net/http" 17 "net/url" 18 "strings" 19) 20 21// IdentityProviderClient contains the methods for the IdentityProvider group. 22// Don't use this type directly, use NewIdentityProviderClient() instead. 23type IdentityProviderClient struct { 24 con *armcore.Connection 25 subscriptionID string 26} 27 28// NewIdentityProviderClient creates a new instance of IdentityProviderClient with the specified values. 29func NewIdentityProviderClient(con *armcore.Connection, subscriptionID string) *IdentityProviderClient { 30 return &IdentityProviderClient{con: con, subscriptionID: subscriptionID} 31} 32 33// CreateOrUpdate - Creates or Updates the IdentityProvider configuration. 34// If the operation fails it returns the *ErrorResponse error type. 35func (client *IdentityProviderClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, parameters IdentityProviderCreateContract, options *IdentityProviderCreateOrUpdateOptions) (IdentityProviderCreateOrUpdateResponse, error) { 36 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, serviceName, identityProviderName, parameters, options) 37 if err != nil { 38 return IdentityProviderCreateOrUpdateResponse{}, err 39 } 40 resp, err := client.con.Pipeline().Do(req) 41 if err != nil { 42 return IdentityProviderCreateOrUpdateResponse{}, err 43 } 44 if !resp.HasStatusCode(http.StatusOK, http.StatusCreated) { 45 return IdentityProviderCreateOrUpdateResponse{}, client.createOrUpdateHandleError(resp) 46 } 47 return client.createOrUpdateHandleResponse(resp) 48} 49 50// createOrUpdateCreateRequest creates the CreateOrUpdate request. 51func (client *IdentityProviderClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, parameters IdentityProviderCreateContract, options *IdentityProviderCreateOrUpdateOptions) (*azcore.Request, error) { 52 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/identityProviders/{identityProviderName}" 53 if resourceGroupName == "" { 54 return nil, errors.New("parameter resourceGroupName cannot be empty") 55 } 56 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 57 if serviceName == "" { 58 return nil, errors.New("parameter serviceName cannot be empty") 59 } 60 urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName)) 61 if identityProviderName == "" { 62 return nil, errors.New("parameter identityProviderName cannot be empty") 63 } 64 urlPath = strings.ReplaceAll(urlPath, "{identityProviderName}", url.PathEscape(string(identityProviderName))) 65 if client.subscriptionID == "" { 66 return nil, errors.New("parameter client.subscriptionID cannot be empty") 67 } 68 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 69 req, err := azcore.NewRequest(ctx, http.MethodPut, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 70 if err != nil { 71 return nil, err 72 } 73 req.Telemetry(telemetryInfo) 74 reqQP := req.URL.Query() 75 reqQP.Set("api-version", "2020-12-01") 76 req.URL.RawQuery = reqQP.Encode() 77 if options != nil && options.IfMatch != nil { 78 req.Header.Set("If-Match", *options.IfMatch) 79 } 80 req.Header.Set("Accept", "application/json") 81 return req, req.MarshalAsJSON(parameters) 82} 83 84// createOrUpdateHandleResponse handles the CreateOrUpdate response. 85func (client *IdentityProviderClient) createOrUpdateHandleResponse(resp *azcore.Response) (IdentityProviderCreateOrUpdateResponse, error) { 86 result := IdentityProviderCreateOrUpdateResponse{RawResponse: resp.Response} 87 if val := resp.Header.Get("ETag"); val != "" { 88 result.ETag = &val 89 } 90 if err := resp.UnmarshalAsJSON(&result.IdentityProviderContract); err != nil { 91 return IdentityProviderCreateOrUpdateResponse{}, err 92 } 93 return result, nil 94} 95 96// createOrUpdateHandleError handles the CreateOrUpdate error response. 97func (client *IdentityProviderClient) createOrUpdateHandleError(resp *azcore.Response) error { 98 body, err := resp.Payload() 99 if err != nil { 100 return azcore.NewResponseError(err, resp.Response) 101 } 102 errType := ErrorResponse{raw: string(body)} 103 if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil { 104 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 105 } 106 return azcore.NewResponseError(&errType, resp.Response) 107} 108 109// Delete - Deletes the specified identity provider configuration. 110// If the operation fails it returns the *ErrorResponse error type. 111func (client *IdentityProviderClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, ifMatch string, options *IdentityProviderDeleteOptions) (IdentityProviderDeleteResponse, error) { 112 req, err := client.deleteCreateRequest(ctx, resourceGroupName, serviceName, identityProviderName, ifMatch, options) 113 if err != nil { 114 return IdentityProviderDeleteResponse{}, err 115 } 116 resp, err := client.con.Pipeline().Do(req) 117 if err != nil { 118 return IdentityProviderDeleteResponse{}, err 119 } 120 if !resp.HasStatusCode(http.StatusOK, http.StatusNoContent) { 121 return IdentityProviderDeleteResponse{}, client.deleteHandleError(resp) 122 } 123 return IdentityProviderDeleteResponse{RawResponse: resp.Response}, nil 124} 125 126// deleteCreateRequest creates the Delete request. 127func (client *IdentityProviderClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, ifMatch string, options *IdentityProviderDeleteOptions) (*azcore.Request, error) { 128 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/identityProviders/{identityProviderName}" 129 if resourceGroupName == "" { 130 return nil, errors.New("parameter resourceGroupName cannot be empty") 131 } 132 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 133 if serviceName == "" { 134 return nil, errors.New("parameter serviceName cannot be empty") 135 } 136 urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName)) 137 if identityProviderName == "" { 138 return nil, errors.New("parameter identityProviderName cannot be empty") 139 } 140 urlPath = strings.ReplaceAll(urlPath, "{identityProviderName}", url.PathEscape(string(identityProviderName))) 141 if client.subscriptionID == "" { 142 return nil, errors.New("parameter client.subscriptionID cannot be empty") 143 } 144 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 145 req, err := azcore.NewRequest(ctx, http.MethodDelete, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 146 if err != nil { 147 return nil, err 148 } 149 req.Telemetry(telemetryInfo) 150 reqQP := req.URL.Query() 151 reqQP.Set("api-version", "2020-12-01") 152 req.URL.RawQuery = reqQP.Encode() 153 req.Header.Set("If-Match", ifMatch) 154 req.Header.Set("Accept", "application/json") 155 return req, nil 156} 157 158// deleteHandleError handles the Delete error response. 159func (client *IdentityProviderClient) deleteHandleError(resp *azcore.Response) error { 160 body, err := resp.Payload() 161 if err != nil { 162 return azcore.NewResponseError(err, resp.Response) 163 } 164 errType := ErrorResponse{raw: string(body)} 165 if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil { 166 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 167 } 168 return azcore.NewResponseError(&errType, resp.Response) 169} 170 171// Get - Gets the configuration details of the identity Provider configured in specified service instance. 172// If the operation fails it returns the *ErrorResponse error type. 173func (client *IdentityProviderClient) Get(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, options *IdentityProviderGetOptions) (IdentityProviderGetResponse, error) { 174 req, err := client.getCreateRequest(ctx, resourceGroupName, serviceName, identityProviderName, options) 175 if err != nil { 176 return IdentityProviderGetResponse{}, err 177 } 178 resp, err := client.con.Pipeline().Do(req) 179 if err != nil { 180 return IdentityProviderGetResponse{}, err 181 } 182 if !resp.HasStatusCode(http.StatusOK) { 183 return IdentityProviderGetResponse{}, client.getHandleError(resp) 184 } 185 return client.getHandleResponse(resp) 186} 187 188// getCreateRequest creates the Get request. 189func (client *IdentityProviderClient) getCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, options *IdentityProviderGetOptions) (*azcore.Request, error) { 190 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/identityProviders/{identityProviderName}" 191 if resourceGroupName == "" { 192 return nil, errors.New("parameter resourceGroupName cannot be empty") 193 } 194 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 195 if serviceName == "" { 196 return nil, errors.New("parameter serviceName cannot be empty") 197 } 198 urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName)) 199 if identityProviderName == "" { 200 return nil, errors.New("parameter identityProviderName cannot be empty") 201 } 202 urlPath = strings.ReplaceAll(urlPath, "{identityProviderName}", url.PathEscape(string(identityProviderName))) 203 if client.subscriptionID == "" { 204 return nil, errors.New("parameter client.subscriptionID cannot be empty") 205 } 206 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 207 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 208 if err != nil { 209 return nil, err 210 } 211 req.Telemetry(telemetryInfo) 212 reqQP := req.URL.Query() 213 reqQP.Set("api-version", "2020-12-01") 214 req.URL.RawQuery = reqQP.Encode() 215 req.Header.Set("Accept", "application/json") 216 return req, nil 217} 218 219// getHandleResponse handles the Get response. 220func (client *IdentityProviderClient) getHandleResponse(resp *azcore.Response) (IdentityProviderGetResponse, error) { 221 result := IdentityProviderGetResponse{RawResponse: resp.Response} 222 if val := resp.Header.Get("ETag"); val != "" { 223 result.ETag = &val 224 } 225 if err := resp.UnmarshalAsJSON(&result.IdentityProviderContract); err != nil { 226 return IdentityProviderGetResponse{}, err 227 } 228 return result, nil 229} 230 231// getHandleError handles the Get error response. 232func (client *IdentityProviderClient) getHandleError(resp *azcore.Response) error { 233 body, err := resp.Payload() 234 if err != nil { 235 return azcore.NewResponseError(err, resp.Response) 236 } 237 errType := ErrorResponse{raw: string(body)} 238 if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil { 239 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 240 } 241 return azcore.NewResponseError(&errType, resp.Response) 242} 243 244// GetEntityTag - Gets the entity state (Etag) version of the identityProvider specified by its identifier. 245// If the operation fails it returns the *ErrorResponse error type. 246func (client *IdentityProviderClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, options *IdentityProviderGetEntityTagOptions) (IdentityProviderGetEntityTagResponse, error) { 247 req, err := client.getEntityTagCreateRequest(ctx, resourceGroupName, serviceName, identityProviderName, options) 248 if err != nil { 249 return IdentityProviderGetEntityTagResponse{}, err 250 } 251 resp, err := client.con.Pipeline().Do(req) 252 if err != nil { 253 return IdentityProviderGetEntityTagResponse{}, err 254 } 255 return client.getEntityTagHandleResponse(resp) 256} 257 258// getEntityTagCreateRequest creates the GetEntityTag request. 259func (client *IdentityProviderClient) getEntityTagCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, options *IdentityProviderGetEntityTagOptions) (*azcore.Request, error) { 260 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/identityProviders/{identityProviderName}" 261 if resourceGroupName == "" { 262 return nil, errors.New("parameter resourceGroupName cannot be empty") 263 } 264 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 265 if serviceName == "" { 266 return nil, errors.New("parameter serviceName cannot be empty") 267 } 268 urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName)) 269 if identityProviderName == "" { 270 return nil, errors.New("parameter identityProviderName cannot be empty") 271 } 272 urlPath = strings.ReplaceAll(urlPath, "{identityProviderName}", url.PathEscape(string(identityProviderName))) 273 if client.subscriptionID == "" { 274 return nil, errors.New("parameter client.subscriptionID cannot be empty") 275 } 276 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 277 req, err := azcore.NewRequest(ctx, http.MethodHead, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 278 if err != nil { 279 return nil, err 280 } 281 req.Telemetry(telemetryInfo) 282 reqQP := req.URL.Query() 283 reqQP.Set("api-version", "2020-12-01") 284 req.URL.RawQuery = reqQP.Encode() 285 req.Header.Set("Accept", "application/json") 286 return req, nil 287} 288 289// getEntityTagHandleResponse handles the GetEntityTag response. 290func (client *IdentityProviderClient) getEntityTagHandleResponse(resp *azcore.Response) (IdentityProviderGetEntityTagResponse, error) { 291 result := IdentityProviderGetEntityTagResponse{RawResponse: resp.Response} 292 if val := resp.Header.Get("ETag"); val != "" { 293 result.ETag = &val 294 } 295 if resp.StatusCode >= 200 && resp.StatusCode < 300 { 296 result.Success = true 297 } 298 return result, nil 299} 300 301// ListByService - Lists a collection of Identity Provider configured in the specified service instance. 302// If the operation fails it returns the *ErrorResponse error type. 303func (client *IdentityProviderClient) ListByService(resourceGroupName string, serviceName string, options *IdentityProviderListByServiceOptions) IdentityProviderListByServicePager { 304 return &identityProviderListByServicePager{ 305 client: client, 306 requester: func(ctx context.Context) (*azcore.Request, error) { 307 return client.listByServiceCreateRequest(ctx, resourceGroupName, serviceName, options) 308 }, 309 advancer: func(ctx context.Context, resp IdentityProviderListByServiceResponse) (*azcore.Request, error) { 310 return azcore.NewRequest(ctx, http.MethodGet, *resp.IdentityProviderList.NextLink) 311 }, 312 } 313} 314 315// listByServiceCreateRequest creates the ListByService request. 316func (client *IdentityProviderClient) listByServiceCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, options *IdentityProviderListByServiceOptions) (*azcore.Request, error) { 317 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/identityProviders" 318 if resourceGroupName == "" { 319 return nil, errors.New("parameter resourceGroupName cannot be empty") 320 } 321 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 322 if serviceName == "" { 323 return nil, errors.New("parameter serviceName cannot be empty") 324 } 325 urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName)) 326 if client.subscriptionID == "" { 327 return nil, errors.New("parameter client.subscriptionID cannot be empty") 328 } 329 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 330 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 331 if err != nil { 332 return nil, err 333 } 334 req.Telemetry(telemetryInfo) 335 reqQP := req.URL.Query() 336 reqQP.Set("api-version", "2020-12-01") 337 req.URL.RawQuery = reqQP.Encode() 338 req.Header.Set("Accept", "application/json") 339 return req, nil 340} 341 342// listByServiceHandleResponse handles the ListByService response. 343func (client *IdentityProviderClient) listByServiceHandleResponse(resp *azcore.Response) (IdentityProviderListByServiceResponse, error) { 344 result := IdentityProviderListByServiceResponse{RawResponse: resp.Response} 345 if err := resp.UnmarshalAsJSON(&result.IdentityProviderList); err != nil { 346 return IdentityProviderListByServiceResponse{}, err 347 } 348 return result, nil 349} 350 351// listByServiceHandleError handles the ListByService error response. 352func (client *IdentityProviderClient) listByServiceHandleError(resp *azcore.Response) error { 353 body, err := resp.Payload() 354 if err != nil { 355 return azcore.NewResponseError(err, resp.Response) 356 } 357 errType := ErrorResponse{raw: string(body)} 358 if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil { 359 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 360 } 361 return azcore.NewResponseError(&errType, resp.Response) 362} 363 364// ListSecrets - Gets the client secret details of the Identity Provider. 365// If the operation fails it returns the *ErrorResponse error type. 366func (client *IdentityProviderClient) ListSecrets(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, options *IdentityProviderListSecretsOptions) (IdentityProviderListSecretsResponse, error) { 367 req, err := client.listSecretsCreateRequest(ctx, resourceGroupName, serviceName, identityProviderName, options) 368 if err != nil { 369 return IdentityProviderListSecretsResponse{}, err 370 } 371 resp, err := client.con.Pipeline().Do(req) 372 if err != nil { 373 return IdentityProviderListSecretsResponse{}, err 374 } 375 if !resp.HasStatusCode(http.StatusOK) { 376 return IdentityProviderListSecretsResponse{}, client.listSecretsHandleError(resp) 377 } 378 return client.listSecretsHandleResponse(resp) 379} 380 381// listSecretsCreateRequest creates the ListSecrets request. 382func (client *IdentityProviderClient) listSecretsCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, options *IdentityProviderListSecretsOptions) (*azcore.Request, error) { 383 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/identityProviders/{identityProviderName}/listSecrets" 384 if resourceGroupName == "" { 385 return nil, errors.New("parameter resourceGroupName cannot be empty") 386 } 387 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 388 if serviceName == "" { 389 return nil, errors.New("parameter serviceName cannot be empty") 390 } 391 urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName)) 392 if identityProviderName == "" { 393 return nil, errors.New("parameter identityProviderName cannot be empty") 394 } 395 urlPath = strings.ReplaceAll(urlPath, "{identityProviderName}", url.PathEscape(string(identityProviderName))) 396 if client.subscriptionID == "" { 397 return nil, errors.New("parameter client.subscriptionID cannot be empty") 398 } 399 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 400 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 401 if err != nil { 402 return nil, err 403 } 404 req.Telemetry(telemetryInfo) 405 reqQP := req.URL.Query() 406 reqQP.Set("api-version", "2020-12-01") 407 req.URL.RawQuery = reqQP.Encode() 408 req.Header.Set("Accept", "application/json") 409 return req, nil 410} 411 412// listSecretsHandleResponse handles the ListSecrets response. 413func (client *IdentityProviderClient) listSecretsHandleResponse(resp *azcore.Response) (IdentityProviderListSecretsResponse, error) { 414 result := IdentityProviderListSecretsResponse{RawResponse: resp.Response} 415 if val := resp.Header.Get("ETag"); val != "" { 416 result.ETag = &val 417 } 418 if err := resp.UnmarshalAsJSON(&result.ClientSecretContract); err != nil { 419 return IdentityProviderListSecretsResponse{}, err 420 } 421 return result, nil 422} 423 424// listSecretsHandleError handles the ListSecrets error response. 425func (client *IdentityProviderClient) listSecretsHandleError(resp *azcore.Response) error { 426 body, err := resp.Payload() 427 if err != nil { 428 return azcore.NewResponseError(err, resp.Response) 429 } 430 errType := ErrorResponse{raw: string(body)} 431 if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil { 432 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 433 } 434 return azcore.NewResponseError(&errType, resp.Response) 435} 436 437// Update - Updates an existing IdentityProvider configuration. 438// If the operation fails it returns the *ErrorResponse error type. 439func (client *IdentityProviderClient) Update(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, ifMatch string, parameters IdentityProviderUpdateParameters, options *IdentityProviderUpdateOptions) (IdentityProviderUpdateResponse, error) { 440 req, err := client.updateCreateRequest(ctx, resourceGroupName, serviceName, identityProviderName, ifMatch, parameters, options) 441 if err != nil { 442 return IdentityProviderUpdateResponse{}, err 443 } 444 resp, err := client.con.Pipeline().Do(req) 445 if err != nil { 446 return IdentityProviderUpdateResponse{}, err 447 } 448 if !resp.HasStatusCode(http.StatusOK) { 449 return IdentityProviderUpdateResponse{}, client.updateHandleError(resp) 450 } 451 return client.updateHandleResponse(resp) 452} 453 454// updateCreateRequest creates the Update request. 455func (client *IdentityProviderClient) updateCreateRequest(ctx context.Context, resourceGroupName string, serviceName string, identityProviderName IdentityProviderType, ifMatch string, parameters IdentityProviderUpdateParameters, options *IdentityProviderUpdateOptions) (*azcore.Request, error) { 456 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/identityProviders/{identityProviderName}" 457 if resourceGroupName == "" { 458 return nil, errors.New("parameter resourceGroupName cannot be empty") 459 } 460 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 461 if serviceName == "" { 462 return nil, errors.New("parameter serviceName cannot be empty") 463 } 464 urlPath = strings.ReplaceAll(urlPath, "{serviceName}", url.PathEscape(serviceName)) 465 if identityProviderName == "" { 466 return nil, errors.New("parameter identityProviderName cannot be empty") 467 } 468 urlPath = strings.ReplaceAll(urlPath, "{identityProviderName}", url.PathEscape(string(identityProviderName))) 469 if client.subscriptionID == "" { 470 return nil, errors.New("parameter client.subscriptionID cannot be empty") 471 } 472 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 473 req, err := azcore.NewRequest(ctx, http.MethodPatch, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 474 if err != nil { 475 return nil, err 476 } 477 req.Telemetry(telemetryInfo) 478 reqQP := req.URL.Query() 479 reqQP.Set("api-version", "2020-12-01") 480 req.URL.RawQuery = reqQP.Encode() 481 req.Header.Set("If-Match", ifMatch) 482 req.Header.Set("Accept", "application/json") 483 return req, req.MarshalAsJSON(parameters) 484} 485 486// updateHandleResponse handles the Update response. 487func (client *IdentityProviderClient) updateHandleResponse(resp *azcore.Response) (IdentityProviderUpdateResponse, error) { 488 result := IdentityProviderUpdateResponse{RawResponse: resp.Response} 489 if val := resp.Header.Get("ETag"); val != "" { 490 result.ETag = &val 491 } 492 if err := resp.UnmarshalAsJSON(&result.IdentityProviderContract); err != nil { 493 return IdentityProviderUpdateResponse{}, err 494 } 495 return result, nil 496} 497 498// updateHandleError handles the Update error response. 499func (client *IdentityProviderClient) updateHandleError(resp *azcore.Response) error { 500 body, err := resp.Payload() 501 if err != nil { 502 return azcore.NewResponseError(err, resp.Response) 503 } 504 errType := ErrorResponse{raw: string(body)} 505 if err := resp.UnmarshalAsJSON(&errType.InnerError); err != nil { 506 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 507 } 508 return azcore.NewResponseError(&errType, resp.Response) 509} 510