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