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	"net/http"
26)
27
28// DscNodeClient is the automation Client
29type DscNodeClient struct {
30	BaseClient
31}
32
33// NewDscNodeClient creates an instance of the DscNodeClient client.
34func NewDscNodeClient(subscriptionID string, countType1 CountType) DscNodeClient {
35	return NewDscNodeClientWithBaseURI(DefaultBaseURI, subscriptionID, countType1)
36}
37
38// NewDscNodeClientWithBaseURI creates an instance of the DscNodeClient client.
39func NewDscNodeClientWithBaseURI(baseURI string, subscriptionID string, countType1 CountType) DscNodeClient {
40	return DscNodeClient{NewWithBaseURI(baseURI, subscriptionID, countType1)}
41}
42
43// Delete delete the dsc node identified by node id.
44// Parameters:
45// resourceGroupName - name of an Azure Resource group.
46// automationAccountName - the name of the automation account.
47// nodeID - the node id.
48func (client DscNodeClient) Delete(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string) (result DscNode, err error) {
49	if err := validation.Validate([]validation.Validation{
50		{TargetValue: resourceGroupName,
51			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
52				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
53				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
54		return result, validation.NewError("automation.DscNodeClient", "Delete", err.Error())
55	}
56
57	req, err := client.DeletePreparer(ctx, resourceGroupName, automationAccountName, nodeID)
58	if err != nil {
59		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Delete", nil, "Failure preparing request")
60		return
61	}
62
63	resp, err := client.DeleteSender(req)
64	if err != nil {
65		result.Response = autorest.Response{Response: resp}
66		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Delete", resp, "Failure sending request")
67		return
68	}
69
70	result, err = client.DeleteResponder(resp)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Delete", resp, "Failure responding to request")
73	}
74
75	return
76}
77
78// DeletePreparer prepares the Delete request.
79func (client DscNodeClient) DeletePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string) (*http.Request, error) {
80	pathParameters := map[string]interface{}{
81		"automationAccountName": autorest.Encode("path", automationAccountName),
82		"nodeId":                autorest.Encode("path", nodeID),
83		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
84		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
85	}
86
87	const APIVersion = "2018-01-15"
88	queryParameters := map[string]interface{}{
89		"api-version": APIVersion,
90	}
91
92	preparer := autorest.CreatePreparer(
93		autorest.AsDelete(),
94		autorest.WithBaseURL(client.BaseURI),
95		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/nodes/{nodeId}", pathParameters),
96		autorest.WithQueryParameters(queryParameters))
97	return preparer.Prepare((&http.Request{}).WithContext(ctx))
98}
99
100// DeleteSender sends the Delete request. The method will close the
101// http.Response Body if it receives an error.
102func (client DscNodeClient) DeleteSender(req *http.Request) (*http.Response, error) {
103	return autorest.SendWithSender(client, req,
104		azure.DoRetryWithRegistration(client.Client))
105}
106
107// DeleteResponder handles the response to the Delete request. The method always
108// closes the http.Response Body.
109func (client DscNodeClient) DeleteResponder(resp *http.Response) (result DscNode, err error) {
110	err = autorest.Respond(
111		resp,
112		client.ByInspecting(),
113		azure.WithErrorUnlessStatusCode(http.StatusOK),
114		autorest.ByUnmarshallingJSON(&result),
115		autorest.ByClosing())
116	result.Response = autorest.Response{Response: resp}
117	return
118}
119
120// Get retrieve the dsc node identified by node id.
121// Parameters:
122// resourceGroupName - name of an Azure Resource group.
123// automationAccountName - the name of the automation account.
124// nodeID - the node id.
125func (client DscNodeClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string) (result DscNode, err error) {
126	if err := validation.Validate([]validation.Validation{
127		{TargetValue: resourceGroupName,
128			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
129				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
130				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
131		return result, validation.NewError("automation.DscNodeClient", "Get", err.Error())
132	}
133
134	req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, nodeID)
135	if err != nil {
136		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Get", nil, "Failure preparing request")
137		return
138	}
139
140	resp, err := client.GetSender(req)
141	if err != nil {
142		result.Response = autorest.Response{Response: resp}
143		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Get", resp, "Failure sending request")
144		return
145	}
146
147	result, err = client.GetResponder(resp)
148	if err != nil {
149		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Get", resp, "Failure responding to request")
150	}
151
152	return
153}
154
155// GetPreparer prepares the Get request.
156func (client DscNodeClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string) (*http.Request, error) {
157	pathParameters := map[string]interface{}{
158		"automationAccountName": autorest.Encode("path", automationAccountName),
159		"nodeId":                autorest.Encode("path", nodeID),
160		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
161		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
162	}
163
164	const APIVersion = "2018-01-15"
165	queryParameters := map[string]interface{}{
166		"api-version": APIVersion,
167	}
168
169	preparer := autorest.CreatePreparer(
170		autorest.AsGet(),
171		autorest.WithBaseURL(client.BaseURI),
172		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/nodes/{nodeId}", pathParameters),
173		autorest.WithQueryParameters(queryParameters))
174	return preparer.Prepare((&http.Request{}).WithContext(ctx))
175}
176
177// GetSender sends the Get request. The method will close the
178// http.Response Body if it receives an error.
179func (client DscNodeClient) GetSender(req *http.Request) (*http.Response, error) {
180	return autorest.SendWithSender(client, req,
181		azure.DoRetryWithRegistration(client.Client))
182}
183
184// GetResponder handles the response to the Get request. The method always
185// closes the http.Response Body.
186func (client DscNodeClient) GetResponder(resp *http.Response) (result DscNode, err error) {
187	err = autorest.Respond(
188		resp,
189		client.ByInspecting(),
190		azure.WithErrorUnlessStatusCode(http.StatusOK),
191		autorest.ByUnmarshallingJSON(&result),
192		autorest.ByClosing())
193	result.Response = autorest.Response{Response: resp}
194	return
195}
196
197// ListByAutomationAccount retrieve a list of dsc nodes.
198// Parameters:
199// resourceGroupName - name of an Azure Resource group.
200// automationAccountName - the name of the automation account.
201// filter - the filter to apply on the operation.
202// skip - the number of rows to skip.
203// top - the the number of rows to take.
204// inlinecount - return total rows.
205func (client DscNodeClient) ListByAutomationAccount(ctx context.Context, resourceGroupName string, automationAccountName string, filter string, skip *int32, top *int32, inlinecount string) (result DscNodeListResultPage, err error) {
206	if err := validation.Validate([]validation.Validation{
207		{TargetValue: resourceGroupName,
208			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
209				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
210				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
211		return result, validation.NewError("automation.DscNodeClient", "ListByAutomationAccount", err.Error())
212	}
213
214	result.fn = client.listByAutomationAccountNextResults
215	req, err := client.ListByAutomationAccountPreparer(ctx, resourceGroupName, automationAccountName, filter, skip, top, inlinecount)
216	if err != nil {
217		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "ListByAutomationAccount", nil, "Failure preparing request")
218		return
219	}
220
221	resp, err := client.ListByAutomationAccountSender(req)
222	if err != nil {
223		result.dnlr.Response = autorest.Response{Response: resp}
224		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "ListByAutomationAccount", resp, "Failure sending request")
225		return
226	}
227
228	result.dnlr, err = client.ListByAutomationAccountResponder(resp)
229	if err != nil {
230		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "ListByAutomationAccount", resp, "Failure responding to request")
231	}
232
233	return
234}
235
236// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request.
237func (client DscNodeClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, filter string, skip *int32, top *int32, inlinecount string) (*http.Request, error) {
238	pathParameters := map[string]interface{}{
239		"automationAccountName": autorest.Encode("path", automationAccountName),
240		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
241		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
242	}
243
244	const APIVersion = "2018-01-15"
245	queryParameters := map[string]interface{}{
246		"api-version": APIVersion,
247	}
248	if len(filter) > 0 {
249		queryParameters["$filter"] = autorest.Encode("query", filter)
250	}
251	if skip != nil {
252		queryParameters["$skip"] = autorest.Encode("query", *skip)
253	}
254	if top != nil {
255		queryParameters["$top"] = autorest.Encode("query", *top)
256	}
257	if len(inlinecount) > 0 {
258		queryParameters["$inlinecount"] = autorest.Encode("query", inlinecount)
259	}
260
261	preparer := autorest.CreatePreparer(
262		autorest.AsGet(),
263		autorest.WithBaseURL(client.BaseURI),
264		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/nodes", pathParameters),
265		autorest.WithQueryParameters(queryParameters))
266	return preparer.Prepare((&http.Request{}).WithContext(ctx))
267}
268
269// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the
270// http.Response Body if it receives an error.
271func (client DscNodeClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) {
272	return autorest.SendWithSender(client, req,
273		azure.DoRetryWithRegistration(client.Client))
274}
275
276// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always
277// closes the http.Response Body.
278func (client DscNodeClient) ListByAutomationAccountResponder(resp *http.Response) (result DscNodeListResult, err error) {
279	err = autorest.Respond(
280		resp,
281		client.ByInspecting(),
282		azure.WithErrorUnlessStatusCode(http.StatusOK),
283		autorest.ByUnmarshallingJSON(&result),
284		autorest.ByClosing())
285	result.Response = autorest.Response{Response: resp}
286	return
287}
288
289// listByAutomationAccountNextResults retrieves the next set of results, if any.
290func (client DscNodeClient) listByAutomationAccountNextResults(lastResults DscNodeListResult) (result DscNodeListResult, err error) {
291	req, err := lastResults.dscNodeListResultPreparer()
292	if err != nil {
293		return result, autorest.NewErrorWithError(err, "automation.DscNodeClient", "listByAutomationAccountNextResults", nil, "Failure preparing next results request")
294	}
295	if req == nil {
296		return
297	}
298	resp, err := client.ListByAutomationAccountSender(req)
299	if err != nil {
300		result.Response = autorest.Response{Response: resp}
301		return result, autorest.NewErrorWithError(err, "automation.DscNodeClient", "listByAutomationAccountNextResults", resp, "Failure sending next results request")
302	}
303	result, err = client.ListByAutomationAccountResponder(resp)
304	if err != nil {
305		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "listByAutomationAccountNextResults", resp, "Failure responding to next results request")
306	}
307	return
308}
309
310// ListByAutomationAccountComplete enumerates all values, automatically crossing page boundaries as required.
311func (client DscNodeClient) ListByAutomationAccountComplete(ctx context.Context, resourceGroupName string, automationAccountName string, filter string, skip *int32, top *int32, inlinecount string) (result DscNodeListResultIterator, err error) {
312	result.page, err = client.ListByAutomationAccount(ctx, resourceGroupName, automationAccountName, filter, skip, top, inlinecount)
313	return
314}
315
316// Update update the dsc node.
317// Parameters:
318// resourceGroupName - name of an Azure Resource group.
319// automationAccountName - the name of the automation account.
320// nodeID - parameters supplied to the update dsc node.
321// dscNodeUpdateParameters - parameters supplied to the update dsc node.
322func (client DscNodeClient) Update(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string, dscNodeUpdateParameters DscNodeUpdateParameters) (result DscNode, err error) {
323	if err := validation.Validate([]validation.Validation{
324		{TargetValue: resourceGroupName,
325			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
326				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
327				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
328		return result, validation.NewError("automation.DscNodeClient", "Update", err.Error())
329	}
330
331	req, err := client.UpdatePreparer(ctx, resourceGroupName, automationAccountName, nodeID, dscNodeUpdateParameters)
332	if err != nil {
333		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Update", nil, "Failure preparing request")
334		return
335	}
336
337	resp, err := client.UpdateSender(req)
338	if err != nil {
339		result.Response = autorest.Response{Response: resp}
340		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Update", resp, "Failure sending request")
341		return
342	}
343
344	result, err = client.UpdateResponder(resp)
345	if err != nil {
346		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Update", resp, "Failure responding to request")
347	}
348
349	return
350}
351
352// UpdatePreparer prepares the Update request.
353func (client DscNodeClient) UpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string, dscNodeUpdateParameters DscNodeUpdateParameters) (*http.Request, error) {
354	pathParameters := map[string]interface{}{
355		"automationAccountName": autorest.Encode("path", automationAccountName),
356		"nodeId":                autorest.Encode("path", nodeID),
357		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
358		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
359	}
360
361	const APIVersion = "2018-01-15"
362	queryParameters := map[string]interface{}{
363		"api-version": APIVersion,
364	}
365
366	preparer := autorest.CreatePreparer(
367		autorest.AsContentType("application/json; charset=utf-8"),
368		autorest.AsPatch(),
369		autorest.WithBaseURL(client.BaseURI),
370		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/nodes/{nodeId}", pathParameters),
371		autorest.WithJSON(dscNodeUpdateParameters),
372		autorest.WithQueryParameters(queryParameters))
373	return preparer.Prepare((&http.Request{}).WithContext(ctx))
374}
375
376// UpdateSender sends the Update request. The method will close the
377// http.Response Body if it receives an error.
378func (client DscNodeClient) UpdateSender(req *http.Request) (*http.Response, error) {
379	return autorest.SendWithSender(client, req,
380		azure.DoRetryWithRegistration(client.Client))
381}
382
383// UpdateResponder handles the response to the Update request. The method always
384// closes the http.Response Body.
385func (client DscNodeClient) UpdateResponder(resp *http.Response) (result DscNode, err error) {
386	err = autorest.Respond(
387		resp,
388		client.ByInspecting(),
389		azure.WithErrorUnlessStatusCode(http.StatusOK),
390		autorest.ByUnmarshallingJSON(&result),
391		autorest.ByClosing())
392	result.Response = autorest.Response{Response: resp}
393	return
394}
395