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// SoftwareUpdateConfigurationsClient is the automation Client 30type SoftwareUpdateConfigurationsClient struct { 31 BaseClient 32} 33 34// NewSoftwareUpdateConfigurationsClient creates an instance of the SoftwareUpdateConfigurationsClient client. 35func NewSoftwareUpdateConfigurationsClient(subscriptionID string) SoftwareUpdateConfigurationsClient { 36 return NewSoftwareUpdateConfigurationsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewSoftwareUpdateConfigurationsClientWithBaseURI creates an instance of the SoftwareUpdateConfigurationsClient 40// client using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI 41// (sovereign clouds, Azure stack). 42func NewSoftwareUpdateConfigurationsClientWithBaseURI(baseURI string, subscriptionID string) SoftwareUpdateConfigurationsClient { 43 return SoftwareUpdateConfigurationsClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// Create create a new software update configuration with the name given in the URI. 47// Parameters: 48// resourceGroupName - name of an Azure Resource group. 49// automationAccountName - the name of the automation account. 50// softwareUpdateConfigurationName - the name of the software update configuration to be created. 51// parameters - request body. 52// clientRequestID - identifies this specific client request. 53func (client SoftwareUpdateConfigurationsClient) Create(ctx context.Context, resourceGroupName string, automationAccountName string, softwareUpdateConfigurationName string, parameters SoftwareUpdateConfiguration, clientRequestID string) (result SoftwareUpdateConfiguration, err error) { 54 if tracing.IsEnabled() { 55 ctx = tracing.StartSpan(ctx, fqdn+"/SoftwareUpdateConfigurationsClient.Create") 56 defer func() { 57 sc := -1 58 if result.Response.Response != nil { 59 sc = result.Response.Response.StatusCode 60 } 61 tracing.EndSpan(ctx, sc, err) 62 }() 63 } 64 if err := validation.Validate([]validation.Validation{ 65 {TargetValue: resourceGroupName, 66 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 67 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 68 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}, 69 {TargetValue: parameters, 70 Constraints: []validation.Constraint{{Target: "parameters.SoftwareUpdateConfigurationProperties", Name: validation.Null, Rule: true, 71 Chain: []validation.Constraint{{Target: "parameters.SoftwareUpdateConfigurationProperties.UpdateConfiguration", Name: validation.Null, Rule: true, Chain: nil}, 72 {Target: "parameters.SoftwareUpdateConfigurationProperties.ScheduleInfo", Name: validation.Null, Rule: true, Chain: nil}, 73 }}}}}); err != nil { 74 return result, validation.NewError("automation.SoftwareUpdateConfigurationsClient", "Create", err.Error()) 75 } 76 77 req, err := client.CreatePreparer(ctx, resourceGroupName, automationAccountName, softwareUpdateConfigurationName, parameters, clientRequestID) 78 if err != nil { 79 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "Create", nil, "Failure preparing request") 80 return 81 } 82 83 resp, err := client.CreateSender(req) 84 if err != nil { 85 result.Response = autorest.Response{Response: resp} 86 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "Create", resp, "Failure sending request") 87 return 88 } 89 90 result, err = client.CreateResponder(resp) 91 if err != nil { 92 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "Create", resp, "Failure responding to request") 93 } 94 95 return 96} 97 98// CreatePreparer prepares the Create request. 99func (client SoftwareUpdateConfigurationsClient) CreatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, softwareUpdateConfigurationName string, parameters SoftwareUpdateConfiguration, clientRequestID string) (*http.Request, error) { 100 pathParameters := map[string]interface{}{ 101 "automationAccountName": autorest.Encode("path", automationAccountName), 102 "resourceGroupName": autorest.Encode("path", resourceGroupName), 103 "softwareUpdateConfigurationName": autorest.Encode("path", softwareUpdateConfigurationName), 104 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 105 } 106 107 const APIVersion = "2017-05-15-preview" 108 queryParameters := map[string]interface{}{ 109 "api-version": APIVersion, 110 } 111 112 parameters.Name = nil 113 parameters.ID = nil 114 parameters.Type = nil 115 preparer := autorest.CreatePreparer( 116 autorest.AsContentType("application/json; charset=utf-8"), 117 autorest.AsPut(), 118 autorest.WithBaseURL(client.BaseURI), 119 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/softwareUpdateConfigurations/{softwareUpdateConfigurationName}", pathParameters), 120 autorest.WithJSON(parameters), 121 autorest.WithQueryParameters(queryParameters)) 122 if len(clientRequestID) > 0 { 123 preparer = autorest.DecoratePreparer(preparer, 124 autorest.WithHeader("clientRequestId", autorest.String(clientRequestID))) 125 } 126 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 127} 128 129// CreateSender sends the Create request. The method will close the 130// http.Response Body if it receives an error. 131func (client SoftwareUpdateConfigurationsClient) CreateSender(req *http.Request) (*http.Response, error) { 132 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 133} 134 135// CreateResponder handles the response to the Create request. The method always 136// closes the http.Response Body. 137func (client SoftwareUpdateConfigurationsClient) CreateResponder(resp *http.Response) (result SoftwareUpdateConfiguration, err error) { 138 err = autorest.Respond( 139 resp, 140 client.ByInspecting(), 141 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 142 autorest.ByUnmarshallingJSON(&result), 143 autorest.ByClosing()) 144 result.Response = autorest.Response{Response: resp} 145 return 146} 147 148// Delete delete a specific software update configuration. 149// Parameters: 150// resourceGroupName - name of an Azure Resource group. 151// automationAccountName - the name of the automation account. 152// softwareUpdateConfigurationName - the name of the software update configuration to be created. 153// clientRequestID - identifies this specific client request. 154func (client SoftwareUpdateConfigurationsClient) Delete(ctx context.Context, resourceGroupName string, automationAccountName string, softwareUpdateConfigurationName string, clientRequestID string) (result autorest.Response, err error) { 155 if tracing.IsEnabled() { 156 ctx = tracing.StartSpan(ctx, fqdn+"/SoftwareUpdateConfigurationsClient.Delete") 157 defer func() { 158 sc := -1 159 if result.Response != nil { 160 sc = result.Response.StatusCode 161 } 162 tracing.EndSpan(ctx, sc, err) 163 }() 164 } 165 if err := validation.Validate([]validation.Validation{ 166 {TargetValue: resourceGroupName, 167 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 168 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 169 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 170 return result, validation.NewError("automation.SoftwareUpdateConfigurationsClient", "Delete", err.Error()) 171 } 172 173 req, err := client.DeletePreparer(ctx, resourceGroupName, automationAccountName, softwareUpdateConfigurationName, clientRequestID) 174 if err != nil { 175 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "Delete", nil, "Failure preparing request") 176 return 177 } 178 179 resp, err := client.DeleteSender(req) 180 if err != nil { 181 result.Response = resp 182 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "Delete", resp, "Failure sending request") 183 return 184 } 185 186 result, err = client.DeleteResponder(resp) 187 if err != nil { 188 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "Delete", resp, "Failure responding to request") 189 } 190 191 return 192} 193 194// DeletePreparer prepares the Delete request. 195func (client SoftwareUpdateConfigurationsClient) DeletePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, softwareUpdateConfigurationName string, clientRequestID string) (*http.Request, error) { 196 pathParameters := map[string]interface{}{ 197 "automationAccountName": autorest.Encode("path", automationAccountName), 198 "resourceGroupName": autorest.Encode("path", resourceGroupName), 199 "softwareUpdateConfigurationName": autorest.Encode("path", softwareUpdateConfigurationName), 200 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 201 } 202 203 const APIVersion = "2017-05-15-preview" 204 queryParameters := map[string]interface{}{ 205 "api-version": APIVersion, 206 } 207 208 preparer := autorest.CreatePreparer( 209 autorest.AsDelete(), 210 autorest.WithBaseURL(client.BaseURI), 211 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/softwareUpdateConfigurations/{softwareUpdateConfigurationName}", pathParameters), 212 autorest.WithQueryParameters(queryParameters)) 213 if len(clientRequestID) > 0 { 214 preparer = autorest.DecoratePreparer(preparer, 215 autorest.WithHeader("clientRequestId", autorest.String(clientRequestID))) 216 } 217 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 218} 219 220// DeleteSender sends the Delete request. The method will close the 221// http.Response Body if it receives an error. 222func (client SoftwareUpdateConfigurationsClient) DeleteSender(req *http.Request) (*http.Response, error) { 223 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 224} 225 226// DeleteResponder handles the response to the Delete request. The method always 227// closes the http.Response Body. 228func (client SoftwareUpdateConfigurationsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 229 err = autorest.Respond( 230 resp, 231 client.ByInspecting(), 232 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 233 autorest.ByClosing()) 234 result.Response = resp 235 return 236} 237 238// GetByName get a single software update configuration by name. 239// Parameters: 240// resourceGroupName - name of an Azure Resource group. 241// automationAccountName - the name of the automation account. 242// softwareUpdateConfigurationName - the name of the software update configuration to be created. 243// clientRequestID - identifies this specific client request. 244func (client SoftwareUpdateConfigurationsClient) GetByName(ctx context.Context, resourceGroupName string, automationAccountName string, softwareUpdateConfigurationName string, clientRequestID string) (result SoftwareUpdateConfiguration, err error) { 245 if tracing.IsEnabled() { 246 ctx = tracing.StartSpan(ctx, fqdn+"/SoftwareUpdateConfigurationsClient.GetByName") 247 defer func() { 248 sc := -1 249 if result.Response.Response != nil { 250 sc = result.Response.Response.StatusCode 251 } 252 tracing.EndSpan(ctx, sc, err) 253 }() 254 } 255 if err := validation.Validate([]validation.Validation{ 256 {TargetValue: resourceGroupName, 257 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 258 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 259 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 260 return result, validation.NewError("automation.SoftwareUpdateConfigurationsClient", "GetByName", err.Error()) 261 } 262 263 req, err := client.GetByNamePreparer(ctx, resourceGroupName, automationAccountName, softwareUpdateConfigurationName, clientRequestID) 264 if err != nil { 265 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "GetByName", nil, "Failure preparing request") 266 return 267 } 268 269 resp, err := client.GetByNameSender(req) 270 if err != nil { 271 result.Response = autorest.Response{Response: resp} 272 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "GetByName", resp, "Failure sending request") 273 return 274 } 275 276 result, err = client.GetByNameResponder(resp) 277 if err != nil { 278 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "GetByName", resp, "Failure responding to request") 279 } 280 281 return 282} 283 284// GetByNamePreparer prepares the GetByName request. 285func (client SoftwareUpdateConfigurationsClient) GetByNamePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, softwareUpdateConfigurationName string, clientRequestID string) (*http.Request, error) { 286 pathParameters := map[string]interface{}{ 287 "automationAccountName": autorest.Encode("path", automationAccountName), 288 "resourceGroupName": autorest.Encode("path", resourceGroupName), 289 "softwareUpdateConfigurationName": autorest.Encode("path", softwareUpdateConfigurationName), 290 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 291 } 292 293 const APIVersion = "2017-05-15-preview" 294 queryParameters := map[string]interface{}{ 295 "api-version": APIVersion, 296 } 297 298 preparer := autorest.CreatePreparer( 299 autorest.AsGet(), 300 autorest.WithBaseURL(client.BaseURI), 301 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/softwareUpdateConfigurations/{softwareUpdateConfigurationName}", pathParameters), 302 autorest.WithQueryParameters(queryParameters)) 303 if len(clientRequestID) > 0 { 304 preparer = autorest.DecoratePreparer(preparer, 305 autorest.WithHeader("clientRequestId", autorest.String(clientRequestID))) 306 } 307 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 308} 309 310// GetByNameSender sends the GetByName request. The method will close the 311// http.Response Body if it receives an error. 312func (client SoftwareUpdateConfigurationsClient) GetByNameSender(req *http.Request) (*http.Response, error) { 313 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 314} 315 316// GetByNameResponder handles the response to the GetByName request. The method always 317// closes the http.Response Body. 318func (client SoftwareUpdateConfigurationsClient) GetByNameResponder(resp *http.Response) (result SoftwareUpdateConfiguration, err error) { 319 err = autorest.Respond( 320 resp, 321 client.ByInspecting(), 322 azure.WithErrorUnlessStatusCode(http.StatusOK), 323 autorest.ByUnmarshallingJSON(&result), 324 autorest.ByClosing()) 325 result.Response = autorest.Response{Response: resp} 326 return 327} 328 329// List get all software update configurations for the account. 330// Parameters: 331// resourceGroupName - name of an Azure Resource group. 332// automationAccountName - the name of the automation account. 333// clientRequestID - identifies this specific client request. 334// filter - the filter to apply on the operation. 335func (client SoftwareUpdateConfigurationsClient) List(ctx context.Context, resourceGroupName string, automationAccountName string, clientRequestID string, filter string) (result SoftwareUpdateConfigurationListResult, err error) { 336 if tracing.IsEnabled() { 337 ctx = tracing.StartSpan(ctx, fqdn+"/SoftwareUpdateConfigurationsClient.List") 338 defer func() { 339 sc := -1 340 if result.Response.Response != nil { 341 sc = result.Response.Response.StatusCode 342 } 343 tracing.EndSpan(ctx, sc, err) 344 }() 345 } 346 if err := validation.Validate([]validation.Validation{ 347 {TargetValue: resourceGroupName, 348 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 349 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 350 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 351 return result, validation.NewError("automation.SoftwareUpdateConfigurationsClient", "List", err.Error()) 352 } 353 354 req, err := client.ListPreparer(ctx, resourceGroupName, automationAccountName, clientRequestID, filter) 355 if err != nil { 356 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "List", nil, "Failure preparing request") 357 return 358 } 359 360 resp, err := client.ListSender(req) 361 if err != nil { 362 result.Response = autorest.Response{Response: resp} 363 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "List", resp, "Failure sending request") 364 return 365 } 366 367 result, err = client.ListResponder(resp) 368 if err != nil { 369 err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationsClient", "List", resp, "Failure responding to request") 370 } 371 372 return 373} 374 375// ListPreparer prepares the List request. 376func (client SoftwareUpdateConfigurationsClient) ListPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, clientRequestID string, filter string) (*http.Request, error) { 377 pathParameters := map[string]interface{}{ 378 "automationAccountName": autorest.Encode("path", automationAccountName), 379 "resourceGroupName": autorest.Encode("path", resourceGroupName), 380 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 381 } 382 383 const APIVersion = "2017-05-15-preview" 384 queryParameters := map[string]interface{}{ 385 "api-version": APIVersion, 386 } 387 if len(filter) > 0 { 388 queryParameters["$filter"] = autorest.Encode("query", filter) 389 } 390 391 preparer := autorest.CreatePreparer( 392 autorest.AsGet(), 393 autorest.WithBaseURL(client.BaseURI), 394 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/softwareUpdateConfigurations", pathParameters), 395 autorest.WithQueryParameters(queryParameters)) 396 if len(clientRequestID) > 0 { 397 preparer = autorest.DecoratePreparer(preparer, 398 autorest.WithHeader("clientRequestId", autorest.String(clientRequestID))) 399 } 400 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 401} 402 403// ListSender sends the List request. The method will close the 404// http.Response Body if it receives an error. 405func (client SoftwareUpdateConfigurationsClient) ListSender(req *http.Request) (*http.Response, error) { 406 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 407} 408 409// ListResponder handles the response to the List request. The method always 410// closes the http.Response Body. 411func (client SoftwareUpdateConfigurationsClient) ListResponder(resp *http.Response) (result SoftwareUpdateConfigurationListResult, err error) { 412 err = autorest.Respond( 413 resp, 414 client.ByInspecting(), 415 azure.WithErrorUnlessStatusCode(http.StatusOK), 416 autorest.ByUnmarshallingJSON(&result), 417 autorest.ByClosing()) 418 result.Response = autorest.Response{Response: resp} 419 return 420} 421