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// RunbookClient is the automation Client
19type RunbookClient struct {
20	BaseClient
21}
22
23// NewRunbookClient creates an instance of the RunbookClient client.
24func NewRunbookClient(subscriptionID string) RunbookClient {
25	return NewRunbookClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewRunbookClientWithBaseURI creates an instance of the RunbookClient client using a custom endpoint.  Use this when
29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewRunbookClientWithBaseURI(baseURI string, subscriptionID string) RunbookClient {
31	return RunbookClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate create the runbook identified by runbook name.
35// Parameters:
36// resourceGroupName - name of an Azure Resource group.
37// automationAccountName - the name of the automation account.
38// runbookName - the runbook name.
39// parameters - the create or update parameters for runbook. Provide either content link for a published
40// runbook or draft, not both.
41func (client RunbookClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, parameters RunbookCreateOrUpdateParameters) (result Runbook, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/RunbookClient.CreateOrUpdate")
44		defer func() {
45			sc := -1
46			if result.Response.Response != nil {
47				sc = result.Response.Response.StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: resourceGroupName,
54			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
55				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
56				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
57		{TargetValue: parameters,
58			Constraints: []validation.Constraint{{Target: "parameters.RunbookCreateOrUpdateProperties", Name: validation.Null, Rule: true,
59				Chain: []validation.Constraint{{Target: "parameters.RunbookCreateOrUpdateProperties.Draft", Name: validation.Null, Rule: false,
60					Chain: []validation.Constraint{{Target: "parameters.RunbookCreateOrUpdateProperties.Draft.DraftContentLink", Name: validation.Null, Rule: false,
61						Chain: []validation.Constraint{{Target: "parameters.RunbookCreateOrUpdateProperties.Draft.DraftContentLink.ContentHash", Name: validation.Null, Rule: false,
62							Chain: []validation.Constraint{{Target: "parameters.RunbookCreateOrUpdateProperties.Draft.DraftContentLink.ContentHash.Algorithm", Name: validation.Null, Rule: true, Chain: nil},
63								{Target: "parameters.RunbookCreateOrUpdateProperties.Draft.DraftContentLink.ContentHash.Value", Name: validation.Null, Rule: true, Chain: nil},
64							}},
65						}},
66					}},
67					{Target: "parameters.RunbookCreateOrUpdateProperties.PublishContentLink", Name: validation.Null, Rule: false,
68						Chain: []validation.Constraint{{Target: "parameters.RunbookCreateOrUpdateProperties.PublishContentLink.ContentHash", Name: validation.Null, Rule: false,
69							Chain: []validation.Constraint{{Target: "parameters.RunbookCreateOrUpdateProperties.PublishContentLink.ContentHash.Algorithm", Name: validation.Null, Rule: true, Chain: nil},
70								{Target: "parameters.RunbookCreateOrUpdateProperties.PublishContentLink.ContentHash.Value", Name: validation.Null, Rule: true, Chain: nil},
71							}},
72						}},
73				}}}}}); err != nil {
74		return result, validation.NewError("automation.RunbookClient", "CreateOrUpdate", err.Error())
75	}
76
77	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, automationAccountName, runbookName, parameters)
78	if err != nil {
79		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "CreateOrUpdate", nil, "Failure preparing request")
80		return
81	}
82
83	resp, err := client.CreateOrUpdateSender(req)
84	if err != nil {
85		result.Response = autorest.Response{Response: resp}
86		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "CreateOrUpdate", resp, "Failure sending request")
87		return
88	}
89
90	result, err = client.CreateOrUpdateResponder(resp)
91	if err != nil {
92		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "CreateOrUpdate", resp, "Failure responding to request")
93		return
94	}
95
96	return
97}
98
99// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
100func (client RunbookClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, parameters RunbookCreateOrUpdateParameters) (*http.Request, error) {
101	pathParameters := map[string]interface{}{
102		"automationAccountName": autorest.Encode("path", automationAccountName),
103		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
104		"runbookName":           autorest.Encode("path", runbookName),
105		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
106	}
107
108	const APIVersion = "2015-10-31"
109	queryParameters := map[string]interface{}{
110		"api-version": APIVersion,
111	}
112
113	preparer := autorest.CreatePreparer(
114		autorest.AsContentType("application/json; charset=utf-8"),
115		autorest.AsPut(),
116		autorest.WithBaseURL(client.BaseURI),
117		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}", pathParameters),
118		autorest.WithJSON(parameters),
119		autorest.WithQueryParameters(queryParameters))
120	return preparer.Prepare((&http.Request{}).WithContext(ctx))
121}
122
123// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
124// http.Response Body if it receives an error.
125func (client RunbookClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
126	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
127}
128
129// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
130// closes the http.Response Body.
131func (client RunbookClient) CreateOrUpdateResponder(resp *http.Response) (result Runbook, err error) {
132	err = autorest.Respond(
133		resp,
134		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusBadRequest),
135		autorest.ByUnmarshallingJSON(&result),
136		autorest.ByClosing())
137	result.Response = autorest.Response{Response: resp}
138	return
139}
140
141// Delete delete the runbook by name.
142// Parameters:
143// resourceGroupName - name of an Azure Resource group.
144// automationAccountName - the name of the automation account.
145// runbookName - the runbook name.
146func (client RunbookClient) Delete(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (result autorest.Response, err error) {
147	if tracing.IsEnabled() {
148		ctx = tracing.StartSpan(ctx, fqdn+"/RunbookClient.Delete")
149		defer func() {
150			sc := -1
151			if result.Response != nil {
152				sc = result.Response.StatusCode
153			}
154			tracing.EndSpan(ctx, sc, err)
155		}()
156	}
157	if err := validation.Validate([]validation.Validation{
158		{TargetValue: resourceGroupName,
159			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
160				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
161				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
162		return result, validation.NewError("automation.RunbookClient", "Delete", err.Error())
163	}
164
165	req, err := client.DeletePreparer(ctx, resourceGroupName, automationAccountName, runbookName)
166	if err != nil {
167		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "Delete", nil, "Failure preparing request")
168		return
169	}
170
171	resp, err := client.DeleteSender(req)
172	if err != nil {
173		result.Response = resp
174		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "Delete", resp, "Failure sending request")
175		return
176	}
177
178	result, err = client.DeleteResponder(resp)
179	if err != nil {
180		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "Delete", resp, "Failure responding to request")
181		return
182	}
183
184	return
185}
186
187// DeletePreparer prepares the Delete request.
188func (client RunbookClient) DeletePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (*http.Request, error) {
189	pathParameters := map[string]interface{}{
190		"automationAccountName": autorest.Encode("path", automationAccountName),
191		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
192		"runbookName":           autorest.Encode("path", runbookName),
193		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
194	}
195
196	const APIVersion = "2015-10-31"
197	queryParameters := map[string]interface{}{
198		"api-version": APIVersion,
199	}
200
201	preparer := autorest.CreatePreparer(
202		autorest.AsDelete(),
203		autorest.WithBaseURL(client.BaseURI),
204		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}", pathParameters),
205		autorest.WithQueryParameters(queryParameters))
206	return preparer.Prepare((&http.Request{}).WithContext(ctx))
207}
208
209// DeleteSender sends the Delete request. The method will close the
210// http.Response Body if it receives an error.
211func (client RunbookClient) DeleteSender(req *http.Request) (*http.Response, error) {
212	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
213}
214
215// DeleteResponder handles the response to the Delete request. The method always
216// closes the http.Response Body.
217func (client RunbookClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
218	err = autorest.Respond(
219		resp,
220		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
221		autorest.ByClosing())
222	result.Response = resp
223	return
224}
225
226// Get retrieve the runbook identified by runbook name.
227// Parameters:
228// resourceGroupName - name of an Azure Resource group.
229// automationAccountName - the name of the automation account.
230// runbookName - the runbook name.
231func (client RunbookClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (result Runbook, err error) {
232	if tracing.IsEnabled() {
233		ctx = tracing.StartSpan(ctx, fqdn+"/RunbookClient.Get")
234		defer func() {
235			sc := -1
236			if result.Response.Response != nil {
237				sc = result.Response.Response.StatusCode
238			}
239			tracing.EndSpan(ctx, sc, err)
240		}()
241	}
242	if err := validation.Validate([]validation.Validation{
243		{TargetValue: resourceGroupName,
244			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
245				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
246				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
247		return result, validation.NewError("automation.RunbookClient", "Get", err.Error())
248	}
249
250	req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, runbookName)
251	if err != nil {
252		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "Get", nil, "Failure preparing request")
253		return
254	}
255
256	resp, err := client.GetSender(req)
257	if err != nil {
258		result.Response = autorest.Response{Response: resp}
259		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "Get", resp, "Failure sending request")
260		return
261	}
262
263	result, err = client.GetResponder(resp)
264	if err != nil {
265		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "Get", resp, "Failure responding to request")
266		return
267	}
268
269	return
270}
271
272// GetPreparer prepares the Get request.
273func (client RunbookClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (*http.Request, error) {
274	pathParameters := map[string]interface{}{
275		"automationAccountName": autorest.Encode("path", automationAccountName),
276		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
277		"runbookName":           autorest.Encode("path", runbookName),
278		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
279	}
280
281	const APIVersion = "2015-10-31"
282	queryParameters := map[string]interface{}{
283		"api-version": APIVersion,
284	}
285
286	preparer := autorest.CreatePreparer(
287		autorest.AsGet(),
288		autorest.WithBaseURL(client.BaseURI),
289		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}", pathParameters),
290		autorest.WithQueryParameters(queryParameters))
291	return preparer.Prepare((&http.Request{}).WithContext(ctx))
292}
293
294// GetSender sends the Get request. The method will close the
295// http.Response Body if it receives an error.
296func (client RunbookClient) GetSender(req *http.Request) (*http.Response, error) {
297	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
298}
299
300// GetResponder handles the response to the Get request. The method always
301// closes the http.Response Body.
302func (client RunbookClient) GetResponder(resp *http.Response) (result Runbook, err error) {
303	err = autorest.Respond(
304		resp,
305		azure.WithErrorUnlessStatusCode(http.StatusOK),
306		autorest.ByUnmarshallingJSON(&result),
307		autorest.ByClosing())
308	result.Response = autorest.Response{Response: resp}
309	return
310}
311
312// GetContent retrieve the content of runbook identified by runbook name.
313// Parameters:
314// resourceGroupName - name of an Azure Resource group.
315// automationAccountName - the name of the automation account.
316// runbookName - the runbook name.
317func (client RunbookClient) GetContent(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (result ReadCloser, err error) {
318	if tracing.IsEnabled() {
319		ctx = tracing.StartSpan(ctx, fqdn+"/RunbookClient.GetContent")
320		defer func() {
321			sc := -1
322			if result.Response.Response != nil {
323				sc = result.Response.Response.StatusCode
324			}
325			tracing.EndSpan(ctx, sc, err)
326		}()
327	}
328	if err := validation.Validate([]validation.Validation{
329		{TargetValue: resourceGroupName,
330			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
331				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
332				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
333		return result, validation.NewError("automation.RunbookClient", "GetContent", err.Error())
334	}
335
336	req, err := client.GetContentPreparer(ctx, resourceGroupName, automationAccountName, runbookName)
337	if err != nil {
338		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "GetContent", nil, "Failure preparing request")
339		return
340	}
341
342	resp, err := client.GetContentSender(req)
343	if err != nil {
344		result.Response = autorest.Response{Response: resp}
345		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "GetContent", resp, "Failure sending request")
346		return
347	}
348
349	result, err = client.GetContentResponder(resp)
350	if err != nil {
351		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "GetContent", resp, "Failure responding to request")
352		return
353	}
354
355	return
356}
357
358// GetContentPreparer prepares the GetContent request.
359func (client RunbookClient) GetContentPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (*http.Request, error) {
360	pathParameters := map[string]interface{}{
361		"automationAccountName": autorest.Encode("path", automationAccountName),
362		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
363		"runbookName":           autorest.Encode("path", runbookName),
364		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
365	}
366
367	const APIVersion = "2015-10-31"
368	queryParameters := map[string]interface{}{
369		"api-version": APIVersion,
370	}
371
372	preparer := autorest.CreatePreparer(
373		autorest.AsGet(),
374		autorest.WithBaseURL(client.BaseURI),
375		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/content", pathParameters),
376		autorest.WithQueryParameters(queryParameters))
377	return preparer.Prepare((&http.Request{}).WithContext(ctx))
378}
379
380// GetContentSender sends the GetContent request. The method will close the
381// http.Response Body if it receives an error.
382func (client RunbookClient) GetContentSender(req *http.Request) (*http.Response, error) {
383	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
384}
385
386// GetContentResponder handles the response to the GetContent request. The method always
387// closes the http.Response Body.
388func (client RunbookClient) GetContentResponder(resp *http.Response) (result ReadCloser, err error) {
389	result.Value = &resp.Body
390	err = autorest.Respond(
391		resp,
392		azure.WithErrorUnlessStatusCode(http.StatusOK))
393	result.Response = autorest.Response{Response: resp}
394	return
395}
396
397// ListByAutomationAccount retrieve a list of runbooks.
398// Parameters:
399// resourceGroupName - name of an Azure Resource group.
400// automationAccountName - the name of the automation account.
401func (client RunbookClient) ListByAutomationAccount(ctx context.Context, resourceGroupName string, automationAccountName string) (result RunbookListResultPage, err error) {
402	if tracing.IsEnabled() {
403		ctx = tracing.StartSpan(ctx, fqdn+"/RunbookClient.ListByAutomationAccount")
404		defer func() {
405			sc := -1
406			if result.rlr.Response.Response != nil {
407				sc = result.rlr.Response.Response.StatusCode
408			}
409			tracing.EndSpan(ctx, sc, err)
410		}()
411	}
412	if err := validation.Validate([]validation.Validation{
413		{TargetValue: resourceGroupName,
414			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
415				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
416				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
417		return result, validation.NewError("automation.RunbookClient", "ListByAutomationAccount", err.Error())
418	}
419
420	result.fn = client.listByAutomationAccountNextResults
421	req, err := client.ListByAutomationAccountPreparer(ctx, resourceGroupName, automationAccountName)
422	if err != nil {
423		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "ListByAutomationAccount", nil, "Failure preparing request")
424		return
425	}
426
427	resp, err := client.ListByAutomationAccountSender(req)
428	if err != nil {
429		result.rlr.Response = autorest.Response{Response: resp}
430		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "ListByAutomationAccount", resp, "Failure sending request")
431		return
432	}
433
434	result.rlr, err = client.ListByAutomationAccountResponder(resp)
435	if err != nil {
436		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "ListByAutomationAccount", resp, "Failure responding to request")
437		return
438	}
439	if result.rlr.hasNextLink() && result.rlr.IsEmpty() {
440		err = result.NextWithContext(ctx)
441		return
442	}
443
444	return
445}
446
447// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request.
448func (client RunbookClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string) (*http.Request, error) {
449	pathParameters := map[string]interface{}{
450		"automationAccountName": autorest.Encode("path", automationAccountName),
451		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
452		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
453	}
454
455	const APIVersion = "2015-10-31"
456	queryParameters := map[string]interface{}{
457		"api-version": APIVersion,
458	}
459
460	preparer := autorest.CreatePreparer(
461		autorest.AsGet(),
462		autorest.WithBaseURL(client.BaseURI),
463		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks", pathParameters),
464		autorest.WithQueryParameters(queryParameters))
465	return preparer.Prepare((&http.Request{}).WithContext(ctx))
466}
467
468// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the
469// http.Response Body if it receives an error.
470func (client RunbookClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) {
471	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
472}
473
474// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always
475// closes the http.Response Body.
476func (client RunbookClient) ListByAutomationAccountResponder(resp *http.Response) (result RunbookListResult, err error) {
477	err = autorest.Respond(
478		resp,
479		azure.WithErrorUnlessStatusCode(http.StatusOK),
480		autorest.ByUnmarshallingJSON(&result),
481		autorest.ByClosing())
482	result.Response = autorest.Response{Response: resp}
483	return
484}
485
486// listByAutomationAccountNextResults retrieves the next set of results, if any.
487func (client RunbookClient) listByAutomationAccountNextResults(ctx context.Context, lastResults RunbookListResult) (result RunbookListResult, err error) {
488	req, err := lastResults.runbookListResultPreparer(ctx)
489	if err != nil {
490		return result, autorest.NewErrorWithError(err, "automation.RunbookClient", "listByAutomationAccountNextResults", nil, "Failure preparing next results request")
491	}
492	if req == nil {
493		return
494	}
495	resp, err := client.ListByAutomationAccountSender(req)
496	if err != nil {
497		result.Response = autorest.Response{Response: resp}
498		return result, autorest.NewErrorWithError(err, "automation.RunbookClient", "listByAutomationAccountNextResults", resp, "Failure sending next results request")
499	}
500	result, err = client.ListByAutomationAccountResponder(resp)
501	if err != nil {
502		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "listByAutomationAccountNextResults", resp, "Failure responding to next results request")
503	}
504	return
505}
506
507// ListByAutomationAccountComplete enumerates all values, automatically crossing page boundaries as required.
508func (client RunbookClient) ListByAutomationAccountComplete(ctx context.Context, resourceGroupName string, automationAccountName string) (result RunbookListResultIterator, err error) {
509	if tracing.IsEnabled() {
510		ctx = tracing.StartSpan(ctx, fqdn+"/RunbookClient.ListByAutomationAccount")
511		defer func() {
512			sc := -1
513			if result.Response().Response.Response != nil {
514				sc = result.page.Response().Response.Response.StatusCode
515			}
516			tracing.EndSpan(ctx, sc, err)
517		}()
518	}
519	result.page, err = client.ListByAutomationAccount(ctx, resourceGroupName, automationAccountName)
520	return
521}
522
523// Update update the runbook identified by runbook name.
524// Parameters:
525// resourceGroupName - name of an Azure Resource group.
526// automationAccountName - the name of the automation account.
527// runbookName - the runbook name.
528// parameters - the update parameters for runbook.
529func (client RunbookClient) Update(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, parameters RunbookUpdateParameters) (result Runbook, err error) {
530	if tracing.IsEnabled() {
531		ctx = tracing.StartSpan(ctx, fqdn+"/RunbookClient.Update")
532		defer func() {
533			sc := -1
534			if result.Response.Response != nil {
535				sc = result.Response.Response.StatusCode
536			}
537			tracing.EndSpan(ctx, sc, err)
538		}()
539	}
540	if err := validation.Validate([]validation.Validation{
541		{TargetValue: resourceGroupName,
542			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
543				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
544				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
545		return result, validation.NewError("automation.RunbookClient", "Update", err.Error())
546	}
547
548	req, err := client.UpdatePreparer(ctx, resourceGroupName, automationAccountName, runbookName, parameters)
549	if err != nil {
550		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "Update", nil, "Failure preparing request")
551		return
552	}
553
554	resp, err := client.UpdateSender(req)
555	if err != nil {
556		result.Response = autorest.Response{Response: resp}
557		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "Update", resp, "Failure sending request")
558		return
559	}
560
561	result, err = client.UpdateResponder(resp)
562	if err != nil {
563		err = autorest.NewErrorWithError(err, "automation.RunbookClient", "Update", resp, "Failure responding to request")
564		return
565	}
566
567	return
568}
569
570// UpdatePreparer prepares the Update request.
571func (client RunbookClient) UpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, parameters RunbookUpdateParameters) (*http.Request, error) {
572	pathParameters := map[string]interface{}{
573		"automationAccountName": autorest.Encode("path", automationAccountName),
574		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
575		"runbookName":           autorest.Encode("path", runbookName),
576		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
577	}
578
579	const APIVersion = "2015-10-31"
580	queryParameters := map[string]interface{}{
581		"api-version": APIVersion,
582	}
583
584	preparer := autorest.CreatePreparer(
585		autorest.AsContentType("application/json; charset=utf-8"),
586		autorest.AsPatch(),
587		autorest.WithBaseURL(client.BaseURI),
588		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}", pathParameters),
589		autorest.WithJSON(parameters),
590		autorest.WithQueryParameters(queryParameters))
591	return preparer.Prepare((&http.Request{}).WithContext(ctx))
592}
593
594// UpdateSender sends the Update request. The method will close the
595// http.Response Body if it receives an error.
596func (client RunbookClient) UpdateSender(req *http.Request) (*http.Response, error) {
597	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
598}
599
600// UpdateResponder handles the response to the Update request. The method always
601// closes the http.Response Body.
602func (client RunbookClient) UpdateResponder(resp *http.Response) (result Runbook, err error) {
603	err = autorest.Respond(
604		resp,
605		azure.WithErrorUnlessStatusCode(http.StatusOK),
606		autorest.ByUnmarshallingJSON(&result),
607		autorest.ByClosing())
608	result.Response = autorest.Response{Response: resp}
609	return
610}
611