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