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