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