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// TestJobClient is the automation Client
30type TestJobClient struct {
31	BaseClient
32}
33
34// NewTestJobClient creates an instance of the TestJobClient client.
35func NewTestJobClient(subscriptionID string) TestJobClient {
36	return NewTestJobClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewTestJobClientWithBaseURI creates an instance of the TestJobClient 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 NewTestJobClientWithBaseURI(baseURI string, subscriptionID string) TestJobClient {
42	return TestJobClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Create create a test job of the runbook.
46// Parameters:
47// resourceGroupName - name of an Azure Resource group.
48// automationAccountName - the name of the automation account.
49// runbookName - the parameters supplied to the create test job operation.
50// parameters - the parameters supplied to the create test job operation.
51func (client TestJobClient) Create(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, parameters TestJobCreateParameters) (result TestJob, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/TestJobClient.Create")
54		defer func() {
55			sc := -1
56			if result.Response.Response != nil {
57				sc = result.Response.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.TestJobClient", "Create", err.Error())
68	}
69
70	req, err := client.CreatePreparer(ctx, resourceGroupName, automationAccountName, runbookName, parameters)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Create", nil, "Failure preparing request")
73		return
74	}
75
76	resp, err := client.CreateSender(req)
77	if err != nil {
78		result.Response = autorest.Response{Response: resp}
79		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Create", resp, "Failure sending request")
80		return
81	}
82
83	result, err = client.CreateResponder(resp)
84	if err != nil {
85		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Create", resp, "Failure responding to request")
86	}
87
88	return
89}
90
91// CreatePreparer prepares the Create request.
92func (client TestJobClient) CreatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, parameters TestJobCreateParameters) (*http.Request, error) {
93	pathParameters := map[string]interface{}{
94		"automationAccountName": autorest.Encode("path", automationAccountName),
95		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
96		"runbookName":           autorest.Encode("path", runbookName),
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.AsContentType("application/json; charset=utf-8"),
107		autorest.AsPut(),
108		autorest.WithBaseURL(client.BaseURI),
109		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/testJob", pathParameters),
110		autorest.WithJSON(parameters),
111		autorest.WithQueryParameters(queryParameters))
112	return preparer.Prepare((&http.Request{}).WithContext(ctx))
113}
114
115// CreateSender sends the Create request. The method will close the
116// http.Response Body if it receives an error.
117func (client TestJobClient) CreateSender(req *http.Request) (*http.Response, error) {
118	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
119}
120
121// CreateResponder handles the response to the Create request. The method always
122// closes the http.Response Body.
123func (client TestJobClient) CreateResponder(resp *http.Response) (result TestJob, err error) {
124	err = autorest.Respond(
125		resp,
126		client.ByInspecting(),
127		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
128		autorest.ByUnmarshallingJSON(&result),
129		autorest.ByClosing())
130	result.Response = autorest.Response{Response: resp}
131	return
132}
133
134// Get retrieve the test job for the specified runbook.
135// Parameters:
136// resourceGroupName - name of an Azure Resource group.
137// automationAccountName - the name of the automation account.
138// runbookName - the runbook name.
139func (client TestJobClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (result TestJob, err error) {
140	if tracing.IsEnabled() {
141		ctx = tracing.StartSpan(ctx, fqdn+"/TestJobClient.Get")
142		defer func() {
143			sc := -1
144			if result.Response.Response != nil {
145				sc = result.Response.Response.StatusCode
146			}
147			tracing.EndSpan(ctx, sc, err)
148		}()
149	}
150	if err := validation.Validate([]validation.Validation{
151		{TargetValue: resourceGroupName,
152			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
153				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
154				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
155		return result, validation.NewError("automation.TestJobClient", "Get", err.Error())
156	}
157
158	req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, runbookName)
159	if err != nil {
160		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Get", nil, "Failure preparing request")
161		return
162	}
163
164	resp, err := client.GetSender(req)
165	if err != nil {
166		result.Response = autorest.Response{Response: resp}
167		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Get", resp, "Failure sending request")
168		return
169	}
170
171	result, err = client.GetResponder(resp)
172	if err != nil {
173		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Get", resp, "Failure responding to request")
174	}
175
176	return
177}
178
179// GetPreparer prepares the Get request.
180func (client TestJobClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (*http.Request, error) {
181	pathParameters := map[string]interface{}{
182		"automationAccountName": autorest.Encode("path", automationAccountName),
183		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
184		"runbookName":           autorest.Encode("path", runbookName),
185		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
186	}
187
188	const APIVersion = "2015-10-31"
189	queryParameters := map[string]interface{}{
190		"api-version": APIVersion,
191	}
192
193	preparer := autorest.CreatePreparer(
194		autorest.AsGet(),
195		autorest.WithBaseURL(client.BaseURI),
196		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/testJob", pathParameters),
197		autorest.WithQueryParameters(queryParameters))
198	return preparer.Prepare((&http.Request{}).WithContext(ctx))
199}
200
201// GetSender sends the Get request. The method will close the
202// http.Response Body if it receives an error.
203func (client TestJobClient) GetSender(req *http.Request) (*http.Response, error) {
204	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
205}
206
207// GetResponder handles the response to the Get request. The method always
208// closes the http.Response Body.
209func (client TestJobClient) GetResponder(resp *http.Response) (result TestJob, err error) {
210	err = autorest.Respond(
211		resp,
212		client.ByInspecting(),
213		azure.WithErrorUnlessStatusCode(http.StatusOK),
214		autorest.ByUnmarshallingJSON(&result),
215		autorest.ByClosing())
216	result.Response = autorest.Response{Response: resp}
217	return
218}
219
220// Resume resume the test job.
221// Parameters:
222// resourceGroupName - name of an Azure Resource group.
223// automationAccountName - the name of the automation account.
224// runbookName - the runbook name.
225func (client TestJobClient) Resume(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (result autorest.Response, err error) {
226	if tracing.IsEnabled() {
227		ctx = tracing.StartSpan(ctx, fqdn+"/TestJobClient.Resume")
228		defer func() {
229			sc := -1
230			if result.Response != nil {
231				sc = result.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.TestJobClient", "Resume", err.Error())
242	}
243
244	req, err := client.ResumePreparer(ctx, resourceGroupName, automationAccountName, runbookName)
245	if err != nil {
246		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Resume", nil, "Failure preparing request")
247		return
248	}
249
250	resp, err := client.ResumeSender(req)
251	if err != nil {
252		result.Response = resp
253		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Resume", resp, "Failure sending request")
254		return
255	}
256
257	result, err = client.ResumeResponder(resp)
258	if err != nil {
259		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Resume", resp, "Failure responding to request")
260	}
261
262	return
263}
264
265// ResumePreparer prepares the Resume request.
266func (client TestJobClient) ResumePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (*http.Request, error) {
267	pathParameters := map[string]interface{}{
268		"automationAccountName": autorest.Encode("path", automationAccountName),
269		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
270		"runbookName":           autorest.Encode("path", runbookName),
271		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
272	}
273
274	const APIVersion = "2015-10-31"
275	queryParameters := map[string]interface{}{
276		"api-version": APIVersion,
277	}
278
279	preparer := autorest.CreatePreparer(
280		autorest.AsPost(),
281		autorest.WithBaseURL(client.BaseURI),
282		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/testJob/resume", pathParameters),
283		autorest.WithQueryParameters(queryParameters))
284	return preparer.Prepare((&http.Request{}).WithContext(ctx))
285}
286
287// ResumeSender sends the Resume request. The method will close the
288// http.Response Body if it receives an error.
289func (client TestJobClient) ResumeSender(req *http.Request) (*http.Response, error) {
290	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
291}
292
293// ResumeResponder handles the response to the Resume request. The method always
294// closes the http.Response Body.
295func (client TestJobClient) ResumeResponder(resp *http.Response) (result autorest.Response, err error) {
296	err = autorest.Respond(
297		resp,
298		client.ByInspecting(),
299		azure.WithErrorUnlessStatusCode(http.StatusOK),
300		autorest.ByClosing())
301	result.Response = resp
302	return
303}
304
305// Stop stop the test job.
306// Parameters:
307// resourceGroupName - name of an Azure Resource group.
308// automationAccountName - the name of the automation account.
309// runbookName - the runbook name.
310func (client TestJobClient) Stop(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (result autorest.Response, err error) {
311	if tracing.IsEnabled() {
312		ctx = tracing.StartSpan(ctx, fqdn+"/TestJobClient.Stop")
313		defer func() {
314			sc := -1
315			if result.Response != nil {
316				sc = result.Response.StatusCode
317			}
318			tracing.EndSpan(ctx, sc, err)
319		}()
320	}
321	if err := validation.Validate([]validation.Validation{
322		{TargetValue: resourceGroupName,
323			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
324				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
325				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
326		return result, validation.NewError("automation.TestJobClient", "Stop", err.Error())
327	}
328
329	req, err := client.StopPreparer(ctx, resourceGroupName, automationAccountName, runbookName)
330	if err != nil {
331		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Stop", nil, "Failure preparing request")
332		return
333	}
334
335	resp, err := client.StopSender(req)
336	if err != nil {
337		result.Response = resp
338		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Stop", resp, "Failure sending request")
339		return
340	}
341
342	result, err = client.StopResponder(resp)
343	if err != nil {
344		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Stop", resp, "Failure responding to request")
345	}
346
347	return
348}
349
350// StopPreparer prepares the Stop request.
351func (client TestJobClient) StopPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (*http.Request, error) {
352	pathParameters := map[string]interface{}{
353		"automationAccountName": autorest.Encode("path", automationAccountName),
354		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
355		"runbookName":           autorest.Encode("path", runbookName),
356		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
357	}
358
359	const APIVersion = "2015-10-31"
360	queryParameters := map[string]interface{}{
361		"api-version": APIVersion,
362	}
363
364	preparer := autorest.CreatePreparer(
365		autorest.AsPost(),
366		autorest.WithBaseURL(client.BaseURI),
367		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/testJob/stop", pathParameters),
368		autorest.WithQueryParameters(queryParameters))
369	return preparer.Prepare((&http.Request{}).WithContext(ctx))
370}
371
372// StopSender sends the Stop request. The method will close the
373// http.Response Body if it receives an error.
374func (client TestJobClient) StopSender(req *http.Request) (*http.Response, error) {
375	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
376}
377
378// StopResponder handles the response to the Stop request. The method always
379// closes the http.Response Body.
380func (client TestJobClient) StopResponder(resp *http.Response) (result autorest.Response, err error) {
381	err = autorest.Respond(
382		resp,
383		client.ByInspecting(),
384		azure.WithErrorUnlessStatusCode(http.StatusOK),
385		autorest.ByClosing())
386	result.Response = resp
387	return
388}
389
390// Suspend suspend the test job.
391// Parameters:
392// resourceGroupName - name of an Azure Resource group.
393// automationAccountName - the name of the automation account.
394// runbookName - the runbook name.
395func (client TestJobClient) Suspend(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (result autorest.Response, err error) {
396	if tracing.IsEnabled() {
397		ctx = tracing.StartSpan(ctx, fqdn+"/TestJobClient.Suspend")
398		defer func() {
399			sc := -1
400			if result.Response != nil {
401				sc = result.Response.StatusCode
402			}
403			tracing.EndSpan(ctx, sc, err)
404		}()
405	}
406	if err := validation.Validate([]validation.Validation{
407		{TargetValue: resourceGroupName,
408			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
409				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
410				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
411		return result, validation.NewError("automation.TestJobClient", "Suspend", err.Error())
412	}
413
414	req, err := client.SuspendPreparer(ctx, resourceGroupName, automationAccountName, runbookName)
415	if err != nil {
416		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Suspend", nil, "Failure preparing request")
417		return
418	}
419
420	resp, err := client.SuspendSender(req)
421	if err != nil {
422		result.Response = resp
423		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Suspend", resp, "Failure sending request")
424		return
425	}
426
427	result, err = client.SuspendResponder(resp)
428	if err != nil {
429		err = autorest.NewErrorWithError(err, "automation.TestJobClient", "Suspend", resp, "Failure responding to request")
430	}
431
432	return
433}
434
435// SuspendPreparer prepares the Suspend request.
436func (client TestJobClient) SuspendPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string) (*http.Request, error) {
437	pathParameters := map[string]interface{}{
438		"automationAccountName": autorest.Encode("path", automationAccountName),
439		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
440		"runbookName":           autorest.Encode("path", runbookName),
441		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
442	}
443
444	const APIVersion = "2015-10-31"
445	queryParameters := map[string]interface{}{
446		"api-version": APIVersion,
447	}
448
449	preparer := autorest.CreatePreparer(
450		autorest.AsPost(),
451		autorest.WithBaseURL(client.BaseURI),
452		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/testJob/suspend", pathParameters),
453		autorest.WithQueryParameters(queryParameters))
454	return preparer.Prepare((&http.Request{}).WithContext(ctx))
455}
456
457// SuspendSender sends the Suspend request. The method will close the
458// http.Response Body if it receives an error.
459func (client TestJobClient) SuspendSender(req *http.Request) (*http.Response, error) {
460	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
461}
462
463// SuspendResponder handles the response to the Suspend request. The method always
464// closes the http.Response Body.
465func (client TestJobClient) SuspendResponder(resp *http.Response) (result autorest.Response, err error) {
466	err = autorest.Respond(
467		resp,
468		client.ByInspecting(),
469		azure.WithErrorUnlessStatusCode(http.StatusOK),
470		autorest.ByClosing())
471	result.Response = resp
472	return
473}
474