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// ConnectionTypeClient is the automation Client 29type ConnectionTypeClient struct { 30 BaseClient 31} 32 33// NewConnectionTypeClient creates an instance of the ConnectionTypeClient client. 34func NewConnectionTypeClient(subscriptionID string, countType1 CountType) ConnectionTypeClient { 35 return NewConnectionTypeClientWithBaseURI(DefaultBaseURI, subscriptionID, countType1) 36} 37 38// NewConnectionTypeClientWithBaseURI creates an instance of the ConnectionTypeClient client. 39func NewConnectionTypeClientWithBaseURI(baseURI string, subscriptionID string, countType1 CountType) ConnectionTypeClient { 40 return ConnectionTypeClient{NewWithBaseURI(baseURI, subscriptionID, countType1)} 41} 42 43// CreateOrUpdate create a connectiontype. 44// Parameters: 45// resourceGroupName - name of an Azure Resource group. 46// automationAccountName - the name of the automation account. 47// connectionTypeName - the parameters supplied to the create or update connectiontype operation. 48// parameters - the parameters supplied to the create or update connectiontype operation. 49func (client ConnectionTypeClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string, parameters ConnectionTypeCreateOrUpdateParameters) (result ConnectionType, 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.ConnectionTypeCreateOrUpdateProperties", Name: validation.Null, Rule: true, 58 Chain: []validation.Constraint{{Target: "parameters.ConnectionTypeCreateOrUpdateProperties.FieldDefinitions", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 59 return result, validation.NewError("automation.ConnectionTypeClient", "CreateOrUpdate", err.Error()) 60 } 61 62 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, automationAccountName, connectionTypeName, parameters) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "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.ConnectionTypeClient", "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.ConnectionTypeClient", "CreateOrUpdate", resp, "Failure responding to request") 78 } 79 80 return 81} 82 83// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 84func (client ConnectionTypeClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string, parameters ConnectionTypeCreateOrUpdateParameters) (*http.Request, error) { 85 pathParameters := map[string]interface{}{ 86 "automationAccountName": autorest.Encode("path", automationAccountName), 87 "connectionTypeName": autorest.Encode("path", connectionTypeName), 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}/connectionTypes/{connectionTypeName}", 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 ConnectionTypeClient) 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 ConnectionTypeClient) CreateOrUpdateResponder(resp *http.Response) (result ConnectionType, err error) { 117 err = autorest.Respond( 118 resp, 119 client.ByInspecting(), 120 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusConflict), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// Delete delete the connectiontype. 128// Parameters: 129// resourceGroupName - name of an Azure Resource group. 130// automationAccountName - the name of the automation account. 131// connectionTypeName - the name of connectiontype. 132func (client ConnectionTypeClient) Delete(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string) (result autorest.Response, 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.ConnectionTypeClient", "Delete", err.Error()) 139 } 140 141 req, err := client.DeletePreparer(ctx, resourceGroupName, automationAccountName, connectionTypeName) 142 if err != nil { 143 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "Delete", nil, "Failure preparing request") 144 return 145 } 146 147 resp, err := client.DeleteSender(req) 148 if err != nil { 149 result.Response = resp 150 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "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.ConnectionTypeClient", "Delete", resp, "Failure responding to request") 157 } 158 159 return 160} 161 162// DeletePreparer prepares the Delete request. 163func (client ConnectionTypeClient) DeletePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string) (*http.Request, error) { 164 pathParameters := map[string]interface{}{ 165 "automationAccountName": autorest.Encode("path", automationAccountName), 166 "connectionTypeName": autorest.Encode("path", connectionTypeName), 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}/connectionTypes/{connectionTypeName}", 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 ConnectionTypeClient) 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 ConnectionTypeClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 194 err = autorest.Respond( 195 resp, 196 client.ByInspecting(), 197 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 198 autorest.ByClosing()) 199 result.Response = resp 200 return 201} 202 203// Get retrieve the connectiontype identified by connectiontype name. 204// Parameters: 205// resourceGroupName - name of an Azure Resource group. 206// automationAccountName - the name of the automation account. 207// connectionTypeName - the name of connectiontype. 208func (client ConnectionTypeClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string) (result ConnectionType, err error) { 209 if err := validation.Validate([]validation.Validation{ 210 {TargetValue: resourceGroupName, 211 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 212 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 213 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 214 return result, validation.NewError("automation.ConnectionTypeClient", "Get", err.Error()) 215 } 216 217 req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, connectionTypeName) 218 if err != nil { 219 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "Get", nil, "Failure preparing request") 220 return 221 } 222 223 resp, err := client.GetSender(req) 224 if err != nil { 225 result.Response = autorest.Response{Response: resp} 226 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "Get", resp, "Failure sending request") 227 return 228 } 229 230 result, err = client.GetResponder(resp) 231 if err != nil { 232 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "Get", resp, "Failure responding to request") 233 } 234 235 return 236} 237 238// GetPreparer prepares the Get request. 239func (client ConnectionTypeClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string) (*http.Request, error) { 240 pathParameters := map[string]interface{}{ 241 "automationAccountName": autorest.Encode("path", automationAccountName), 242 "connectionTypeName": autorest.Encode("path", connectionTypeName), 243 "resourceGroupName": autorest.Encode("path", resourceGroupName), 244 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 245 } 246 247 const APIVersion = "2015-10-31" 248 queryParameters := map[string]interface{}{ 249 "api-version": APIVersion, 250 } 251 252 preparer := autorest.CreatePreparer( 253 autorest.AsGet(), 254 autorest.WithBaseURL(client.BaseURI), 255 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/connectionTypes/{connectionTypeName}", pathParameters), 256 autorest.WithQueryParameters(queryParameters)) 257 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 258} 259 260// GetSender sends the Get request. The method will close the 261// http.Response Body if it receives an error. 262func (client ConnectionTypeClient) GetSender(req *http.Request) (*http.Response, error) { 263 return autorest.SendWithSender(client, req, 264 azure.DoRetryWithRegistration(client.Client)) 265} 266 267// GetResponder handles the response to the Get request. The method always 268// closes the http.Response Body. 269func (client ConnectionTypeClient) GetResponder(resp *http.Response) (result ConnectionType, err error) { 270 err = autorest.Respond( 271 resp, 272 client.ByInspecting(), 273 azure.WithErrorUnlessStatusCode(http.StatusOK), 274 autorest.ByUnmarshallingJSON(&result), 275 autorest.ByClosing()) 276 result.Response = autorest.Response{Response: resp} 277 return 278} 279 280// ListByAutomationAccount retrieve a list of connectiontypes. 281// Parameters: 282// resourceGroupName - name of an Azure Resource group. 283// automationAccountName - the name of the automation account. 284func (client ConnectionTypeClient) ListByAutomationAccount(ctx context.Context, resourceGroupName string, automationAccountName string) (result ConnectionTypeListResultPage, err error) { 285 if err := validation.Validate([]validation.Validation{ 286 {TargetValue: resourceGroupName, 287 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 288 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 289 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 290 return result, validation.NewError("automation.ConnectionTypeClient", "ListByAutomationAccount", err.Error()) 291 } 292 293 result.fn = client.listByAutomationAccountNextResults 294 req, err := client.ListByAutomationAccountPreparer(ctx, resourceGroupName, automationAccountName) 295 if err != nil { 296 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "ListByAutomationAccount", nil, "Failure preparing request") 297 return 298 } 299 300 resp, err := client.ListByAutomationAccountSender(req) 301 if err != nil { 302 result.ctlr.Response = autorest.Response{Response: resp} 303 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "ListByAutomationAccount", resp, "Failure sending request") 304 return 305 } 306 307 result.ctlr, err = client.ListByAutomationAccountResponder(resp) 308 if err != nil { 309 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "ListByAutomationAccount", resp, "Failure responding to request") 310 } 311 312 return 313} 314 315// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request. 316func (client ConnectionTypeClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string) (*http.Request, error) { 317 pathParameters := map[string]interface{}{ 318 "automationAccountName": autorest.Encode("path", automationAccountName), 319 "resourceGroupName": autorest.Encode("path", resourceGroupName), 320 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 321 } 322 323 const APIVersion = "2015-10-31" 324 queryParameters := map[string]interface{}{ 325 "api-version": APIVersion, 326 } 327 328 preparer := autorest.CreatePreparer( 329 autorest.AsGet(), 330 autorest.WithBaseURL(client.BaseURI), 331 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/connectionTypes", pathParameters), 332 autorest.WithQueryParameters(queryParameters)) 333 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 334} 335 336// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the 337// http.Response Body if it receives an error. 338func (client ConnectionTypeClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) { 339 return autorest.SendWithSender(client, req, 340 azure.DoRetryWithRegistration(client.Client)) 341} 342 343// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always 344// closes the http.Response Body. 345func (client ConnectionTypeClient) ListByAutomationAccountResponder(resp *http.Response) (result ConnectionTypeListResult, err error) { 346 err = autorest.Respond( 347 resp, 348 client.ByInspecting(), 349 azure.WithErrorUnlessStatusCode(http.StatusOK), 350 autorest.ByUnmarshallingJSON(&result), 351 autorest.ByClosing()) 352 result.Response = autorest.Response{Response: resp} 353 return 354} 355 356// listByAutomationAccountNextResults retrieves the next set of results, if any. 357func (client ConnectionTypeClient) listByAutomationAccountNextResults(lastResults ConnectionTypeListResult) (result ConnectionTypeListResult, err error) { 358 req, err := lastResults.connectionTypeListResultPreparer() 359 if err != nil { 360 return result, autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "listByAutomationAccountNextResults", nil, "Failure preparing next results request") 361 } 362 if req == nil { 363 return 364 } 365 resp, err := client.ListByAutomationAccountSender(req) 366 if err != nil { 367 result.Response = autorest.Response{Response: resp} 368 return result, autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "listByAutomationAccountNextResults", resp, "Failure sending next results request") 369 } 370 result, err = client.ListByAutomationAccountResponder(resp) 371 if err != nil { 372 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "listByAutomationAccountNextResults", resp, "Failure responding to next results request") 373 } 374 return 375} 376 377// ListByAutomationAccountComplete enumerates all values, automatically crossing page boundaries as required. 378func (client ConnectionTypeClient) ListByAutomationAccountComplete(ctx context.Context, resourceGroupName string, automationAccountName string) (result ConnectionTypeListResultIterator, err error) { 379 result.page, err = client.ListByAutomationAccount(ctx, resourceGroupName, automationAccountName) 380 return 381} 382