1package automation
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// TestJobStreamsClient is the automation Client
19type TestJobStreamsClient struct {
20	BaseClient
21}
22
23// NewTestJobStreamsClient creates an instance of the TestJobStreamsClient client.
24func NewTestJobStreamsClient(subscriptionID string) TestJobStreamsClient {
25	return NewTestJobStreamsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewTestJobStreamsClientWithBaseURI creates an instance of the TestJobStreamsClient client using a custom endpoint.
29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewTestJobStreamsClientWithBaseURI(baseURI string, subscriptionID string) TestJobStreamsClient {
31	return TestJobStreamsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// Get retrieve a test job stream of the test job identified by runbook name and stream id.
35// Parameters:
36// resourceGroupName - name of an Azure Resource group.
37// automationAccountName - the name of the automation account.
38// runbookName - the runbook name.
39// jobStreamID - the job stream id.
40func (client TestJobStreamsClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, jobStreamID string) (result JobStream, err error) {
41	if tracing.IsEnabled() {
42		ctx = tracing.StartSpan(ctx, fqdn+"/TestJobStreamsClient.Get")
43		defer func() {
44			sc := -1
45			if result.Response.Response != nil {
46				sc = result.Response.Response.StatusCode
47			}
48			tracing.EndSpan(ctx, sc, err)
49		}()
50	}
51	if err := validation.Validate([]validation.Validation{
52		{TargetValue: resourceGroupName,
53			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
54				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
55				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
56		return result, validation.NewError("automation.TestJobStreamsClient", "Get", err.Error())
57	}
58
59	req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, runbookName, jobStreamID)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "automation.TestJobStreamsClient", "Get", nil, "Failure preparing request")
62		return
63	}
64
65	resp, err := client.GetSender(req)
66	if err != nil {
67		result.Response = autorest.Response{Response: resp}
68		err = autorest.NewErrorWithError(err, "automation.TestJobStreamsClient", "Get", resp, "Failure sending request")
69		return
70	}
71
72	result, err = client.GetResponder(resp)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "automation.TestJobStreamsClient", "Get", resp, "Failure responding to request")
75		return
76	}
77
78	return
79}
80
81// GetPreparer prepares the Get request.
82func (client TestJobStreamsClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, jobStreamID string) (*http.Request, error) {
83	pathParameters := map[string]interface{}{
84		"automationAccountName": autorest.Encode("path", automationAccountName),
85		"jobStreamId":           autorest.Encode("path", jobStreamID),
86		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
87		"runbookName":           autorest.Encode("path", runbookName),
88		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
89	}
90
91	const APIVersion = "2015-10-31"
92	queryParameters := map[string]interface{}{
93		"api-version": APIVersion,
94	}
95
96	preparer := autorest.CreatePreparer(
97		autorest.AsGet(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/testJob/streams/{jobStreamId}", pathParameters),
100		autorest.WithQueryParameters(queryParameters))
101	return preparer.Prepare((&http.Request{}).WithContext(ctx))
102}
103
104// GetSender sends the Get request. The method will close the
105// http.Response Body if it receives an error.
106func (client TestJobStreamsClient) GetSender(req *http.Request) (*http.Response, error) {
107	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
108}
109
110// GetResponder handles the response to the Get request. The method always
111// closes the http.Response Body.
112func (client TestJobStreamsClient) GetResponder(resp *http.Response) (result JobStream, err error) {
113	err = autorest.Respond(
114		resp,
115		azure.WithErrorUnlessStatusCode(http.StatusOK),
116		autorest.ByUnmarshallingJSON(&result),
117		autorest.ByClosing())
118	result.Response = autorest.Response{Response: resp}
119	return
120}
121
122// ListByTestJob retrieve a list of test job streams identified by runbook name.
123// Parameters:
124// resourceGroupName - name of an Azure Resource group.
125// automationAccountName - the name of the automation account.
126// runbookName - the runbook name.
127// filter - the filter to apply on the operation.
128func (client TestJobStreamsClient) ListByTestJob(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, filter string) (result JobStreamListResultPage, err error) {
129	if tracing.IsEnabled() {
130		ctx = tracing.StartSpan(ctx, fqdn+"/TestJobStreamsClient.ListByTestJob")
131		defer func() {
132			sc := -1
133			if result.jslr.Response.Response != nil {
134				sc = result.jslr.Response.Response.StatusCode
135			}
136			tracing.EndSpan(ctx, sc, err)
137		}()
138	}
139	if err := validation.Validate([]validation.Validation{
140		{TargetValue: resourceGroupName,
141			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
142				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
143				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
144		return result, validation.NewError("automation.TestJobStreamsClient", "ListByTestJob", err.Error())
145	}
146
147	result.fn = client.listByTestJobNextResults
148	req, err := client.ListByTestJobPreparer(ctx, resourceGroupName, automationAccountName, runbookName, filter)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "automation.TestJobStreamsClient", "ListByTestJob", nil, "Failure preparing request")
151		return
152	}
153
154	resp, err := client.ListByTestJobSender(req)
155	if err != nil {
156		result.jslr.Response = autorest.Response{Response: resp}
157		err = autorest.NewErrorWithError(err, "automation.TestJobStreamsClient", "ListByTestJob", resp, "Failure sending request")
158		return
159	}
160
161	result.jslr, err = client.ListByTestJobResponder(resp)
162	if err != nil {
163		err = autorest.NewErrorWithError(err, "automation.TestJobStreamsClient", "ListByTestJob", resp, "Failure responding to request")
164		return
165	}
166	if result.jslr.hasNextLink() && result.jslr.IsEmpty() {
167		err = result.NextWithContext(ctx)
168		return
169	}
170
171	return
172}
173
174// ListByTestJobPreparer prepares the ListByTestJob request.
175func (client TestJobStreamsClient) ListByTestJobPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, filter string) (*http.Request, error) {
176	pathParameters := map[string]interface{}{
177		"automationAccountName": autorest.Encode("path", automationAccountName),
178		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
179		"runbookName":           autorest.Encode("path", runbookName),
180		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
181	}
182
183	const APIVersion = "2015-10-31"
184	queryParameters := map[string]interface{}{
185		"api-version": APIVersion,
186	}
187	if len(filter) > 0 {
188		queryParameters["$filter"] = autorest.Encode("query", filter)
189	}
190
191	preparer := autorest.CreatePreparer(
192		autorest.AsGet(),
193		autorest.WithBaseURL(client.BaseURI),
194		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/runbooks/{runbookName}/draft/testJob/streams", pathParameters),
195		autorest.WithQueryParameters(queryParameters))
196	return preparer.Prepare((&http.Request{}).WithContext(ctx))
197}
198
199// ListByTestJobSender sends the ListByTestJob request. The method will close the
200// http.Response Body if it receives an error.
201func (client TestJobStreamsClient) ListByTestJobSender(req *http.Request) (*http.Response, error) {
202	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
203}
204
205// ListByTestJobResponder handles the response to the ListByTestJob request. The method always
206// closes the http.Response Body.
207func (client TestJobStreamsClient) ListByTestJobResponder(resp *http.Response) (result JobStreamListResult, err error) {
208	err = autorest.Respond(
209		resp,
210		azure.WithErrorUnlessStatusCode(http.StatusOK),
211		autorest.ByUnmarshallingJSON(&result),
212		autorest.ByClosing())
213	result.Response = autorest.Response{Response: resp}
214	return
215}
216
217// listByTestJobNextResults retrieves the next set of results, if any.
218func (client TestJobStreamsClient) listByTestJobNextResults(ctx context.Context, lastResults JobStreamListResult) (result JobStreamListResult, err error) {
219	req, err := lastResults.jobStreamListResultPreparer(ctx)
220	if err != nil {
221		return result, autorest.NewErrorWithError(err, "automation.TestJobStreamsClient", "listByTestJobNextResults", nil, "Failure preparing next results request")
222	}
223	if req == nil {
224		return
225	}
226	resp, err := client.ListByTestJobSender(req)
227	if err != nil {
228		result.Response = autorest.Response{Response: resp}
229		return result, autorest.NewErrorWithError(err, "automation.TestJobStreamsClient", "listByTestJobNextResults", resp, "Failure sending next results request")
230	}
231	result, err = client.ListByTestJobResponder(resp)
232	if err != nil {
233		err = autorest.NewErrorWithError(err, "automation.TestJobStreamsClient", "listByTestJobNextResults", resp, "Failure responding to next results request")
234	}
235	return
236}
237
238// ListByTestJobComplete enumerates all values, automatically crossing page boundaries as required.
239func (client TestJobStreamsClient) ListByTestJobComplete(ctx context.Context, resourceGroupName string, automationAccountName string, runbookName string, filter string) (result JobStreamListResultIterator, err error) {
240	if tracing.IsEnabled() {
241		ctx = tracing.StartSpan(ctx, fqdn+"/TestJobStreamsClient.ListByTestJob")
242		defer func() {
243			sc := -1
244			if result.Response().Response.Response != nil {
245				sc = result.page.Response().Response.Response.StatusCode
246			}
247			tracing.EndSpan(ctx, sc, err)
248		}()
249	}
250	result.page, err = client.ListByTestJob(ctx, resourceGroupName, automationAccountName, runbookName, filter)
251	return
252}
253