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