1package eventgrid 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// DomainsClient is the azure EventGrid Management Client 30type DomainsClient struct { 31 BaseClient 32} 33 34// NewDomainsClient creates an instance of the DomainsClient client. 35func NewDomainsClient(subscriptionID string) DomainsClient { 36 return NewDomainsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewDomainsClientWithBaseURI creates an instance of the DomainsClient client using a custom endpoint. Use this when 40// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewDomainsClientWithBaseURI(baseURI string, subscriptionID string) DomainsClient { 42 return DomainsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CreateOrUpdate asynchronously creates or updates a new domain with the specified parameters. 46// Parameters: 47// resourceGroupName - the name of the resource group within the user's subscription. 48// domainName - name of the domain 49// domainInfo - domain information 50func (client DomainsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, domainName string, domainInfo Domain) (result DomainsCreateOrUpdateFuture, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/DomainsClient.CreateOrUpdate") 53 defer func() { 54 sc := -1 55 if result.Response() != nil { 56 sc = result.Response().StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, domainName, domainInfo) 62 if err != nil { 63 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "CreateOrUpdate", nil, "Failure preparing request") 64 return 65 } 66 67 result, err = client.CreateOrUpdateSender(req) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "CreateOrUpdate", result.Response(), "Failure sending request") 70 return 71 } 72 73 return 74} 75 76// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 77func (client DomainsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, domainName string, domainInfo Domain) (*http.Request, error) { 78 pathParameters := map[string]interface{}{ 79 "domainName": autorest.Encode("path", domainName), 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 } 83 84 const APIVersion = "2019-02-01-preview" 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 89 preparer := autorest.CreatePreparer( 90 autorest.AsContentType("application/json; charset=utf-8"), 91 autorest.AsPut(), 92 autorest.WithBaseURL(client.BaseURI), 93 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}", pathParameters), 94 autorest.WithJSON(domainInfo), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 100// http.Response Body if it receives an error. 101func (client DomainsClient) CreateOrUpdateSender(req *http.Request) (future DomainsCreateOrUpdateFuture, err error) { 102 var resp *http.Response 103 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 104 if err != nil { 105 return 106 } 107 future.Future, err = azure.NewFutureFromResponse(resp) 108 return 109} 110 111// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 112// closes the http.Response Body. 113func (client DomainsClient) CreateOrUpdateResponder(resp *http.Response) (result Domain, err error) { 114 err = autorest.Respond( 115 resp, 116 client.ByInspecting(), 117 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 118 autorest.ByUnmarshallingJSON(&result), 119 autorest.ByClosing()) 120 result.Response = autorest.Response{Response: resp} 121 return 122} 123 124// Delete delete existing domain 125// Parameters: 126// resourceGroupName - the name of the resource group within the user's subscription. 127// domainName - name of the domain 128func (client DomainsClient) Delete(ctx context.Context, resourceGroupName string, domainName string) (result DomainsDeleteFuture, err error) { 129 if tracing.IsEnabled() { 130 ctx = tracing.StartSpan(ctx, fqdn+"/DomainsClient.Delete") 131 defer func() { 132 sc := -1 133 if result.Response() != nil { 134 sc = result.Response().StatusCode 135 } 136 tracing.EndSpan(ctx, sc, err) 137 }() 138 } 139 req, err := client.DeletePreparer(ctx, resourceGroupName, domainName) 140 if err != nil { 141 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "Delete", nil, "Failure preparing request") 142 return 143 } 144 145 result, err = client.DeleteSender(req) 146 if err != nil { 147 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "Delete", result.Response(), "Failure sending request") 148 return 149 } 150 151 return 152} 153 154// DeletePreparer prepares the Delete request. 155func (client DomainsClient) DeletePreparer(ctx context.Context, resourceGroupName string, domainName string) (*http.Request, error) { 156 pathParameters := map[string]interface{}{ 157 "domainName": autorest.Encode("path", domainName), 158 "resourceGroupName": autorest.Encode("path", resourceGroupName), 159 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 160 } 161 162 const APIVersion = "2019-02-01-preview" 163 queryParameters := map[string]interface{}{ 164 "api-version": APIVersion, 165 } 166 167 preparer := autorest.CreatePreparer( 168 autorest.AsDelete(), 169 autorest.WithBaseURL(client.BaseURI), 170 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}", pathParameters), 171 autorest.WithQueryParameters(queryParameters)) 172 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 173} 174 175// DeleteSender sends the Delete request. The method will close the 176// http.Response Body if it receives an error. 177func (client DomainsClient) DeleteSender(req *http.Request) (future DomainsDeleteFuture, err error) { 178 var resp *http.Response 179 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 180 if err != nil { 181 return 182 } 183 future.Future, err = azure.NewFutureFromResponse(resp) 184 return 185} 186 187// DeleteResponder handles the response to the Delete request. The method always 188// closes the http.Response Body. 189func (client DomainsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 190 err = autorest.Respond( 191 resp, 192 client.ByInspecting(), 193 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 194 autorest.ByClosing()) 195 result.Response = resp 196 return 197} 198 199// Get get properties of a domain 200// Parameters: 201// resourceGroupName - the name of the resource group within the user's subscription. 202// domainName - name of the domain 203func (client DomainsClient) Get(ctx context.Context, resourceGroupName string, domainName string) (result Domain, err error) { 204 if tracing.IsEnabled() { 205 ctx = tracing.StartSpan(ctx, fqdn+"/DomainsClient.Get") 206 defer func() { 207 sc := -1 208 if result.Response.Response != nil { 209 sc = result.Response.Response.StatusCode 210 } 211 tracing.EndSpan(ctx, sc, err) 212 }() 213 } 214 req, err := client.GetPreparer(ctx, resourceGroupName, domainName) 215 if err != nil { 216 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "Get", nil, "Failure preparing request") 217 return 218 } 219 220 resp, err := client.GetSender(req) 221 if err != nil { 222 result.Response = autorest.Response{Response: resp} 223 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "Get", resp, "Failure sending request") 224 return 225 } 226 227 result, err = client.GetResponder(resp) 228 if err != nil { 229 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "Get", resp, "Failure responding to request") 230 } 231 232 return 233} 234 235// GetPreparer prepares the Get request. 236func (client DomainsClient) GetPreparer(ctx context.Context, resourceGroupName string, domainName string) (*http.Request, error) { 237 pathParameters := map[string]interface{}{ 238 "domainName": autorest.Encode("path", domainName), 239 "resourceGroupName": autorest.Encode("path", resourceGroupName), 240 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 241 } 242 243 const APIVersion = "2019-02-01-preview" 244 queryParameters := map[string]interface{}{ 245 "api-version": APIVersion, 246 } 247 248 preparer := autorest.CreatePreparer( 249 autorest.AsGet(), 250 autorest.WithBaseURL(client.BaseURI), 251 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}", pathParameters), 252 autorest.WithQueryParameters(queryParameters)) 253 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 254} 255 256// GetSender sends the Get request. The method will close the 257// http.Response Body if it receives an error. 258func (client DomainsClient) GetSender(req *http.Request) (*http.Response, error) { 259 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 260} 261 262// GetResponder handles the response to the Get request. The method always 263// closes the http.Response Body. 264func (client DomainsClient) GetResponder(resp *http.Response) (result Domain, err error) { 265 err = autorest.Respond( 266 resp, 267 client.ByInspecting(), 268 azure.WithErrorUnlessStatusCode(http.StatusOK), 269 autorest.ByUnmarshallingJSON(&result), 270 autorest.ByClosing()) 271 result.Response = autorest.Response{Response: resp} 272 return 273} 274 275// ListByResourceGroup list all the domains under a resource group 276// Parameters: 277// resourceGroupName - the name of the resource group within the user's subscription. 278// filter - filter the results using OData syntax. 279// top - the number of results to return. 280func (client DomainsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string, filter string, top *int32) (result DomainsListResultPage, err error) { 281 if tracing.IsEnabled() { 282 ctx = tracing.StartSpan(ctx, fqdn+"/DomainsClient.ListByResourceGroup") 283 defer func() { 284 sc := -1 285 if result.dlr.Response.Response != nil { 286 sc = result.dlr.Response.Response.StatusCode 287 } 288 tracing.EndSpan(ctx, sc, err) 289 }() 290 } 291 result.fn = client.listByResourceGroupNextResults 292 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName, filter, top) 293 if err != nil { 294 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "ListByResourceGroup", nil, "Failure preparing request") 295 return 296 } 297 298 resp, err := client.ListByResourceGroupSender(req) 299 if err != nil { 300 result.dlr.Response = autorest.Response{Response: resp} 301 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "ListByResourceGroup", resp, "Failure sending request") 302 return 303 } 304 305 result.dlr, err = client.ListByResourceGroupResponder(resp) 306 if err != nil { 307 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "ListByResourceGroup", resp, "Failure responding to request") 308 } 309 310 return 311} 312 313// ListByResourceGroupPreparer prepares the ListByResourceGroup request. 314func (client DomainsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string, filter string, top *int32) (*http.Request, error) { 315 pathParameters := map[string]interface{}{ 316 "resourceGroupName": autorest.Encode("path", resourceGroupName), 317 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 318 } 319 320 const APIVersion = "2019-02-01-preview" 321 queryParameters := map[string]interface{}{ 322 "api-version": APIVersion, 323 } 324 if len(filter) > 0 { 325 queryParameters["$filter"] = autorest.Encode("query", filter) 326 } 327 if top != nil { 328 queryParameters["$top"] = autorest.Encode("query", *top) 329 } 330 331 preparer := autorest.CreatePreparer( 332 autorest.AsGet(), 333 autorest.WithBaseURL(client.BaseURI), 334 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains", pathParameters), 335 autorest.WithQueryParameters(queryParameters)) 336 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 337} 338 339// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the 340// http.Response Body if it receives an error. 341func (client DomainsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { 342 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 343} 344 345// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always 346// closes the http.Response Body. 347func (client DomainsClient) ListByResourceGroupResponder(resp *http.Response) (result DomainsListResult, err error) { 348 err = autorest.Respond( 349 resp, 350 client.ByInspecting(), 351 azure.WithErrorUnlessStatusCode(http.StatusOK), 352 autorest.ByUnmarshallingJSON(&result), 353 autorest.ByClosing()) 354 result.Response = autorest.Response{Response: resp} 355 return 356} 357 358// listByResourceGroupNextResults retrieves the next set of results, if any. 359func (client DomainsClient) listByResourceGroupNextResults(ctx context.Context, lastResults DomainsListResult) (result DomainsListResult, err error) { 360 req, err := lastResults.domainsListResultPreparer(ctx) 361 if err != nil { 362 return result, autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request") 363 } 364 if req == nil { 365 return 366 } 367 resp, err := client.ListByResourceGroupSender(req) 368 if err != nil { 369 result.Response = autorest.Response{Response: resp} 370 return result, autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "listByResourceGroupNextResults", resp, "Failure sending next results request") 371 } 372 result, err = client.ListByResourceGroupResponder(resp) 373 if err != nil { 374 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request") 375 } 376 return 377} 378 379// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. 380func (client DomainsClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string, filter string, top *int32) (result DomainsListResultIterator, err error) { 381 if tracing.IsEnabled() { 382 ctx = tracing.StartSpan(ctx, fqdn+"/DomainsClient.ListByResourceGroup") 383 defer func() { 384 sc := -1 385 if result.Response().Response.Response != nil { 386 sc = result.page.Response().Response.Response.StatusCode 387 } 388 tracing.EndSpan(ctx, sc, err) 389 }() 390 } 391 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName, filter, top) 392 return 393} 394 395// ListBySubscription list all the domains under an Azure subscription 396// Parameters: 397// filter - filter the results using OData syntax. 398// top - the number of results to return. 399func (client DomainsClient) ListBySubscription(ctx context.Context, filter string, top *int32) (result DomainsListResultPage, err error) { 400 if tracing.IsEnabled() { 401 ctx = tracing.StartSpan(ctx, fqdn+"/DomainsClient.ListBySubscription") 402 defer func() { 403 sc := -1 404 if result.dlr.Response.Response != nil { 405 sc = result.dlr.Response.Response.StatusCode 406 } 407 tracing.EndSpan(ctx, sc, err) 408 }() 409 } 410 result.fn = client.listBySubscriptionNextResults 411 req, err := client.ListBySubscriptionPreparer(ctx, filter, top) 412 if err != nil { 413 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "ListBySubscription", nil, "Failure preparing request") 414 return 415 } 416 417 resp, err := client.ListBySubscriptionSender(req) 418 if err != nil { 419 result.dlr.Response = autorest.Response{Response: resp} 420 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "ListBySubscription", resp, "Failure sending request") 421 return 422 } 423 424 result.dlr, err = client.ListBySubscriptionResponder(resp) 425 if err != nil { 426 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "ListBySubscription", resp, "Failure responding to request") 427 } 428 429 return 430} 431 432// ListBySubscriptionPreparer prepares the ListBySubscription request. 433func (client DomainsClient) ListBySubscriptionPreparer(ctx context.Context, filter string, top *int32) (*http.Request, error) { 434 pathParameters := map[string]interface{}{ 435 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 436 } 437 438 const APIVersion = "2019-02-01-preview" 439 queryParameters := map[string]interface{}{ 440 "api-version": APIVersion, 441 } 442 if len(filter) > 0 { 443 queryParameters["$filter"] = autorest.Encode("query", filter) 444 } 445 if top != nil { 446 queryParameters["$top"] = autorest.Encode("query", *top) 447 } 448 449 preparer := autorest.CreatePreparer( 450 autorest.AsGet(), 451 autorest.WithBaseURL(client.BaseURI), 452 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.EventGrid/domains", pathParameters), 453 autorest.WithQueryParameters(queryParameters)) 454 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 455} 456 457// ListBySubscriptionSender sends the ListBySubscription request. The method will close the 458// http.Response Body if it receives an error. 459func (client DomainsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) { 460 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 461} 462 463// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always 464// closes the http.Response Body. 465func (client DomainsClient) ListBySubscriptionResponder(resp *http.Response) (result DomainsListResult, err error) { 466 err = autorest.Respond( 467 resp, 468 client.ByInspecting(), 469 azure.WithErrorUnlessStatusCode(http.StatusOK), 470 autorest.ByUnmarshallingJSON(&result), 471 autorest.ByClosing()) 472 result.Response = autorest.Response{Response: resp} 473 return 474} 475 476// listBySubscriptionNextResults retrieves the next set of results, if any. 477func (client DomainsClient) listBySubscriptionNextResults(ctx context.Context, lastResults DomainsListResult) (result DomainsListResult, err error) { 478 req, err := lastResults.domainsListResultPreparer(ctx) 479 if err != nil { 480 return result, autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request") 481 } 482 if req == nil { 483 return 484 } 485 resp, err := client.ListBySubscriptionSender(req) 486 if err != nil { 487 result.Response = autorest.Response{Response: resp} 488 return result, autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "listBySubscriptionNextResults", resp, "Failure sending next results request") 489 } 490 result, err = client.ListBySubscriptionResponder(resp) 491 if err != nil { 492 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request") 493 } 494 return 495} 496 497// ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required. 498func (client DomainsClient) ListBySubscriptionComplete(ctx context.Context, filter string, top *int32) (result DomainsListResultIterator, err error) { 499 if tracing.IsEnabled() { 500 ctx = tracing.StartSpan(ctx, fqdn+"/DomainsClient.ListBySubscription") 501 defer func() { 502 sc := -1 503 if result.Response().Response.Response != nil { 504 sc = result.page.Response().Response.Response.StatusCode 505 } 506 tracing.EndSpan(ctx, sc, err) 507 }() 508 } 509 result.page, err = client.ListBySubscription(ctx, filter, top) 510 return 511} 512 513// ListSharedAccessKeys list the two keys used to publish to a domain 514// Parameters: 515// resourceGroupName - the name of the resource group within the user's subscription. 516// domainName - name of the domain 517func (client DomainsClient) ListSharedAccessKeys(ctx context.Context, resourceGroupName string, domainName string) (result DomainSharedAccessKeys, err error) { 518 if tracing.IsEnabled() { 519 ctx = tracing.StartSpan(ctx, fqdn+"/DomainsClient.ListSharedAccessKeys") 520 defer func() { 521 sc := -1 522 if result.Response.Response != nil { 523 sc = result.Response.Response.StatusCode 524 } 525 tracing.EndSpan(ctx, sc, err) 526 }() 527 } 528 req, err := client.ListSharedAccessKeysPreparer(ctx, resourceGroupName, domainName) 529 if err != nil { 530 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "ListSharedAccessKeys", nil, "Failure preparing request") 531 return 532 } 533 534 resp, err := client.ListSharedAccessKeysSender(req) 535 if err != nil { 536 result.Response = autorest.Response{Response: resp} 537 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "ListSharedAccessKeys", resp, "Failure sending request") 538 return 539 } 540 541 result, err = client.ListSharedAccessKeysResponder(resp) 542 if err != nil { 543 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "ListSharedAccessKeys", resp, "Failure responding to request") 544 } 545 546 return 547} 548 549// ListSharedAccessKeysPreparer prepares the ListSharedAccessKeys request. 550func (client DomainsClient) ListSharedAccessKeysPreparer(ctx context.Context, resourceGroupName string, domainName string) (*http.Request, error) { 551 pathParameters := map[string]interface{}{ 552 "domainName": autorest.Encode("path", domainName), 553 "resourceGroupName": autorest.Encode("path", resourceGroupName), 554 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 555 } 556 557 const APIVersion = "2019-02-01-preview" 558 queryParameters := map[string]interface{}{ 559 "api-version": APIVersion, 560 } 561 562 preparer := autorest.CreatePreparer( 563 autorest.AsPost(), 564 autorest.WithBaseURL(client.BaseURI), 565 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}/listKeys", pathParameters), 566 autorest.WithQueryParameters(queryParameters)) 567 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 568} 569 570// ListSharedAccessKeysSender sends the ListSharedAccessKeys request. The method will close the 571// http.Response Body if it receives an error. 572func (client DomainsClient) ListSharedAccessKeysSender(req *http.Request) (*http.Response, error) { 573 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 574} 575 576// ListSharedAccessKeysResponder handles the response to the ListSharedAccessKeys request. The method always 577// closes the http.Response Body. 578func (client DomainsClient) ListSharedAccessKeysResponder(resp *http.Response) (result DomainSharedAccessKeys, err error) { 579 err = autorest.Respond( 580 resp, 581 client.ByInspecting(), 582 azure.WithErrorUnlessStatusCode(http.StatusOK), 583 autorest.ByUnmarshallingJSON(&result), 584 autorest.ByClosing()) 585 result.Response = autorest.Response{Response: resp} 586 return 587} 588 589// RegenerateKey regenerate a shared access key for a domain 590// Parameters: 591// resourceGroupName - the name of the resource group within the user's subscription. 592// domainName - name of the domain 593// regenerateKeyRequest - request body to regenerate key 594func (client DomainsClient) RegenerateKey(ctx context.Context, resourceGroupName string, domainName string, regenerateKeyRequest DomainRegenerateKeyRequest) (result DomainSharedAccessKeys, err error) { 595 if tracing.IsEnabled() { 596 ctx = tracing.StartSpan(ctx, fqdn+"/DomainsClient.RegenerateKey") 597 defer func() { 598 sc := -1 599 if result.Response.Response != nil { 600 sc = result.Response.Response.StatusCode 601 } 602 tracing.EndSpan(ctx, sc, err) 603 }() 604 } 605 if err := validation.Validate([]validation.Validation{ 606 {TargetValue: regenerateKeyRequest, 607 Constraints: []validation.Constraint{{Target: "regenerateKeyRequest.KeyName", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 608 return result, validation.NewError("eventgrid.DomainsClient", "RegenerateKey", err.Error()) 609 } 610 611 req, err := client.RegenerateKeyPreparer(ctx, resourceGroupName, domainName, regenerateKeyRequest) 612 if err != nil { 613 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "RegenerateKey", nil, "Failure preparing request") 614 return 615 } 616 617 resp, err := client.RegenerateKeySender(req) 618 if err != nil { 619 result.Response = autorest.Response{Response: resp} 620 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "RegenerateKey", resp, "Failure sending request") 621 return 622 } 623 624 result, err = client.RegenerateKeyResponder(resp) 625 if err != nil { 626 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "RegenerateKey", resp, "Failure responding to request") 627 } 628 629 return 630} 631 632// RegenerateKeyPreparer prepares the RegenerateKey request. 633func (client DomainsClient) RegenerateKeyPreparer(ctx context.Context, resourceGroupName string, domainName string, regenerateKeyRequest DomainRegenerateKeyRequest) (*http.Request, error) { 634 pathParameters := map[string]interface{}{ 635 "domainName": autorest.Encode("path", domainName), 636 "resourceGroupName": autorest.Encode("path", resourceGroupName), 637 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 638 } 639 640 const APIVersion = "2019-02-01-preview" 641 queryParameters := map[string]interface{}{ 642 "api-version": APIVersion, 643 } 644 645 preparer := autorest.CreatePreparer( 646 autorest.AsContentType("application/json; charset=utf-8"), 647 autorest.AsPost(), 648 autorest.WithBaseURL(client.BaseURI), 649 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}/regenerateKey", pathParameters), 650 autorest.WithJSON(regenerateKeyRequest), 651 autorest.WithQueryParameters(queryParameters)) 652 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 653} 654 655// RegenerateKeySender sends the RegenerateKey request. The method will close the 656// http.Response Body if it receives an error. 657func (client DomainsClient) RegenerateKeySender(req *http.Request) (*http.Response, error) { 658 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 659} 660 661// RegenerateKeyResponder handles the response to the RegenerateKey request. The method always 662// closes the http.Response Body. 663func (client DomainsClient) RegenerateKeyResponder(resp *http.Response) (result DomainSharedAccessKeys, err error) { 664 err = autorest.Respond( 665 resp, 666 client.ByInspecting(), 667 azure.WithErrorUnlessStatusCode(http.StatusOK), 668 autorest.ByUnmarshallingJSON(&result), 669 autorest.ByClosing()) 670 result.Response = autorest.Response{Response: resp} 671 return 672} 673 674// Update asynchronously updates a domain with the specified parameters. 675// Parameters: 676// resourceGroupName - the name of the resource group within the user's subscription. 677// domainName - name of the domain 678// domainUpdateParameters - domain update information 679func (client DomainsClient) Update(ctx context.Context, resourceGroupName string, domainName string, domainUpdateParameters DomainUpdateParameters) (result DomainsUpdateFuture, err error) { 680 if tracing.IsEnabled() { 681 ctx = tracing.StartSpan(ctx, fqdn+"/DomainsClient.Update") 682 defer func() { 683 sc := -1 684 if result.Response() != nil { 685 sc = result.Response().StatusCode 686 } 687 tracing.EndSpan(ctx, sc, err) 688 }() 689 } 690 req, err := client.UpdatePreparer(ctx, resourceGroupName, domainName, domainUpdateParameters) 691 if err != nil { 692 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "Update", nil, "Failure preparing request") 693 return 694 } 695 696 result, err = client.UpdateSender(req) 697 if err != nil { 698 err = autorest.NewErrorWithError(err, "eventgrid.DomainsClient", "Update", result.Response(), "Failure sending request") 699 return 700 } 701 702 return 703} 704 705// UpdatePreparer prepares the Update request. 706func (client DomainsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, domainName string, domainUpdateParameters DomainUpdateParameters) (*http.Request, error) { 707 pathParameters := map[string]interface{}{ 708 "domainName": autorest.Encode("path", domainName), 709 "resourceGroupName": autorest.Encode("path", resourceGroupName), 710 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 711 } 712 713 const APIVersion = "2019-02-01-preview" 714 queryParameters := map[string]interface{}{ 715 "api-version": APIVersion, 716 } 717 718 preparer := autorest.CreatePreparer( 719 autorest.AsContentType("application/json; charset=utf-8"), 720 autorest.AsPatch(), 721 autorest.WithBaseURL(client.BaseURI), 722 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}", pathParameters), 723 autorest.WithJSON(domainUpdateParameters), 724 autorest.WithQueryParameters(queryParameters)) 725 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 726} 727 728// UpdateSender sends the Update request. The method will close the 729// http.Response Body if it receives an error. 730func (client DomainsClient) UpdateSender(req *http.Request) (future DomainsUpdateFuture, err error) { 731 var resp *http.Response 732 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 733 if err != nil { 734 return 735 } 736 future.Future, err = azure.NewFutureFromResponse(resp) 737 return 738} 739 740// UpdateResponder handles the response to the Update request. The method always 741// closes the http.Response Body. 742func (client DomainsClient) UpdateResponder(resp *http.Response) (result Domain, err error) { 743 err = autorest.Respond( 744 resp, 745 client.ByInspecting(), 746 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 747 autorest.ByUnmarshallingJSON(&result), 748 autorest.ByClosing()) 749 result.Response = autorest.Response{Response: resp} 750 return 751} 752