1package automation 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// ConnectionClient is the automation Client 19type ConnectionClient struct { 20 BaseClient 21} 22 23// NewConnectionClient creates an instance of the ConnectionClient client. 24func NewConnectionClient(subscriptionID string) ConnectionClient { 25 return NewConnectionClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewConnectionClientWithBaseURI creates an instance of the ConnectionClient 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 NewConnectionClientWithBaseURI(baseURI string, subscriptionID string) ConnectionClient { 31 return ConnectionClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate create or update a connection. 35// Parameters: 36// resourceGroupName - name of an Azure Resource group. 37// automationAccountName - the name of the automation account. 38// connectionName - the parameters supplied to the create or update connection operation. 39// parameters - the parameters supplied to the create or update connection operation. 40func (client ConnectionClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, automationAccountName string, connectionName string, parameters ConnectionCreateOrUpdateParameters) (result Connection, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionClient.CreateOrUpdate") 43 defer func() { 44 sc := -1 45 if result.Response.Response != nil { 46 sc = result.Response.Response.StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 if err := validation.Validate([]validation.Validation{ 52 {TargetValue: resourceGroupName, 53 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 54 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 55 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}, 56 {TargetValue: parameters, 57 Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil}, 58 {Target: "parameters.ConnectionCreateOrUpdateProperties", Name: validation.Null, Rule: true, 59 Chain: []validation.Constraint{{Target: "parameters.ConnectionCreateOrUpdateProperties.ConnectionType", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 60 return result, validation.NewError("automation.ConnectionClient", "CreateOrUpdate", err.Error()) 61 } 62 63 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, automationAccountName, connectionName, parameters) 64 if err != nil { 65 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "CreateOrUpdate", nil, "Failure preparing request") 66 return 67 } 68 69 resp, err := client.CreateOrUpdateSender(req) 70 if err != nil { 71 result.Response = autorest.Response{Response: resp} 72 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "CreateOrUpdate", resp, "Failure sending request") 73 return 74 } 75 76 result, err = client.CreateOrUpdateResponder(resp) 77 if err != nil { 78 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "CreateOrUpdate", resp, "Failure responding to request") 79 return 80 } 81 82 return 83} 84 85// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 86func (client ConnectionClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, connectionName string, parameters ConnectionCreateOrUpdateParameters) (*http.Request, error) { 87 pathParameters := map[string]interface{}{ 88 "automationAccountName": autorest.Encode("path", automationAccountName), 89 "connectionName": autorest.Encode("path", connectionName), 90 "resourceGroupName": autorest.Encode("path", resourceGroupName), 91 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 92 } 93 94 const APIVersion = "2019-06-01" 95 queryParameters := map[string]interface{}{ 96 "api-version": APIVersion, 97 } 98 99 preparer := autorest.CreatePreparer( 100 autorest.AsContentType("application/json; charset=utf-8"), 101 autorest.AsPut(), 102 autorest.WithBaseURL(client.BaseURI), 103 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/connections/{connectionName}", pathParameters), 104 autorest.WithJSON(parameters), 105 autorest.WithQueryParameters(queryParameters)) 106 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 107} 108 109// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 110// http.Response Body if it receives an error. 111func (client ConnectionClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 112 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 113} 114 115// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 116// closes the http.Response Body. 117func (client ConnectionClient) CreateOrUpdateResponder(resp *http.Response) (result Connection, err error) { 118 err = autorest.Respond( 119 resp, 120 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// Delete delete the connection. 128// Parameters: 129// resourceGroupName - name of an Azure Resource group. 130// automationAccountName - the name of the automation account. 131// connectionName - the name of connection. 132func (client ConnectionClient) Delete(ctx context.Context, resourceGroupName string, automationAccountName string, connectionName string) (result autorest.Response, err error) { 133 if tracing.IsEnabled() { 134 ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionClient.Delete") 135 defer func() { 136 sc := -1 137 if result.Response != nil { 138 sc = result.Response.StatusCode 139 } 140 tracing.EndSpan(ctx, sc, err) 141 }() 142 } 143 if err := validation.Validate([]validation.Validation{ 144 {TargetValue: resourceGroupName, 145 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 146 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 147 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 148 return result, validation.NewError("automation.ConnectionClient", "Delete", err.Error()) 149 } 150 151 req, err := client.DeletePreparer(ctx, resourceGroupName, automationAccountName, connectionName) 152 if err != nil { 153 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "Delete", nil, "Failure preparing request") 154 return 155 } 156 157 resp, err := client.DeleteSender(req) 158 if err != nil { 159 result.Response = resp 160 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "Delete", resp, "Failure sending request") 161 return 162 } 163 164 result, err = client.DeleteResponder(resp) 165 if err != nil { 166 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "Delete", resp, "Failure responding to request") 167 return 168 } 169 170 return 171} 172 173// DeletePreparer prepares the Delete request. 174func (client ConnectionClient) DeletePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, connectionName string) (*http.Request, error) { 175 pathParameters := map[string]interface{}{ 176 "automationAccountName": autorest.Encode("path", automationAccountName), 177 "connectionName": autorest.Encode("path", connectionName), 178 "resourceGroupName": autorest.Encode("path", resourceGroupName), 179 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 180 } 181 182 const APIVersion = "2019-06-01" 183 queryParameters := map[string]interface{}{ 184 "api-version": APIVersion, 185 } 186 187 preparer := autorest.CreatePreparer( 188 autorest.AsDelete(), 189 autorest.WithBaseURL(client.BaseURI), 190 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/connections/{connectionName}", pathParameters), 191 autorest.WithQueryParameters(queryParameters)) 192 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 193} 194 195// DeleteSender sends the Delete request. The method will close the 196// http.Response Body if it receives an error. 197func (client ConnectionClient) DeleteSender(req *http.Request) (*http.Response, error) { 198 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 199} 200 201// DeleteResponder handles the response to the Delete request. The method always 202// closes the http.Response Body. 203func (client ConnectionClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 204 err = autorest.Respond( 205 resp, 206 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 207 autorest.ByClosing()) 208 result.Response = resp 209 return 210} 211 212// Get retrieve the connection identified by connection name. 213// Parameters: 214// resourceGroupName - name of an Azure Resource group. 215// automationAccountName - the name of the automation account. 216// connectionName - the name of connection. 217func (client ConnectionClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, connectionName string) (result Connection, err error) { 218 if tracing.IsEnabled() { 219 ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionClient.Get") 220 defer func() { 221 sc := -1 222 if result.Response.Response != nil { 223 sc = result.Response.Response.StatusCode 224 } 225 tracing.EndSpan(ctx, sc, err) 226 }() 227 } 228 if err := validation.Validate([]validation.Validation{ 229 {TargetValue: resourceGroupName, 230 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 231 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 232 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 233 return result, validation.NewError("automation.ConnectionClient", "Get", err.Error()) 234 } 235 236 req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, connectionName) 237 if err != nil { 238 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "Get", nil, "Failure preparing request") 239 return 240 } 241 242 resp, err := client.GetSender(req) 243 if err != nil { 244 result.Response = autorest.Response{Response: resp} 245 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "Get", resp, "Failure sending request") 246 return 247 } 248 249 result, err = client.GetResponder(resp) 250 if err != nil { 251 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "Get", resp, "Failure responding to request") 252 return 253 } 254 255 return 256} 257 258// GetPreparer prepares the Get request. 259func (client ConnectionClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, connectionName string) (*http.Request, error) { 260 pathParameters := map[string]interface{}{ 261 "automationAccountName": autorest.Encode("path", automationAccountName), 262 "connectionName": autorest.Encode("path", connectionName), 263 "resourceGroupName": autorest.Encode("path", resourceGroupName), 264 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 265 } 266 267 const APIVersion = "2019-06-01" 268 queryParameters := map[string]interface{}{ 269 "api-version": APIVersion, 270 } 271 272 preparer := autorest.CreatePreparer( 273 autorest.AsGet(), 274 autorest.WithBaseURL(client.BaseURI), 275 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/connections/{connectionName}", pathParameters), 276 autorest.WithQueryParameters(queryParameters)) 277 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 278} 279 280// GetSender sends the Get request. The method will close the 281// http.Response Body if it receives an error. 282func (client ConnectionClient) GetSender(req *http.Request) (*http.Response, error) { 283 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 284} 285 286// GetResponder handles the response to the Get request. The method always 287// closes the http.Response Body. 288func (client ConnectionClient) GetResponder(resp *http.Response) (result Connection, err error) { 289 err = autorest.Respond( 290 resp, 291 azure.WithErrorUnlessStatusCode(http.StatusOK), 292 autorest.ByUnmarshallingJSON(&result), 293 autorest.ByClosing()) 294 result.Response = autorest.Response{Response: resp} 295 return 296} 297 298// ListByAutomationAccount retrieve a list of connections. 299// Parameters: 300// resourceGroupName - name of an Azure Resource group. 301// automationAccountName - the name of the automation account. 302func (client ConnectionClient) ListByAutomationAccount(ctx context.Context, resourceGroupName string, automationAccountName string) (result ConnectionListResultPage, err error) { 303 if tracing.IsEnabled() { 304 ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionClient.ListByAutomationAccount") 305 defer func() { 306 sc := -1 307 if result.clr.Response.Response != nil { 308 sc = result.clr.Response.Response.StatusCode 309 } 310 tracing.EndSpan(ctx, sc, err) 311 }() 312 } 313 if err := validation.Validate([]validation.Validation{ 314 {TargetValue: resourceGroupName, 315 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 316 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 317 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 318 return result, validation.NewError("automation.ConnectionClient", "ListByAutomationAccount", err.Error()) 319 } 320 321 result.fn = client.listByAutomationAccountNextResults 322 req, err := client.ListByAutomationAccountPreparer(ctx, resourceGroupName, automationAccountName) 323 if err != nil { 324 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "ListByAutomationAccount", nil, "Failure preparing request") 325 return 326 } 327 328 resp, err := client.ListByAutomationAccountSender(req) 329 if err != nil { 330 result.clr.Response = autorest.Response{Response: resp} 331 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "ListByAutomationAccount", resp, "Failure sending request") 332 return 333 } 334 335 result.clr, err = client.ListByAutomationAccountResponder(resp) 336 if err != nil { 337 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "ListByAutomationAccount", resp, "Failure responding to request") 338 return 339 } 340 if result.clr.hasNextLink() && result.clr.IsEmpty() { 341 err = result.NextWithContext(ctx) 342 return 343 } 344 345 return 346} 347 348// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request. 349func (client ConnectionClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string) (*http.Request, error) { 350 pathParameters := map[string]interface{}{ 351 "automationAccountName": autorest.Encode("path", automationAccountName), 352 "resourceGroupName": autorest.Encode("path", resourceGroupName), 353 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 354 } 355 356 const APIVersion = "2019-06-01" 357 queryParameters := map[string]interface{}{ 358 "api-version": APIVersion, 359 } 360 361 preparer := autorest.CreatePreparer( 362 autorest.AsGet(), 363 autorest.WithBaseURL(client.BaseURI), 364 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/connections", pathParameters), 365 autorest.WithQueryParameters(queryParameters)) 366 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 367} 368 369// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the 370// http.Response Body if it receives an error. 371func (client ConnectionClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) { 372 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 373} 374 375// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always 376// closes the http.Response Body. 377func (client ConnectionClient) ListByAutomationAccountResponder(resp *http.Response) (result ConnectionListResult, err error) { 378 err = autorest.Respond( 379 resp, 380 azure.WithErrorUnlessStatusCode(http.StatusOK), 381 autorest.ByUnmarshallingJSON(&result), 382 autorest.ByClosing()) 383 result.Response = autorest.Response{Response: resp} 384 return 385} 386 387// listByAutomationAccountNextResults retrieves the next set of results, if any. 388func (client ConnectionClient) listByAutomationAccountNextResults(ctx context.Context, lastResults ConnectionListResult) (result ConnectionListResult, err error) { 389 req, err := lastResults.connectionListResultPreparer(ctx) 390 if err != nil { 391 return result, autorest.NewErrorWithError(err, "automation.ConnectionClient", "listByAutomationAccountNextResults", nil, "Failure preparing next results request") 392 } 393 if req == nil { 394 return 395 } 396 resp, err := client.ListByAutomationAccountSender(req) 397 if err != nil { 398 result.Response = autorest.Response{Response: resp} 399 return result, autorest.NewErrorWithError(err, "automation.ConnectionClient", "listByAutomationAccountNextResults", resp, "Failure sending next results request") 400 } 401 result, err = client.ListByAutomationAccountResponder(resp) 402 if err != nil { 403 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "listByAutomationAccountNextResults", resp, "Failure responding to next results request") 404 } 405 return 406} 407 408// ListByAutomationAccountComplete enumerates all values, automatically crossing page boundaries as required. 409func (client ConnectionClient) ListByAutomationAccountComplete(ctx context.Context, resourceGroupName string, automationAccountName string) (result ConnectionListResultIterator, err error) { 410 if tracing.IsEnabled() { 411 ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionClient.ListByAutomationAccount") 412 defer func() { 413 sc := -1 414 if result.Response().Response.Response != nil { 415 sc = result.page.Response().Response.Response.StatusCode 416 } 417 tracing.EndSpan(ctx, sc, err) 418 }() 419 } 420 result.page, err = client.ListByAutomationAccount(ctx, resourceGroupName, automationAccountName) 421 return 422} 423 424// Update update a connection. 425// Parameters: 426// resourceGroupName - name of an Azure Resource group. 427// automationAccountName - the name of the automation account. 428// connectionName - the parameters supplied to the update a connection operation. 429// parameters - the parameters supplied to the update a connection operation. 430func (client ConnectionClient) Update(ctx context.Context, resourceGroupName string, automationAccountName string, connectionName string, parameters ConnectionUpdateParameters) (result Connection, err error) { 431 if tracing.IsEnabled() { 432 ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionClient.Update") 433 defer func() { 434 sc := -1 435 if result.Response.Response != nil { 436 sc = result.Response.Response.StatusCode 437 } 438 tracing.EndSpan(ctx, sc, err) 439 }() 440 } 441 if err := validation.Validate([]validation.Validation{ 442 {TargetValue: resourceGroupName, 443 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 444 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 445 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 446 return result, validation.NewError("automation.ConnectionClient", "Update", err.Error()) 447 } 448 449 req, err := client.UpdatePreparer(ctx, resourceGroupName, automationAccountName, connectionName, parameters) 450 if err != nil { 451 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "Update", nil, "Failure preparing request") 452 return 453 } 454 455 resp, err := client.UpdateSender(req) 456 if err != nil { 457 result.Response = autorest.Response{Response: resp} 458 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "Update", resp, "Failure sending request") 459 return 460 } 461 462 result, err = client.UpdateResponder(resp) 463 if err != nil { 464 err = autorest.NewErrorWithError(err, "automation.ConnectionClient", "Update", resp, "Failure responding to request") 465 return 466 } 467 468 return 469} 470 471// UpdatePreparer prepares the Update request. 472func (client ConnectionClient) UpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, connectionName string, parameters ConnectionUpdateParameters) (*http.Request, error) { 473 pathParameters := map[string]interface{}{ 474 "automationAccountName": autorest.Encode("path", automationAccountName), 475 "connectionName": autorest.Encode("path", connectionName), 476 "resourceGroupName": autorest.Encode("path", resourceGroupName), 477 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 478 } 479 480 const APIVersion = "2019-06-01" 481 queryParameters := map[string]interface{}{ 482 "api-version": APIVersion, 483 } 484 485 preparer := autorest.CreatePreparer( 486 autorest.AsContentType("application/json; charset=utf-8"), 487 autorest.AsPatch(), 488 autorest.WithBaseURL(client.BaseURI), 489 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/connections/{connectionName}", pathParameters), 490 autorest.WithJSON(parameters), 491 autorest.WithQueryParameters(queryParameters)) 492 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 493} 494 495// UpdateSender sends the Update request. The method will close the 496// http.Response Body if it receives an error. 497func (client ConnectionClient) UpdateSender(req *http.Request) (*http.Response, error) { 498 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 499} 500 501// UpdateResponder handles the response to the Update request. The method always 502// closes the http.Response Body. 503func (client ConnectionClient) UpdateResponder(resp *http.Response) (result Connection, err error) { 504 err = autorest.Respond( 505 resp, 506 azure.WithErrorUnlessStatusCode(http.StatusOK), 507 autorest.ByUnmarshallingJSON(&result), 508 autorest.ByClosing()) 509 result.Response = autorest.Response{Response: resp} 510 return 511} 512