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	}
87
88	return
89}
90
91// DeletePreparer prepares the Delete request.
92func (client HybridRunbookWorkerGroupClient) DeletePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, hybridRunbookWorkerGroupName string) (*http.Request, error) {
93	pathParameters := map[string]interface{}{
94		"automationAccountName":        autorest.Encode("path", automationAccountName),
95		"hybridRunbookWorkerGroupName": autorest.Encode("path", hybridRunbookWorkerGroupName),
96		"resourceGroupName":            autorest.Encode("path", resourceGroupName),
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.AsDelete(),
107		autorest.WithBaseURL(client.BaseURI),
108		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/hybridRunbookWorkerGroups/{hybridRunbookWorkerGroupName}", pathParameters),
109		autorest.WithQueryParameters(queryParameters))
110	return preparer.Prepare((&http.Request{}).WithContext(ctx))
111}
112
113// DeleteSender sends the Delete request. The method will close the
114// http.Response Body if it receives an error.
115func (client HybridRunbookWorkerGroupClient) DeleteSender(req *http.Request) (*http.Response, error) {
116	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
117}
118
119// DeleteResponder handles the response to the Delete request. The method always
120// closes the http.Response Body.
121func (client HybridRunbookWorkerGroupClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
122	err = autorest.Respond(
123		resp,
124		client.ByInspecting(),
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	}
172
173	return
174}
175
176// GetPreparer prepares the Get request.
177func (client HybridRunbookWorkerGroupClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, hybridRunbookWorkerGroupName string) (*http.Request, error) {
178	pathParameters := map[string]interface{}{
179		"automationAccountName":        autorest.Encode("path", automationAccountName),
180		"hybridRunbookWorkerGroupName": autorest.Encode("path", hybridRunbookWorkerGroupName),
181		"resourceGroupName":            autorest.Encode("path", resourceGroupName),
182		"subscriptionId":               autorest.Encode("path", client.SubscriptionID),
183	}
184
185	const APIVersion = "2015-10-31"
186	queryParameters := map[string]interface{}{
187		"api-version": APIVersion,
188	}
189
190	preparer := autorest.CreatePreparer(
191		autorest.AsGet(),
192		autorest.WithBaseURL(client.BaseURI),
193		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/hybridRunbookWorkerGroups/{hybridRunbookWorkerGroupName}", pathParameters),
194		autorest.WithQueryParameters(queryParameters))
195	return preparer.Prepare((&http.Request{}).WithContext(ctx))
196}
197
198// GetSender sends the Get request. The method will close the
199// http.Response Body if it receives an error.
200func (client HybridRunbookWorkerGroupClient) GetSender(req *http.Request) (*http.Response, error) {
201	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
202}
203
204// GetResponder handles the response to the Get request. The method always
205// closes the http.Response Body.
206func (client HybridRunbookWorkerGroupClient) GetResponder(resp *http.Response) (result HybridRunbookWorkerGroup, err error) {
207	err = autorest.Respond(
208		resp,
209		client.ByInspecting(),
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	}
259
260	return
261}
262
263// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request.
264func (client HybridRunbookWorkerGroupClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (*http.Request, error) {
265	pathParameters := map[string]interface{}{
266		"automationAccountName": autorest.Encode("path", automationAccountName),
267		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
268		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
269	}
270
271	const APIVersion = "2015-10-31"
272	queryParameters := map[string]interface{}{
273		"api-version": APIVersion,
274	}
275	if len(filter) > 0 {
276		queryParameters["$filter"] = autorest.Encode("query", filter)
277	}
278
279	preparer := autorest.CreatePreparer(
280		autorest.AsGet(),
281		autorest.WithBaseURL(client.BaseURI),
282		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/hybridRunbookWorkerGroups", pathParameters),
283		autorest.WithQueryParameters(queryParameters))
284	return preparer.Prepare((&http.Request{}).WithContext(ctx))
285}
286
287// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the
288// http.Response Body if it receives an error.
289func (client HybridRunbookWorkerGroupClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) {
290	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
291}
292
293// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always
294// closes the http.Response Body.
295func (client HybridRunbookWorkerGroupClient) ListByAutomationAccountResponder(resp *http.Response) (result HybridRunbookWorkerGroupsListResult, err error) {
296	err = autorest.Respond(
297		resp,
298		client.ByInspecting(),
299		azure.WithErrorUnlessStatusCode(http.StatusOK),
300		autorest.ByUnmarshallingJSON(&result),
301		autorest.ByClosing())
302	result.Response = autorest.Response{Response: resp}
303	return
304}
305
306// listByAutomationAccountNextResults retrieves the next set of results, if any.
307func (client HybridRunbookWorkerGroupClient) listByAutomationAccountNextResults(ctx context.Context, lastResults HybridRunbookWorkerGroupsListResult) (result HybridRunbookWorkerGroupsListResult, err error) {
308	req, err := lastResults.hybridRunbookWorkerGroupsListResultPreparer(ctx)
309	if err != nil {
310		return result, autorest.NewErrorWithError(err, "automation.HybridRunbookWorkerGroupClient", "listByAutomationAccountNextResults", nil, "Failure preparing next results request")
311	}
312	if req == nil {
313		return
314	}
315	resp, err := client.ListByAutomationAccountSender(req)
316	if err != nil {
317		result.Response = autorest.Response{Response: resp}
318		return result, autorest.NewErrorWithError(err, "automation.HybridRunbookWorkerGroupClient", "listByAutomationAccountNextResults", resp, "Failure sending next results request")
319	}
320	result, err = client.ListByAutomationAccountResponder(resp)
321	if err != nil {
322		err = autorest.NewErrorWithError(err, "automation.HybridRunbookWorkerGroupClient", "listByAutomationAccountNextResults", resp, "Failure responding to next results request")
323	}
324	return
325}
326
327// ListByAutomationAccountComplete enumerates all values, automatically crossing page boundaries as required.
328func (client HybridRunbookWorkerGroupClient) ListByAutomationAccountComplete(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (result HybridRunbookWorkerGroupsListResultIterator, err error) {
329	if tracing.IsEnabled() {
330		ctx = tracing.StartSpan(ctx, fqdn+"/HybridRunbookWorkerGroupClient.ListByAutomationAccount")
331		defer func() {
332			sc := -1
333			if result.Response().Response.Response != nil {
334				sc = result.page.Response().Response.Response.StatusCode
335			}
336			tracing.EndSpan(ctx, sc, err)
337		}()
338	}
339	result.page, err = client.ListByAutomationAccount(ctx, resourceGroupName, automationAccountName, filter)
340	return
341}
342
343// Update update a hybrid runbook worker group.
344// Parameters:
345// resourceGroupName - name of an Azure Resource group.
346// automationAccountName - the name of the automation account.
347// hybridRunbookWorkerGroupName - the hybrid runbook worker group name
348// parameters - the hybrid runbook worker group
349func (client HybridRunbookWorkerGroupClient) Update(ctx context.Context, resourceGroupName string, automationAccountName string, hybridRunbookWorkerGroupName string, parameters HybridRunbookWorkerGroupUpdateParameters) (result HybridRunbookWorkerGroup, err error) {
350	if tracing.IsEnabled() {
351		ctx = tracing.StartSpan(ctx, fqdn+"/HybridRunbookWorkerGroupClient.Update")
352		defer func() {
353			sc := -1
354			if result.Response.Response != nil {
355				sc = result.Response.Response.StatusCode
356			}
357			tracing.EndSpan(ctx, sc, err)
358		}()
359	}
360	if err := validation.Validate([]validation.Validation{
361		{TargetValue: resourceGroupName,
362			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
363				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
364				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
365		return result, validation.NewError("automation.HybridRunbookWorkerGroupClient", "Update", err.Error())
366	}
367
368	req, err := client.UpdatePreparer(ctx, resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, parameters)
369	if err != nil {
370		err = autorest.NewErrorWithError(err, "automation.HybridRunbookWorkerGroupClient", "Update", nil, "Failure preparing request")
371		return
372	}
373
374	resp, err := client.UpdateSender(req)
375	if err != nil {
376		result.Response = autorest.Response{Response: resp}
377		err = autorest.NewErrorWithError(err, "automation.HybridRunbookWorkerGroupClient", "Update", resp, "Failure sending request")
378		return
379	}
380
381	result, err = client.UpdateResponder(resp)
382	if err != nil {
383		err = autorest.NewErrorWithError(err, "automation.HybridRunbookWorkerGroupClient", "Update", resp, "Failure responding to request")
384	}
385
386	return
387}
388
389// UpdatePreparer prepares the Update request.
390func (client HybridRunbookWorkerGroupClient) UpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, hybridRunbookWorkerGroupName string, parameters HybridRunbookWorkerGroupUpdateParameters) (*http.Request, error) {
391	pathParameters := map[string]interface{}{
392		"automationAccountName":        autorest.Encode("path", automationAccountName),
393		"hybridRunbookWorkerGroupName": autorest.Encode("path", hybridRunbookWorkerGroupName),
394		"resourceGroupName":            autorest.Encode("path", resourceGroupName),
395		"subscriptionId":               autorest.Encode("path", client.SubscriptionID),
396	}
397
398	const APIVersion = "2015-10-31"
399	queryParameters := map[string]interface{}{
400		"api-version": APIVersion,
401	}
402
403	preparer := autorest.CreatePreparer(
404		autorest.AsContentType("application/json; charset=utf-8"),
405		autorest.AsPatch(),
406		autorest.WithBaseURL(client.BaseURI),
407		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/hybridRunbookWorkerGroups/{hybridRunbookWorkerGroupName}", pathParameters),
408		autorest.WithJSON(parameters),
409		autorest.WithQueryParameters(queryParameters))
410	return preparer.Prepare((&http.Request{}).WithContext(ctx))
411}
412
413// UpdateSender sends the Update request. The method will close the
414// http.Response Body if it receives an error.
415func (client HybridRunbookWorkerGroupClient) UpdateSender(req *http.Request) (*http.Response, error) {
416	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
417}
418
419// UpdateResponder handles the response to the Update request. The method always
420// closes the http.Response Body.
421func (client HybridRunbookWorkerGroupClient) UpdateResponder(resp *http.Response) (result HybridRunbookWorkerGroup, err error) {
422	err = autorest.Respond(
423		resp,
424		client.ByInspecting(),
425		azure.WithErrorUnlessStatusCode(http.StatusOK),
426		autorest.ByUnmarshallingJSON(&result),
427		autorest.ByClosing())
428	result.Response = autorest.Response{Response: resp}
429	return
430}
431