1package automation 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// WatcherClient is the automation Client 30type WatcherClient struct { 31 BaseClient 32} 33 34// NewWatcherClient creates an instance of the WatcherClient client. 35func NewWatcherClient(subscriptionID string) WatcherClient { 36 return NewWatcherClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewWatcherClientWithBaseURI creates an instance of the WatcherClient 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 NewWatcherClientWithBaseURI(baseURI string, subscriptionID string) WatcherClient { 42 return WatcherClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CreateOrUpdate create the watcher identified by watcher name. 46// Parameters: 47// resourceGroupName - name of an Azure Resource group. 48// automationAccountName - the name of the automation account. 49// watcherName - the watcher name. 50// parameters - the create or update parameters for watcher. 51func (client WatcherClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string, parameters Watcher) (result Watcher, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/WatcherClient.CreateOrUpdate") 54 defer func() { 55 sc := -1 56 if result.Response.Response != nil { 57 sc = result.Response.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: resourceGroupName, 64 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 65 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 66 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 67 return result, validation.NewError("automation.WatcherClient", "CreateOrUpdate", err.Error()) 68 } 69 70 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, automationAccountName, watcherName, parameters) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "CreateOrUpdate", nil, "Failure preparing request") 73 return 74 } 75 76 resp, err := client.CreateOrUpdateSender(req) 77 if err != nil { 78 result.Response = autorest.Response{Response: resp} 79 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "CreateOrUpdate", resp, "Failure sending request") 80 return 81 } 82 83 result, err = client.CreateOrUpdateResponder(resp) 84 if err != nil { 85 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "CreateOrUpdate", resp, "Failure responding to request") 86 } 87 88 return 89} 90 91// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 92func (client WatcherClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string, parameters Watcher) (*http.Request, error) { 93 pathParameters := map[string]interface{}{ 94 "automationAccountName": autorest.Encode("path", automationAccountName), 95 "resourceGroupName": autorest.Encode("path", resourceGroupName), 96 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 97 "watcherName": autorest.Encode("path", watcherName), 98 } 99 100 const APIVersion = "2015-10-31" 101 queryParameters := map[string]interface{}{ 102 "api-version": APIVersion, 103 } 104 105 preparer := autorest.CreatePreparer( 106 autorest.AsContentType("application/json; charset=utf-8"), 107 autorest.AsPut(), 108 autorest.WithBaseURL(client.BaseURI), 109 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/watchers/{watcherName}", pathParameters), 110 autorest.WithJSON(parameters), 111 autorest.WithQueryParameters(queryParameters)) 112 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 113} 114 115// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 116// http.Response Body if it receives an error. 117func (client WatcherClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 118 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 119} 120 121// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 122// closes the http.Response Body. 123func (client WatcherClient) CreateOrUpdateResponder(resp *http.Response) (result Watcher, err error) { 124 err = autorest.Respond( 125 resp, 126 client.ByInspecting(), 127 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 128 autorest.ByUnmarshallingJSON(&result), 129 autorest.ByClosing()) 130 result.Response = autorest.Response{Response: resp} 131 return 132} 133 134// Delete delete the watcher by name. 135// Parameters: 136// resourceGroupName - name of an Azure Resource group. 137// automationAccountName - the name of the automation account. 138// watcherName - the watcher name. 139func (client WatcherClient) Delete(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string) (result autorest.Response, err error) { 140 if tracing.IsEnabled() { 141 ctx = tracing.StartSpan(ctx, fqdn+"/WatcherClient.Delete") 142 defer func() { 143 sc := -1 144 if result.Response != nil { 145 sc = result.Response.StatusCode 146 } 147 tracing.EndSpan(ctx, sc, err) 148 }() 149 } 150 if err := validation.Validate([]validation.Validation{ 151 {TargetValue: resourceGroupName, 152 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 153 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 154 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 155 return result, validation.NewError("automation.WatcherClient", "Delete", err.Error()) 156 } 157 158 req, err := client.DeletePreparer(ctx, resourceGroupName, automationAccountName, watcherName) 159 if err != nil { 160 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Delete", nil, "Failure preparing request") 161 return 162 } 163 164 resp, err := client.DeleteSender(req) 165 if err != nil { 166 result.Response = resp 167 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Delete", resp, "Failure sending request") 168 return 169 } 170 171 result, err = client.DeleteResponder(resp) 172 if err != nil { 173 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Delete", resp, "Failure responding to request") 174 } 175 176 return 177} 178 179// DeletePreparer prepares the Delete request. 180func (client WatcherClient) DeletePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string) (*http.Request, error) { 181 pathParameters := map[string]interface{}{ 182 "automationAccountName": autorest.Encode("path", automationAccountName), 183 "resourceGroupName": autorest.Encode("path", resourceGroupName), 184 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 185 "watcherName": autorest.Encode("path", watcherName), 186 } 187 188 const APIVersion = "2015-10-31" 189 queryParameters := map[string]interface{}{ 190 "api-version": APIVersion, 191 } 192 193 preparer := autorest.CreatePreparer( 194 autorest.AsDelete(), 195 autorest.WithBaseURL(client.BaseURI), 196 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/watchers/{watcherName}", pathParameters), 197 autorest.WithQueryParameters(queryParameters)) 198 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 199} 200 201// DeleteSender sends the Delete request. The method will close the 202// http.Response Body if it receives an error. 203func (client WatcherClient) DeleteSender(req *http.Request) (*http.Response, error) { 204 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 205} 206 207// DeleteResponder handles the response to the Delete request. The method always 208// closes the http.Response Body. 209func (client WatcherClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 210 err = autorest.Respond( 211 resp, 212 client.ByInspecting(), 213 azure.WithErrorUnlessStatusCode(http.StatusOK), 214 autorest.ByClosing()) 215 result.Response = resp 216 return 217} 218 219// Get retrieve the watcher identified by watcher name. 220// Parameters: 221// resourceGroupName - name of an Azure Resource group. 222// automationAccountName - the name of the automation account. 223// watcherName - the watcher name. 224func (client WatcherClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string) (result Watcher, err error) { 225 if tracing.IsEnabled() { 226 ctx = tracing.StartSpan(ctx, fqdn+"/WatcherClient.Get") 227 defer func() { 228 sc := -1 229 if result.Response.Response != nil { 230 sc = result.Response.Response.StatusCode 231 } 232 tracing.EndSpan(ctx, sc, err) 233 }() 234 } 235 if err := validation.Validate([]validation.Validation{ 236 {TargetValue: resourceGroupName, 237 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 238 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 239 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 240 return result, validation.NewError("automation.WatcherClient", "Get", err.Error()) 241 } 242 243 req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, watcherName) 244 if err != nil { 245 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Get", nil, "Failure preparing request") 246 return 247 } 248 249 resp, err := client.GetSender(req) 250 if err != nil { 251 result.Response = autorest.Response{Response: resp} 252 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Get", resp, "Failure sending request") 253 return 254 } 255 256 result, err = client.GetResponder(resp) 257 if err != nil { 258 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Get", resp, "Failure responding to request") 259 } 260 261 return 262} 263 264// GetPreparer prepares the Get request. 265func (client WatcherClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string) (*http.Request, error) { 266 pathParameters := map[string]interface{}{ 267 "automationAccountName": autorest.Encode("path", automationAccountName), 268 "resourceGroupName": autorest.Encode("path", resourceGroupName), 269 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 270 "watcherName": autorest.Encode("path", watcherName), 271 } 272 273 const APIVersion = "2015-10-31" 274 queryParameters := map[string]interface{}{ 275 "api-version": APIVersion, 276 } 277 278 preparer := autorest.CreatePreparer( 279 autorest.AsGet(), 280 autorest.WithBaseURL(client.BaseURI), 281 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/watchers/{watcherName}", pathParameters), 282 autorest.WithQueryParameters(queryParameters)) 283 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 284} 285 286// GetSender sends the Get request. The method will close the 287// http.Response Body if it receives an error. 288func (client WatcherClient) GetSender(req *http.Request) (*http.Response, error) { 289 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 290} 291 292// GetResponder handles the response to the Get request. The method always 293// closes the http.Response Body. 294func (client WatcherClient) GetResponder(resp *http.Response) (result Watcher, err error) { 295 err = autorest.Respond( 296 resp, 297 client.ByInspecting(), 298 azure.WithErrorUnlessStatusCode(http.StatusOK), 299 autorest.ByUnmarshallingJSON(&result), 300 autorest.ByClosing()) 301 result.Response = autorest.Response{Response: resp} 302 return 303} 304 305// ListByAutomationAccount retrieve a list of watchers. 306// Parameters: 307// resourceGroupName - name of an Azure Resource group. 308// automationAccountName - the name of the automation account. 309// filter - the filter to apply on the operation. 310func (client WatcherClient) ListByAutomationAccount(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (result WatcherListResultPage, err error) { 311 if tracing.IsEnabled() { 312 ctx = tracing.StartSpan(ctx, fqdn+"/WatcherClient.ListByAutomationAccount") 313 defer func() { 314 sc := -1 315 if result.wlr.Response.Response != nil { 316 sc = result.wlr.Response.Response.StatusCode 317 } 318 tracing.EndSpan(ctx, sc, err) 319 }() 320 } 321 if err := validation.Validate([]validation.Validation{ 322 {TargetValue: resourceGroupName, 323 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 324 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 325 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 326 return result, validation.NewError("automation.WatcherClient", "ListByAutomationAccount", err.Error()) 327 } 328 329 result.fn = client.listByAutomationAccountNextResults 330 req, err := client.ListByAutomationAccountPreparer(ctx, resourceGroupName, automationAccountName, filter) 331 if err != nil { 332 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "ListByAutomationAccount", nil, "Failure preparing request") 333 return 334 } 335 336 resp, err := client.ListByAutomationAccountSender(req) 337 if err != nil { 338 result.wlr.Response = autorest.Response{Response: resp} 339 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "ListByAutomationAccount", resp, "Failure sending request") 340 return 341 } 342 343 result.wlr, err = client.ListByAutomationAccountResponder(resp) 344 if err != nil { 345 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "ListByAutomationAccount", resp, "Failure responding to request") 346 } 347 348 return 349} 350 351// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request. 352func (client WatcherClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (*http.Request, error) { 353 pathParameters := map[string]interface{}{ 354 "automationAccountName": autorest.Encode("path", automationAccountName), 355 "resourceGroupName": autorest.Encode("path", resourceGroupName), 356 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 357 } 358 359 const APIVersion = "2015-10-31" 360 queryParameters := map[string]interface{}{ 361 "api-version": APIVersion, 362 } 363 if len(filter) > 0 { 364 queryParameters["$filter"] = autorest.Encode("query", filter) 365 } 366 367 preparer := autorest.CreatePreparer( 368 autorest.AsGet(), 369 autorest.WithBaseURL(client.BaseURI), 370 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/watchers", pathParameters), 371 autorest.WithQueryParameters(queryParameters)) 372 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 373} 374 375// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the 376// http.Response Body if it receives an error. 377func (client WatcherClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) { 378 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 379} 380 381// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always 382// closes the http.Response Body. 383func (client WatcherClient) ListByAutomationAccountResponder(resp *http.Response) (result WatcherListResult, err error) { 384 err = autorest.Respond( 385 resp, 386 client.ByInspecting(), 387 azure.WithErrorUnlessStatusCode(http.StatusOK), 388 autorest.ByUnmarshallingJSON(&result), 389 autorest.ByClosing()) 390 result.Response = autorest.Response{Response: resp} 391 return 392} 393 394// listByAutomationAccountNextResults retrieves the next set of results, if any. 395func (client WatcherClient) listByAutomationAccountNextResults(ctx context.Context, lastResults WatcherListResult) (result WatcherListResult, err error) { 396 req, err := lastResults.watcherListResultPreparer(ctx) 397 if err != nil { 398 return result, autorest.NewErrorWithError(err, "automation.WatcherClient", "listByAutomationAccountNextResults", nil, "Failure preparing next results request") 399 } 400 if req == nil { 401 return 402 } 403 resp, err := client.ListByAutomationAccountSender(req) 404 if err != nil { 405 result.Response = autorest.Response{Response: resp} 406 return result, autorest.NewErrorWithError(err, "automation.WatcherClient", "listByAutomationAccountNextResults", resp, "Failure sending next results request") 407 } 408 result, err = client.ListByAutomationAccountResponder(resp) 409 if err != nil { 410 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "listByAutomationAccountNextResults", resp, "Failure responding to next results request") 411 } 412 return 413} 414 415// ListByAutomationAccountComplete enumerates all values, automatically crossing page boundaries as required. 416func (client WatcherClient) ListByAutomationAccountComplete(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (result WatcherListResultIterator, err error) { 417 if tracing.IsEnabled() { 418 ctx = tracing.StartSpan(ctx, fqdn+"/WatcherClient.ListByAutomationAccount") 419 defer func() { 420 sc := -1 421 if result.Response().Response.Response != nil { 422 sc = result.page.Response().Response.Response.StatusCode 423 } 424 tracing.EndSpan(ctx, sc, err) 425 }() 426 } 427 result.page, err = client.ListByAutomationAccount(ctx, resourceGroupName, automationAccountName, filter) 428 return 429} 430 431// Start resume the watcher identified by watcher name. 432// Parameters: 433// resourceGroupName - name of an Azure Resource group. 434// automationAccountName - the name of the automation account. 435// watcherName - the watcher name. 436func (client WatcherClient) Start(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string) (result autorest.Response, err error) { 437 if tracing.IsEnabled() { 438 ctx = tracing.StartSpan(ctx, fqdn+"/WatcherClient.Start") 439 defer func() { 440 sc := -1 441 if result.Response != nil { 442 sc = result.Response.StatusCode 443 } 444 tracing.EndSpan(ctx, sc, err) 445 }() 446 } 447 if err := validation.Validate([]validation.Validation{ 448 {TargetValue: resourceGroupName, 449 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 450 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 451 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 452 return result, validation.NewError("automation.WatcherClient", "Start", err.Error()) 453 } 454 455 req, err := client.StartPreparer(ctx, resourceGroupName, automationAccountName, watcherName) 456 if err != nil { 457 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Start", nil, "Failure preparing request") 458 return 459 } 460 461 resp, err := client.StartSender(req) 462 if err != nil { 463 result.Response = resp 464 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Start", resp, "Failure sending request") 465 return 466 } 467 468 result, err = client.StartResponder(resp) 469 if err != nil { 470 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Start", resp, "Failure responding to request") 471 } 472 473 return 474} 475 476// StartPreparer prepares the Start request. 477func (client WatcherClient) StartPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string) (*http.Request, error) { 478 pathParameters := map[string]interface{}{ 479 "automationAccountName": autorest.Encode("path", automationAccountName), 480 "resourceGroupName": autorest.Encode("path", resourceGroupName), 481 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 482 "watcherName": autorest.Encode("path", watcherName), 483 } 484 485 const APIVersion = "2015-10-31" 486 queryParameters := map[string]interface{}{ 487 "api-version": APIVersion, 488 } 489 490 preparer := autorest.CreatePreparer( 491 autorest.AsPost(), 492 autorest.WithBaseURL(client.BaseURI), 493 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/watchers/{watcherName}/start", pathParameters), 494 autorest.WithQueryParameters(queryParameters)) 495 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 496} 497 498// StartSender sends the Start request. The method will close the 499// http.Response Body if it receives an error. 500func (client WatcherClient) StartSender(req *http.Request) (*http.Response, error) { 501 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 502} 503 504// StartResponder handles the response to the Start request. The method always 505// closes the http.Response Body. 506func (client WatcherClient) StartResponder(resp *http.Response) (result autorest.Response, err error) { 507 err = autorest.Respond( 508 resp, 509 client.ByInspecting(), 510 azure.WithErrorUnlessStatusCode(http.StatusOK), 511 autorest.ByClosing()) 512 result.Response = resp 513 return 514} 515 516// Stop resume the watcher identified by watcher name. 517// Parameters: 518// resourceGroupName - name of an Azure Resource group. 519// automationAccountName - the name of the automation account. 520// watcherName - the watcher name. 521func (client WatcherClient) Stop(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string) (result autorest.Response, err error) { 522 if tracing.IsEnabled() { 523 ctx = tracing.StartSpan(ctx, fqdn+"/WatcherClient.Stop") 524 defer func() { 525 sc := -1 526 if result.Response != nil { 527 sc = result.Response.StatusCode 528 } 529 tracing.EndSpan(ctx, sc, err) 530 }() 531 } 532 if err := validation.Validate([]validation.Validation{ 533 {TargetValue: resourceGroupName, 534 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 535 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 536 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 537 return result, validation.NewError("automation.WatcherClient", "Stop", err.Error()) 538 } 539 540 req, err := client.StopPreparer(ctx, resourceGroupName, automationAccountName, watcherName) 541 if err != nil { 542 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Stop", nil, "Failure preparing request") 543 return 544 } 545 546 resp, err := client.StopSender(req) 547 if err != nil { 548 result.Response = resp 549 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Stop", resp, "Failure sending request") 550 return 551 } 552 553 result, err = client.StopResponder(resp) 554 if err != nil { 555 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Stop", resp, "Failure responding to request") 556 } 557 558 return 559} 560 561// StopPreparer prepares the Stop request. 562func (client WatcherClient) StopPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string) (*http.Request, error) { 563 pathParameters := map[string]interface{}{ 564 "automationAccountName": autorest.Encode("path", automationAccountName), 565 "resourceGroupName": autorest.Encode("path", resourceGroupName), 566 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 567 "watcherName": autorest.Encode("path", watcherName), 568 } 569 570 const APIVersion = "2015-10-31" 571 queryParameters := map[string]interface{}{ 572 "api-version": APIVersion, 573 } 574 575 preparer := autorest.CreatePreparer( 576 autorest.AsPost(), 577 autorest.WithBaseURL(client.BaseURI), 578 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/watchers/{watcherName}/stop", pathParameters), 579 autorest.WithQueryParameters(queryParameters)) 580 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 581} 582 583// StopSender sends the Stop request. The method will close the 584// http.Response Body if it receives an error. 585func (client WatcherClient) StopSender(req *http.Request) (*http.Response, error) { 586 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 587} 588 589// StopResponder handles the response to the Stop request. The method always 590// closes the http.Response Body. 591func (client WatcherClient) StopResponder(resp *http.Response) (result autorest.Response, err error) { 592 err = autorest.Respond( 593 resp, 594 client.ByInspecting(), 595 azure.WithErrorUnlessStatusCode(http.StatusOK), 596 autorest.ByClosing()) 597 result.Response = resp 598 return 599} 600 601// Update update the watcher identified by watcher name. 602// Parameters: 603// resourceGroupName - name of an Azure Resource group. 604// automationAccountName - the name of the automation account. 605// watcherName - the watcher name. 606// parameters - the update parameters for watcher. 607func (client WatcherClient) Update(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string, parameters WatcherUpdateParameters) (result Watcher, err error) { 608 if tracing.IsEnabled() { 609 ctx = tracing.StartSpan(ctx, fqdn+"/WatcherClient.Update") 610 defer func() { 611 sc := -1 612 if result.Response.Response != nil { 613 sc = result.Response.Response.StatusCode 614 } 615 tracing.EndSpan(ctx, sc, err) 616 }() 617 } 618 if err := validation.Validate([]validation.Validation{ 619 {TargetValue: resourceGroupName, 620 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 621 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 622 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 623 return result, validation.NewError("automation.WatcherClient", "Update", err.Error()) 624 } 625 626 req, err := client.UpdatePreparer(ctx, resourceGroupName, automationAccountName, watcherName, parameters) 627 if err != nil { 628 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Update", nil, "Failure preparing request") 629 return 630 } 631 632 resp, err := client.UpdateSender(req) 633 if err != nil { 634 result.Response = autorest.Response{Response: resp} 635 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Update", resp, "Failure sending request") 636 return 637 } 638 639 result, err = client.UpdateResponder(resp) 640 if err != nil { 641 err = autorest.NewErrorWithError(err, "automation.WatcherClient", "Update", resp, "Failure responding to request") 642 } 643 644 return 645} 646 647// UpdatePreparer prepares the Update request. 648func (client WatcherClient) UpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, watcherName string, parameters WatcherUpdateParameters) (*http.Request, error) { 649 pathParameters := map[string]interface{}{ 650 "automationAccountName": autorest.Encode("path", automationAccountName), 651 "resourceGroupName": autorest.Encode("path", resourceGroupName), 652 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 653 "watcherName": autorest.Encode("path", watcherName), 654 } 655 656 const APIVersion = "2015-10-31" 657 queryParameters := map[string]interface{}{ 658 "api-version": APIVersion, 659 } 660 661 preparer := autorest.CreatePreparer( 662 autorest.AsContentType("application/json; charset=utf-8"), 663 autorest.AsPatch(), 664 autorest.WithBaseURL(client.BaseURI), 665 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/watchers/{watcherName}", pathParameters), 666 autorest.WithJSON(parameters), 667 autorest.WithQueryParameters(queryParameters)) 668 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 669} 670 671// UpdateSender sends the Update request. The method will close the 672// http.Response Body if it receives an error. 673func (client WatcherClient) UpdateSender(req *http.Request) (*http.Response, error) { 674 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 675} 676 677// UpdateResponder handles the response to the Update request. The method always 678// closes the http.Response Body. 679func (client WatcherClient) UpdateResponder(resp *http.Response) (result Watcher, err error) { 680 err = autorest.Respond( 681 resp, 682 client.ByInspecting(), 683 azure.WithErrorUnlessStatusCode(http.StatusOK), 684 autorest.ByUnmarshallingJSON(&result), 685 autorest.ByClosing()) 686 result.Response = autorest.Response{Response: resp} 687 return 688} 689