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 "io" 27 "net/http" 28) 29 30// RunbookDraftClient is the automation Client 31type RunbookDraftClient struct { 32 BaseClient 33} 34 35// NewRunbookDraftClient creates an instance of the RunbookDraftClient client. 36func NewRunbookDraftClient(subscriptionID string) RunbookDraftClient { 37 return NewRunbookDraftClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewRunbookDraftClientWithBaseURI creates an instance of the RunbookDraftClient 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 NewRunbookDraftClientWithBaseURI(baseURI string, subscriptionID string) RunbookDraftClient { 43 return RunbookDraftClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// Get retrieve the runbook draft identified by runbook name. 47// Parameters: 48// resourceGroupName - name of an Azure Resource group. 49// automationAccountName - the name of the automation account. 50// runbookName - the runbook name. 51func (client RunbookDraftClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (result RunbookDraft, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/RunbookDraftClient.Get") 54 defer func() { 55 sc := -1 56 if result.Response.Response != nil { 57 sc = result.Response.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: resourceGroupName, 64 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 65 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 66 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 67 return result, validation.NewError("automation.RunbookDraftClient", "Get", err.Error()) 68 } 69 70 req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, runbookName) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "Get", nil, "Failure preparing request") 73 return 74 } 75 76 resp, err := client.GetSender(req) 77 if err != nil { 78 result.Response = autorest.Response{Response: resp} 79 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "Get", resp, "Failure sending request") 80 return 81 } 82 83 result, err = client.GetResponder(resp) 84 if err != nil { 85 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "Get", resp, "Failure responding to request") 86 } 87 88 return 89} 90 91// GetPreparer prepares the Get request. 92func (client RunbookDraftClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (*http.Request, error) { 93 pathParameters := map[string]interface{}{ 94 "automationAccountName": autorest.Encode("path", automationAccountName), 95 "resourceGroupName": autorest.Encode("path", resourceGroupName), 96 "runbookName": autorest.Encode("path", runbookName), 97 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 98 } 99 100 const APIVersion = "2015-10-31" 101 queryParameters := map[string]interface{}{ 102 "api-version": APIVersion, 103 } 104 105 preparer := autorest.CreatePreparer( 106 autorest.AsGet(), 107 autorest.WithBaseURL(client.BaseURI), 108 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft", pathParameters), 109 autorest.WithQueryParameters(queryParameters)) 110 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 111} 112 113// GetSender sends the Get request. The method will close the 114// http.Response Body if it receives an error. 115func (client RunbookDraftClient) GetSender(req *http.Request) (*http.Response, error) { 116 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 117} 118 119// GetResponder handles the response to the Get request. The method always 120// closes the http.Response Body. 121func (client RunbookDraftClient) GetResponder(resp *http.Response) (result RunbookDraft, err error) { 122 err = autorest.Respond( 123 resp, 124 client.ByInspecting(), 125 azure.WithErrorUnlessStatusCode(http.StatusOK), 126 autorest.ByUnmarshallingJSON(&result), 127 autorest.ByClosing()) 128 result.Response = autorest.Response{Response: resp} 129 return 130} 131 132// GetContent retrieve the content of runbook draft identified by runbook name. 133// Parameters: 134// resourceGroupName - name of an Azure Resource group. 135// automationAccountName - the name of the automation account. 136// runbookName - the runbook name. 137func (client RunbookDraftClient) GetContent(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (result ReadCloser, err error) { 138 if tracing.IsEnabled() { 139 ctx = tracing.StartSpan(ctx, fqdn+"/RunbookDraftClient.GetContent") 140 defer func() { 141 sc := -1 142 if result.Response.Response != nil { 143 sc = result.Response.Response.StatusCode 144 } 145 tracing.EndSpan(ctx, sc, err) 146 }() 147 } 148 if err := validation.Validate([]validation.Validation{ 149 {TargetValue: resourceGroupName, 150 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 151 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 152 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 153 return result, validation.NewError("automation.RunbookDraftClient", "GetContent", err.Error()) 154 } 155 156 req, err := client.GetContentPreparer(ctx, resourceGroupName, automationAccountName, runbookName) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "GetContent", nil, "Failure preparing request") 159 return 160 } 161 162 resp, err := client.GetContentSender(req) 163 if err != nil { 164 result.Response = autorest.Response{Response: resp} 165 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "GetContent", resp, "Failure sending request") 166 return 167 } 168 169 result, err = client.GetContentResponder(resp) 170 if err != nil { 171 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "GetContent", resp, "Failure responding to request") 172 } 173 174 return 175} 176 177// GetContentPreparer prepares the GetContent request. 178func (client RunbookDraftClient) GetContentPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (*http.Request, error) { 179 pathParameters := map[string]interface{}{ 180 "automationAccountName": autorest.Encode("path", automationAccountName), 181 "resourceGroupName": autorest.Encode("path", resourceGroupName), 182 "runbookName": autorest.Encode("path", runbookName), 183 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 184 } 185 186 const APIVersion = "2015-10-31" 187 queryParameters := map[string]interface{}{ 188 "api-version": APIVersion, 189 } 190 191 preparer := autorest.CreatePreparer( 192 autorest.AsGet(), 193 autorest.WithBaseURL(client.BaseURI), 194 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/content", pathParameters), 195 autorest.WithQueryParameters(queryParameters)) 196 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 197} 198 199// GetContentSender sends the GetContent request. The method will close the 200// http.Response Body if it receives an error. 201func (client RunbookDraftClient) GetContentSender(req *http.Request) (*http.Response, error) { 202 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 203} 204 205// GetContentResponder handles the response to the GetContent request. The method always 206// closes the http.Response Body. 207func (client RunbookDraftClient) GetContentResponder(resp *http.Response) (result ReadCloser, err error) { 208 result.Value = &resp.Body 209 err = autorest.Respond( 210 resp, 211 client.ByInspecting(), 212 azure.WithErrorUnlessStatusCode(http.StatusOK)) 213 result.Response = autorest.Response{Response: resp} 214 return 215} 216 217// Publish publish runbook draft. 218// Parameters: 219// resourceGroupName - name of an Azure Resource group. 220// automationAccountName - the name of the automation account. 221// runbookName - the parameters supplied to the publish runbook operation. 222func (client RunbookDraftClient) Publish(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (result RunbookDraftPublishFuture, err error) { 223 if tracing.IsEnabled() { 224 ctx = tracing.StartSpan(ctx, fqdn+"/RunbookDraftClient.Publish") 225 defer func() { 226 sc := -1 227 if result.Response() != nil { 228 sc = result.Response().StatusCode 229 } 230 tracing.EndSpan(ctx, sc, err) 231 }() 232 } 233 if err := validation.Validate([]validation.Validation{ 234 {TargetValue: resourceGroupName, 235 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 236 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 237 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 238 return result, validation.NewError("automation.RunbookDraftClient", "Publish", err.Error()) 239 } 240 241 req, err := client.PublishPreparer(ctx, resourceGroupName, automationAccountName, runbookName) 242 if err != nil { 243 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "Publish", nil, "Failure preparing request") 244 return 245 } 246 247 result, err = client.PublishSender(req) 248 if err != nil { 249 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "Publish", result.Response(), "Failure sending request") 250 return 251 } 252 253 return 254} 255 256// PublishPreparer prepares the Publish request. 257func (client RunbookDraftClient) PublishPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (*http.Request, error) { 258 pathParameters := map[string]interface{}{ 259 "automationAccountName": autorest.Encode("path", automationAccountName), 260 "resourceGroupName": autorest.Encode("path", resourceGroupName), 261 "runbookName": autorest.Encode("path", runbookName), 262 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 263 } 264 265 const APIVersion = "2015-10-31" 266 queryParameters := map[string]interface{}{ 267 "api-version": APIVersion, 268 } 269 270 preparer := autorest.CreatePreparer( 271 autorest.AsPost(), 272 autorest.WithBaseURL(client.BaseURI), 273 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/publish", pathParameters), 274 autorest.WithQueryParameters(queryParameters)) 275 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 276} 277 278// PublishSender sends the Publish request. The method will close the 279// http.Response Body if it receives an error. 280func (client RunbookDraftClient) PublishSender(req *http.Request) (future RunbookDraftPublishFuture, err error) { 281 var resp *http.Response 282 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 283 if err != nil { 284 return 285 } 286 future.Future, err = azure.NewFutureFromResponse(resp) 287 return 288} 289 290// PublishResponder handles the response to the Publish request. The method always 291// closes the http.Response Body. 292func (client RunbookDraftClient) PublishResponder(resp *http.Response) (result autorest.Response, err error) { 293 err = autorest.Respond( 294 resp, 295 client.ByInspecting(), 296 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 297 autorest.ByClosing()) 298 result.Response = resp 299 return 300} 301 302// ReplaceContent replaces the runbook draft content. 303// Parameters: 304// resourceGroupName - name of an Azure Resource group. 305// automationAccountName - the name of the automation account. 306// runbookName - the runbook name. 307// runbookContent - the runbook draft content. 308func (client RunbookDraftClient) ReplaceContent(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, runbookContent io.ReadCloser) (result RunbookDraftReplaceContentFuture, err error) { 309 if tracing.IsEnabled() { 310 ctx = tracing.StartSpan(ctx, fqdn+"/RunbookDraftClient.ReplaceContent") 311 defer func() { 312 sc := -1 313 if result.Response() != nil { 314 sc = result.Response().StatusCode 315 } 316 tracing.EndSpan(ctx, sc, err) 317 }() 318 } 319 if err := validation.Validate([]validation.Validation{ 320 {TargetValue: resourceGroupName, 321 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 322 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 323 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 324 return result, validation.NewError("automation.RunbookDraftClient", "ReplaceContent", err.Error()) 325 } 326 327 req, err := client.ReplaceContentPreparer(ctx, resourceGroupName, automationAccountName, runbookName, runbookContent) 328 if err != nil { 329 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "ReplaceContent", nil, "Failure preparing request") 330 return 331 } 332 333 result, err = client.ReplaceContentSender(req) 334 if err != nil { 335 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "ReplaceContent", result.Response(), "Failure sending request") 336 return 337 } 338 339 return 340} 341 342// ReplaceContentPreparer prepares the ReplaceContent request. 343func (client RunbookDraftClient) ReplaceContentPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, runbookContent io.ReadCloser) (*http.Request, error) { 344 pathParameters := map[string]interface{}{ 345 "automationAccountName": autorest.Encode("path", automationAccountName), 346 "resourceGroupName": autorest.Encode("path", resourceGroupName), 347 "runbookName": autorest.Encode("path", runbookName), 348 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 349 } 350 351 const APIVersion = "2015-10-31" 352 queryParameters := map[string]interface{}{ 353 "api-version": APIVersion, 354 } 355 356 preparer := autorest.CreatePreparer( 357 autorest.AsContentType("text/powershell"), 358 autorest.AsPut(), 359 autorest.WithBaseURL(client.BaseURI), 360 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/content", pathParameters), 361 autorest.WithFile(runbookContent), 362 autorest.WithQueryParameters(queryParameters)) 363 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 364} 365 366// ReplaceContentSender sends the ReplaceContent request. The method will close the 367// http.Response Body if it receives an error. 368func (client RunbookDraftClient) ReplaceContentSender(req *http.Request) (future RunbookDraftReplaceContentFuture, err error) { 369 var resp *http.Response 370 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 371 if err != nil { 372 return 373 } 374 future.Future, err = azure.NewFutureFromResponse(resp) 375 return 376} 377 378// ReplaceContentResponder handles the response to the ReplaceContent request. The method always 379// closes the http.Response Body. 380func (client RunbookDraftClient) ReplaceContentResponder(resp *http.Response) (result ReadCloser, err error) { 381 err = autorest.Respond( 382 resp, 383 client.ByInspecting(), 384 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 385 autorest.ByUnmarshallingJSON(&result), 386 autorest.ByClosing()) 387 result.Response = autorest.Response{Response: resp} 388 return 389} 390 391// UndoEdit undo draft edit to last known published state identified by runbook name. 392// Parameters: 393// resourceGroupName - name of an Azure Resource group. 394// automationAccountName - the name of the automation account. 395// runbookName - the runbook name. 396func (client RunbookDraftClient) UndoEdit(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (result RunbookDraftUndoEditResult, err error) { 397 if tracing.IsEnabled() { 398 ctx = tracing.StartSpan(ctx, fqdn+"/RunbookDraftClient.UndoEdit") 399 defer func() { 400 sc := -1 401 if result.Response.Response != nil { 402 sc = result.Response.Response.StatusCode 403 } 404 tracing.EndSpan(ctx, sc, err) 405 }() 406 } 407 if err := validation.Validate([]validation.Validation{ 408 {TargetValue: resourceGroupName, 409 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 410 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 411 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 412 return result, validation.NewError("automation.RunbookDraftClient", "UndoEdit", err.Error()) 413 } 414 415 req, err := client.UndoEditPreparer(ctx, resourceGroupName, automationAccountName, runbookName) 416 if err != nil { 417 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "UndoEdit", nil, "Failure preparing request") 418 return 419 } 420 421 resp, err := client.UndoEditSender(req) 422 if err != nil { 423 result.Response = autorest.Response{Response: resp} 424 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "UndoEdit", resp, "Failure sending request") 425 return 426 } 427 428 result, err = client.UndoEditResponder(resp) 429 if err != nil { 430 err = autorest.NewErrorWithError(err, "automation.RunbookDraftClient", "UndoEdit", resp, "Failure responding to request") 431 } 432 433 return 434} 435 436// UndoEditPreparer prepares the UndoEdit request. 437func (client RunbookDraftClient) UndoEditPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (*http.Request, error) { 438 pathParameters := map[string]interface{}{ 439 "automationAccountName": autorest.Encode("path", automationAccountName), 440 "resourceGroupName": autorest.Encode("path", resourceGroupName), 441 "runbookName": autorest.Encode("path", runbookName), 442 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 443 } 444 445 const APIVersion = "2015-10-31" 446 queryParameters := map[string]interface{}{ 447 "api-version": APIVersion, 448 } 449 450 preparer := autorest.CreatePreparer( 451 autorest.AsPost(), 452 autorest.WithBaseURL(client.BaseURI), 453 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/undoEdit", pathParameters), 454 autorest.WithQueryParameters(queryParameters)) 455 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 456} 457 458// UndoEditSender sends the UndoEdit request. The method will close the 459// http.Response Body if it receives an error. 460func (client RunbookDraftClient) UndoEditSender(req *http.Request) (*http.Response, error) { 461 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 462} 463 464// UndoEditResponder handles the response to the UndoEdit request. The method always 465// closes the http.Response Body. 466func (client RunbookDraftClient) UndoEditResponder(resp *http.Response) (result RunbookDraftUndoEditResult, err error) { 467 err = autorest.Respond( 468 resp, 469 client.ByInspecting(), 470 azure.WithErrorUnlessStatusCode(http.StatusOK), 471 autorest.ByUnmarshallingJSON(&result), 472 autorest.ByClosing()) 473 result.Response = autorest.Response{Response: resp} 474 return 475} 476