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