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// DscNodeClient is the automation Client
30type DscNodeClient struct {
31	BaseClient
32}
33
34// NewDscNodeClient creates an instance of the DscNodeClient client.
35func NewDscNodeClient(subscriptionID string) DscNodeClient {
36	return NewDscNodeClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewDscNodeClientWithBaseURI creates an instance of the DscNodeClient client using a custom endpoint.  Use this when
40// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewDscNodeClientWithBaseURI(baseURI string, subscriptionID string) DscNodeClient {
42	return DscNodeClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Delete delete the dsc node identified by node id.
46// Parameters:
47// resourceGroupName - name of an Azure Resource group.
48// automationAccountName - the name of the automation account.
49// nodeID - the node id.
50func (client DscNodeClient) Delete(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string) (result DscNode, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/DscNodeClient.Delete")
53		defer func() {
54			sc := -1
55			if result.Response.Response != nil {
56				sc = result.Response.Response.StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	if err := validation.Validate([]validation.Validation{
62		{TargetValue: resourceGroupName,
63			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
64				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
65				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
66		return result, validation.NewError("automation.DscNodeClient", "Delete", err.Error())
67	}
68
69	req, err := client.DeletePreparer(ctx, resourceGroupName, automationAccountName, nodeID)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Delete", nil, "Failure preparing request")
72		return
73	}
74
75	resp, err := client.DeleteSender(req)
76	if err != nil {
77		result.Response = autorest.Response{Response: resp}
78		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Delete", resp, "Failure sending request")
79		return
80	}
81
82	result, err = client.DeleteResponder(resp)
83	if err != nil {
84		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Delete", resp, "Failure responding to request")
85	}
86
87	return
88}
89
90// DeletePreparer prepares the Delete request.
91func (client DscNodeClient) DeletePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string) (*http.Request, error) {
92	pathParameters := map[string]interface{}{
93		"automationAccountName": autorest.Encode("path", automationAccountName),
94		"nodeId":                autorest.Encode("path", nodeID),
95		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
96		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
97	}
98
99	const APIVersion = "2018-01-15"
100	queryParameters := map[string]interface{}{
101		"api-version": APIVersion,
102	}
103
104	preparer := autorest.CreatePreparer(
105		autorest.AsDelete(),
106		autorest.WithBaseURL(client.BaseURI),
107		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/nodes/{nodeId}", pathParameters),
108		autorest.WithQueryParameters(queryParameters))
109	return preparer.Prepare((&http.Request{}).WithContext(ctx))
110}
111
112// DeleteSender sends the Delete request. The method will close the
113// http.Response Body if it receives an error.
114func (client DscNodeClient) DeleteSender(req *http.Request) (*http.Response, error) {
115	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
116}
117
118// DeleteResponder handles the response to the Delete request. The method always
119// closes the http.Response Body.
120func (client DscNodeClient) DeleteResponder(resp *http.Response) (result DscNode, err error) {
121	err = autorest.Respond(
122		resp,
123		client.ByInspecting(),
124		azure.WithErrorUnlessStatusCode(http.StatusOK),
125		autorest.ByUnmarshallingJSON(&result),
126		autorest.ByClosing())
127	result.Response = autorest.Response{Response: resp}
128	return
129}
130
131// Get retrieve the dsc node identified by node id.
132// Parameters:
133// resourceGroupName - name of an Azure Resource group.
134// automationAccountName - the name of the automation account.
135// nodeID - the node id.
136func (client DscNodeClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string) (result DscNode, err error) {
137	if tracing.IsEnabled() {
138		ctx = tracing.StartSpan(ctx, fqdn+"/DscNodeClient.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.DscNodeClient", "Get", err.Error())
153	}
154
155	req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, nodeID)
156	if err != nil {
157		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "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.DscNodeClient", "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.DscNodeClient", "Get", resp, "Failure responding to request")
171	}
172
173	return
174}
175
176// GetPreparer prepares the Get request.
177func (client DscNodeClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string) (*http.Request, error) {
178	pathParameters := map[string]interface{}{
179		"automationAccountName": autorest.Encode("path", automationAccountName),
180		"nodeId":                autorest.Encode("path", nodeID),
181		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
182		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
183	}
184
185	const APIVersion = "2018-01-15"
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}/nodes/{nodeId}", 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 DscNodeClient) 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 DscNodeClient) GetResponder(resp *http.Response) (result DscNode, 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 dsc nodes.
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.
222// skip - the number of rows to skip.
223// top - the number of rows to take.
224// inlinecount - return total rows.
225func (client DscNodeClient) ListByAutomationAccount(ctx context.Context, resourceGroupName string, automationAccountName string, filter string, skip *int32, top *int32, inlinecount string) (result DscNodeListResultPage, err error) {
226	if tracing.IsEnabled() {
227		ctx = tracing.StartSpan(ctx, fqdn+"/DscNodeClient.ListByAutomationAccount")
228		defer func() {
229			sc := -1
230			if result.dnlr.Response.Response != nil {
231				sc = result.dnlr.Response.Response.StatusCode
232			}
233			tracing.EndSpan(ctx, sc, err)
234		}()
235	}
236	if err := validation.Validate([]validation.Validation{
237		{TargetValue: resourceGroupName,
238			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
239				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
240				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
241		return result, validation.NewError("automation.DscNodeClient", "ListByAutomationAccount", err.Error())
242	}
243
244	result.fn = client.listByAutomationAccountNextResults
245	req, err := client.ListByAutomationAccountPreparer(ctx, resourceGroupName, automationAccountName, filter, skip, top, inlinecount)
246	if err != nil {
247		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "ListByAutomationAccount", nil, "Failure preparing request")
248		return
249	}
250
251	resp, err := client.ListByAutomationAccountSender(req)
252	if err != nil {
253		result.dnlr.Response = autorest.Response{Response: resp}
254		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "ListByAutomationAccount", resp, "Failure sending request")
255		return
256	}
257
258	result.dnlr, err = client.ListByAutomationAccountResponder(resp)
259	if err != nil {
260		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "ListByAutomationAccount", resp, "Failure responding to request")
261	}
262
263	return
264}
265
266// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request.
267func (client DscNodeClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, filter string, skip *int32, top *int32, inlinecount string) (*http.Request, error) {
268	pathParameters := map[string]interface{}{
269		"automationAccountName": autorest.Encode("path", automationAccountName),
270		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
271		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
272	}
273
274	const APIVersion = "2018-01-15"
275	queryParameters := map[string]interface{}{
276		"api-version": APIVersion,
277	}
278	if len(filter) > 0 {
279		queryParameters["$filter"] = autorest.Encode("query", filter)
280	}
281	if skip != nil {
282		queryParameters["$skip"] = autorest.Encode("query", *skip)
283	}
284	if top != nil {
285		queryParameters["$top"] = autorest.Encode("query", *top)
286	}
287	if len(inlinecount) > 0 {
288		queryParameters["$inlinecount"] = autorest.Encode("query", inlinecount)
289	}
290
291	preparer := autorest.CreatePreparer(
292		autorest.AsGet(),
293		autorest.WithBaseURL(client.BaseURI),
294		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/nodes", pathParameters),
295		autorest.WithQueryParameters(queryParameters))
296	return preparer.Prepare((&http.Request{}).WithContext(ctx))
297}
298
299// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the
300// http.Response Body if it receives an error.
301func (client DscNodeClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) {
302	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
303}
304
305// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always
306// closes the http.Response Body.
307func (client DscNodeClient) ListByAutomationAccountResponder(resp *http.Response) (result DscNodeListResult, err error) {
308	err = autorest.Respond(
309		resp,
310		client.ByInspecting(),
311		azure.WithErrorUnlessStatusCode(http.StatusOK),
312		autorest.ByUnmarshallingJSON(&result),
313		autorest.ByClosing())
314	result.Response = autorest.Response{Response: resp}
315	return
316}
317
318// listByAutomationAccountNextResults retrieves the next set of results, if any.
319func (client DscNodeClient) listByAutomationAccountNextResults(ctx context.Context, lastResults DscNodeListResult) (result DscNodeListResult, err error) {
320	req, err := lastResults.dscNodeListResultPreparer(ctx)
321	if err != nil {
322		return result, autorest.NewErrorWithError(err, "automation.DscNodeClient", "listByAutomationAccountNextResults", nil, "Failure preparing next results request")
323	}
324	if req == nil {
325		return
326	}
327	resp, err := client.ListByAutomationAccountSender(req)
328	if err != nil {
329		result.Response = autorest.Response{Response: resp}
330		return result, autorest.NewErrorWithError(err, "automation.DscNodeClient", "listByAutomationAccountNextResults", resp, "Failure sending next results request")
331	}
332	result, err = client.ListByAutomationAccountResponder(resp)
333	if err != nil {
334		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "listByAutomationAccountNextResults", resp, "Failure responding to next results request")
335	}
336	return
337}
338
339// ListByAutomationAccountComplete enumerates all values, automatically crossing page boundaries as required.
340func (client DscNodeClient) ListByAutomationAccountComplete(ctx context.Context, resourceGroupName string, automationAccountName string, filter string, skip *int32, top *int32, inlinecount string) (result DscNodeListResultIterator, err error) {
341	if tracing.IsEnabled() {
342		ctx = tracing.StartSpan(ctx, fqdn+"/DscNodeClient.ListByAutomationAccount")
343		defer func() {
344			sc := -1
345			if result.Response().Response.Response != nil {
346				sc = result.page.Response().Response.Response.StatusCode
347			}
348			tracing.EndSpan(ctx, sc, err)
349		}()
350	}
351	result.page, err = client.ListByAutomationAccount(ctx, resourceGroupName, automationAccountName, filter, skip, top, inlinecount)
352	return
353}
354
355// Update update the dsc node.
356// Parameters:
357// resourceGroupName - name of an Azure Resource group.
358// automationAccountName - the name of the automation account.
359// nodeID - parameters supplied to the update dsc node.
360// dscNodeUpdateParameters - parameters supplied to the update dsc node.
361func (client DscNodeClient) Update(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string, dscNodeUpdateParameters DscNodeUpdateParameters) (result DscNode, err error) {
362	if tracing.IsEnabled() {
363		ctx = tracing.StartSpan(ctx, fqdn+"/DscNodeClient.Update")
364		defer func() {
365			sc := -1
366			if result.Response.Response != nil {
367				sc = result.Response.Response.StatusCode
368			}
369			tracing.EndSpan(ctx, sc, err)
370		}()
371	}
372	if err := validation.Validate([]validation.Validation{
373		{TargetValue: resourceGroupName,
374			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
375				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
376				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
377		return result, validation.NewError("automation.DscNodeClient", "Update", err.Error())
378	}
379
380	req, err := client.UpdatePreparer(ctx, resourceGroupName, automationAccountName, nodeID, dscNodeUpdateParameters)
381	if err != nil {
382		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Update", nil, "Failure preparing request")
383		return
384	}
385
386	resp, err := client.UpdateSender(req)
387	if err != nil {
388		result.Response = autorest.Response{Response: resp}
389		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Update", resp, "Failure sending request")
390		return
391	}
392
393	result, err = client.UpdateResponder(resp)
394	if err != nil {
395		err = autorest.NewErrorWithError(err, "automation.DscNodeClient", "Update", resp, "Failure responding to request")
396	}
397
398	return
399}
400
401// UpdatePreparer prepares the Update request.
402func (client DscNodeClient) UpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, nodeID string, dscNodeUpdateParameters DscNodeUpdateParameters) (*http.Request, error) {
403	pathParameters := map[string]interface{}{
404		"automationAccountName": autorest.Encode("path", automationAccountName),
405		"nodeId":                autorest.Encode("path", nodeID),
406		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
407		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
408	}
409
410	const APIVersion = "2018-01-15"
411	queryParameters := map[string]interface{}{
412		"api-version": APIVersion,
413	}
414
415	preparer := autorest.CreatePreparer(
416		autorest.AsContentType("application/json; charset=utf-8"),
417		autorest.AsPatch(),
418		autorest.WithBaseURL(client.BaseURI),
419		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/nodes/{nodeId}", pathParameters),
420		autorest.WithJSON(dscNodeUpdateParameters),
421		autorest.WithQueryParameters(queryParameters))
422	return preparer.Prepare((&http.Request{}).WithContext(ctx))
423}
424
425// UpdateSender sends the Update request. The method will close the
426// http.Response Body if it receives an error.
427func (client DscNodeClient) UpdateSender(req *http.Request) (*http.Response, error) {
428	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
429}
430
431// UpdateResponder handles the response to the Update request. The method always
432// closes the http.Response Body.
433func (client DscNodeClient) UpdateResponder(resp *http.Response) (result DscNode, err error) {
434	err = autorest.Respond(
435		resp,
436		client.ByInspecting(),
437		azure.WithErrorUnlessStatusCode(http.StatusOK),
438		autorest.ByUnmarshallingJSON(&result),
439		autorest.ByClosing())
440	result.Response = autorest.Response{Response: resp}
441	return
442}
443