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