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) ConnectionTypeClient { 35 return NewConnectionTypeClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewConnectionTypeClientWithBaseURI creates an instance of the ConnectionTypeClient client. 39func NewConnectionTypeClientWithBaseURI(baseURI string, subscriptionID string) ConnectionTypeClient { 40 return ConnectionTypeClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// CreateOrUpdate create a connectiontype. 44// 45// resourceGroupName is the resource group name. automationAccountName is the automation account name. 46// connectionTypeName is the parameters supplied to the create or update connectiontype operation. parameters is 47// the parameters supplied to the create or update connectiontype operation. 48func (client ConnectionTypeClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string, parameters ConnectionTypeCreateOrUpdateParameters) (result ConnectionType, err error) { 49 if err := validation.Validate([]validation.Validation{ 50 {TargetValue: resourceGroupName, 51 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}, 52 {TargetValue: parameters, 53 Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil}, 54 {Target: "parameters.ConnectionTypeCreateOrUpdateProperties", Name: validation.Null, Rule: true, 55 Chain: []validation.Constraint{{Target: "parameters.ConnectionTypeCreateOrUpdateProperties.FieldDefinitions", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 56 return result, validation.NewError("automation.ConnectionTypeClient", "CreateOrUpdate", err.Error()) 57 } 58 59 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, automationAccountName, connectionTypeName, parameters) 60 if err != nil { 61 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "CreateOrUpdate", nil, "Failure preparing request") 62 return 63 } 64 65 resp, err := client.CreateOrUpdateSender(req) 66 if err != nil { 67 result.Response = autorest.Response{Response: resp} 68 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "CreateOrUpdate", resp, "Failure sending request") 69 return 70 } 71 72 result, err = client.CreateOrUpdateResponder(resp) 73 if err != nil { 74 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "CreateOrUpdate", resp, "Failure responding to request") 75 } 76 77 return 78} 79 80// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 81func (client ConnectionTypeClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string, parameters ConnectionTypeCreateOrUpdateParameters) (*http.Request, error) { 82 pathParameters := map[string]interface{}{ 83 "automationAccountName": autorest.Encode("path", automationAccountName), 84 "connectionTypeName": autorest.Encode("path", connectionTypeName), 85 "resourceGroupName": autorest.Encode("path", resourceGroupName), 86 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 87 } 88 89 const APIVersion = "2015-10-31" 90 queryParameters := map[string]interface{}{ 91 "api-version": APIVersion, 92 } 93 94 preparer := autorest.CreatePreparer( 95 autorest.AsContentType("application/json; charset=utf-8"), 96 autorest.AsPut(), 97 autorest.WithBaseURL(client.BaseURI), 98 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/connectionTypes/{connectionTypeName}", pathParameters), 99 autorest.WithJSON(parameters), 100 autorest.WithQueryParameters(queryParameters)) 101 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 102} 103 104// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 105// http.Response Body if it receives an error. 106func (client ConnectionTypeClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 107 return autorest.SendWithSender(client, req, 108 azure.DoRetryWithRegistration(client.Client)) 109} 110 111// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 112// closes the http.Response Body. 113func (client ConnectionTypeClient) CreateOrUpdateResponder(resp *http.Response) (result ConnectionType, err error) { 114 err = autorest.Respond( 115 resp, 116 client.ByInspecting(), 117 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusConflict), 118 autorest.ByUnmarshallingJSON(&result), 119 autorest.ByClosing()) 120 result.Response = autorest.Response{Response: resp} 121 return 122} 123 124// Delete delete the connectiontype. 125// 126// resourceGroupName is the resource group name. automationAccountName is the automation account name. 127// connectionTypeName is the name of connectiontype. 128func (client ConnectionTypeClient) Delete(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string) (result autorest.Response, err error) { 129 if err := validation.Validate([]validation.Validation{ 130 {TargetValue: resourceGroupName, 131 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 132 return result, validation.NewError("automation.ConnectionTypeClient", "Delete", err.Error()) 133 } 134 135 req, err := client.DeletePreparer(ctx, resourceGroupName, automationAccountName, connectionTypeName) 136 if err != nil { 137 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "Delete", nil, "Failure preparing request") 138 return 139 } 140 141 resp, err := client.DeleteSender(req) 142 if err != nil { 143 result.Response = resp 144 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "Delete", resp, "Failure sending request") 145 return 146 } 147 148 result, err = client.DeleteResponder(resp) 149 if err != nil { 150 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "Delete", resp, "Failure responding to request") 151 } 152 153 return 154} 155 156// DeletePreparer prepares the Delete request. 157func (client ConnectionTypeClient) DeletePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string) (*http.Request, error) { 158 pathParameters := map[string]interface{}{ 159 "automationAccountName": autorest.Encode("path", automationAccountName), 160 "connectionTypeName": autorest.Encode("path", connectionTypeName), 161 "resourceGroupName": autorest.Encode("path", resourceGroupName), 162 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 163 } 164 165 const APIVersion = "2015-10-31" 166 queryParameters := map[string]interface{}{ 167 "api-version": APIVersion, 168 } 169 170 preparer := autorest.CreatePreparer( 171 autorest.AsDelete(), 172 autorest.WithBaseURL(client.BaseURI), 173 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/connectionTypes/{connectionTypeName}", pathParameters), 174 autorest.WithQueryParameters(queryParameters)) 175 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 176} 177 178// DeleteSender sends the Delete request. The method will close the 179// http.Response Body if it receives an error. 180func (client ConnectionTypeClient) DeleteSender(req *http.Request) (*http.Response, error) { 181 return autorest.SendWithSender(client, req, 182 azure.DoRetryWithRegistration(client.Client)) 183} 184 185// DeleteResponder handles the response to the Delete request. The method always 186// closes the http.Response Body. 187func (client ConnectionTypeClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 188 err = autorest.Respond( 189 resp, 190 client.ByInspecting(), 191 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 192 autorest.ByClosing()) 193 result.Response = resp 194 return 195} 196 197// Get retrieve the connectiontype identified by connectiontype name. 198// 199// resourceGroupName is the resource group name. automationAccountName is the automation account name. 200// connectionTypeName is the name of connectiontype. 201func (client ConnectionTypeClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string) (result ConnectionType, err error) { 202 if err := validation.Validate([]validation.Validation{ 203 {TargetValue: resourceGroupName, 204 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 205 return result, validation.NewError("automation.ConnectionTypeClient", "Get", err.Error()) 206 } 207 208 req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, connectionTypeName) 209 if err != nil { 210 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "Get", nil, "Failure preparing request") 211 return 212 } 213 214 resp, err := client.GetSender(req) 215 if err != nil { 216 result.Response = autorest.Response{Response: resp} 217 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "Get", resp, "Failure sending request") 218 return 219 } 220 221 result, err = client.GetResponder(resp) 222 if err != nil { 223 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "Get", resp, "Failure responding to request") 224 } 225 226 return 227} 228 229// GetPreparer prepares the Get request. 230func (client ConnectionTypeClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, connectionTypeName string) (*http.Request, error) { 231 pathParameters := map[string]interface{}{ 232 "automationAccountName": autorest.Encode("path", automationAccountName), 233 "connectionTypeName": autorest.Encode("path", connectionTypeName), 234 "resourceGroupName": autorest.Encode("path", resourceGroupName), 235 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 236 } 237 238 const APIVersion = "2015-10-31" 239 queryParameters := map[string]interface{}{ 240 "api-version": APIVersion, 241 } 242 243 preparer := autorest.CreatePreparer( 244 autorest.AsGet(), 245 autorest.WithBaseURL(client.BaseURI), 246 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/connectionTypes/{connectionTypeName}", pathParameters), 247 autorest.WithQueryParameters(queryParameters)) 248 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 249} 250 251// GetSender sends the Get request. The method will close the 252// http.Response Body if it receives an error. 253func (client ConnectionTypeClient) GetSender(req *http.Request) (*http.Response, error) { 254 return autorest.SendWithSender(client, req, 255 azure.DoRetryWithRegistration(client.Client)) 256} 257 258// GetResponder handles the response to the Get request. The method always 259// closes the http.Response Body. 260func (client ConnectionTypeClient) GetResponder(resp *http.Response) (result ConnectionType, err error) { 261 err = autorest.Respond( 262 resp, 263 client.ByInspecting(), 264 azure.WithErrorUnlessStatusCode(http.StatusOK), 265 autorest.ByUnmarshallingJSON(&result), 266 autorest.ByClosing()) 267 result.Response = autorest.Response{Response: resp} 268 return 269} 270 271// ListByAutomationAccount retrieve a list of connectiontypes. 272// 273// resourceGroupName is the resource group name. automationAccountName is the automation account name. 274func (client ConnectionTypeClient) ListByAutomationAccount(ctx context.Context, resourceGroupName string, automationAccountName string) (result ConnectionTypeListResultPage, err error) { 275 if err := validation.Validate([]validation.Validation{ 276 {TargetValue: resourceGroupName, 277 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 278 return result, validation.NewError("automation.ConnectionTypeClient", "ListByAutomationAccount", err.Error()) 279 } 280 281 result.fn = client.listByAutomationAccountNextResults 282 req, err := client.ListByAutomationAccountPreparer(ctx, resourceGroupName, automationAccountName) 283 if err != nil { 284 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "ListByAutomationAccount", nil, "Failure preparing request") 285 return 286 } 287 288 resp, err := client.ListByAutomationAccountSender(req) 289 if err != nil { 290 result.ctlr.Response = autorest.Response{Response: resp} 291 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "ListByAutomationAccount", resp, "Failure sending request") 292 return 293 } 294 295 result.ctlr, err = client.ListByAutomationAccountResponder(resp) 296 if err != nil { 297 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "ListByAutomationAccount", resp, "Failure responding to request") 298 } 299 300 return 301} 302 303// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request. 304func (client ConnectionTypeClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string) (*http.Request, error) { 305 pathParameters := map[string]interface{}{ 306 "automationAccountName": autorest.Encode("path", automationAccountName), 307 "resourceGroupName": autorest.Encode("path", resourceGroupName), 308 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 309 } 310 311 const APIVersion = "2015-10-31" 312 queryParameters := map[string]interface{}{ 313 "api-version": APIVersion, 314 } 315 316 preparer := autorest.CreatePreparer( 317 autorest.AsGet(), 318 autorest.WithBaseURL(client.BaseURI), 319 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/connectionTypes", pathParameters), 320 autorest.WithQueryParameters(queryParameters)) 321 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 322} 323 324// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the 325// http.Response Body if it receives an error. 326func (client ConnectionTypeClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) { 327 return autorest.SendWithSender(client, req, 328 azure.DoRetryWithRegistration(client.Client)) 329} 330 331// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always 332// closes the http.Response Body. 333func (client ConnectionTypeClient) ListByAutomationAccountResponder(resp *http.Response) (result ConnectionTypeListResult, err error) { 334 err = autorest.Respond( 335 resp, 336 client.ByInspecting(), 337 azure.WithErrorUnlessStatusCode(http.StatusOK), 338 autorest.ByUnmarshallingJSON(&result), 339 autorest.ByClosing()) 340 result.Response = autorest.Response{Response: resp} 341 return 342} 343 344// listByAutomationAccountNextResults retrieves the next set of results, if any. 345func (client ConnectionTypeClient) listByAutomationAccountNextResults(lastResults ConnectionTypeListResult) (result ConnectionTypeListResult, err error) { 346 req, err := lastResults.connectionTypeListResultPreparer() 347 if err != nil { 348 return result, autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "listByAutomationAccountNextResults", nil, "Failure preparing next results request") 349 } 350 if req == nil { 351 return 352 } 353 resp, err := client.ListByAutomationAccountSender(req) 354 if err != nil { 355 result.Response = autorest.Response{Response: resp} 356 return result, autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "listByAutomationAccountNextResults", resp, "Failure sending next results request") 357 } 358 result, err = client.ListByAutomationAccountResponder(resp) 359 if err != nil { 360 err = autorest.NewErrorWithError(err, "automation.ConnectionTypeClient", "listByAutomationAccountNextResults", resp, "Failure responding to next results request") 361 } 362 return 363} 364 365// ListByAutomationAccountComplete enumerates all values, automatically crossing page boundaries as required. 366func (client ConnectionTypeClient) ListByAutomationAccountComplete(ctx context.Context, resourceGroupName string, automationAccountName string) (result ConnectionTypeListResultIterator, err error) { 367 result.page, err = client.ListByAutomationAccount(ctx, resourceGroupName, automationAccountName) 368 return 369} 370