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