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	"github.com/gofrs/uuid"
16	"net/http"
17)
18
19// SourceControlSyncJobStreamsClient is the automation Client
20type SourceControlSyncJobStreamsClient struct {
21	BaseClient
22}
23
24// NewSourceControlSyncJobStreamsClient creates an instance of the SourceControlSyncJobStreamsClient client.
25func NewSourceControlSyncJobStreamsClient(subscriptionID string) SourceControlSyncJobStreamsClient {
26	return NewSourceControlSyncJobStreamsClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewSourceControlSyncJobStreamsClientWithBaseURI creates an instance of the SourceControlSyncJobStreamsClient client
30// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
31// clouds, Azure stack).
32func NewSourceControlSyncJobStreamsClientWithBaseURI(baseURI string, subscriptionID string) SourceControlSyncJobStreamsClient {
33	return SourceControlSyncJobStreamsClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// Get retrieve a sync job stream identified by stream id.
37// Parameters:
38// resourceGroupName - name of an Azure Resource group.
39// automationAccountName - the name of the automation account.
40// sourceControlName - the source control name.
41// sourceControlSyncJobID - the source control sync job id.
42// streamID - the id of the sync job stream.
43func (client SourceControlSyncJobStreamsClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string, sourceControlSyncJobID uuid.UUID, streamID string) (result SourceControlSyncJobStreamByID, err error) {
44	if tracing.IsEnabled() {
45		ctx = tracing.StartSpan(ctx, fqdn+"/SourceControlSyncJobStreamsClient.Get")
46		defer func() {
47			sc := -1
48			if result.Response.Response != nil {
49				sc = result.Response.Response.StatusCode
50			}
51			tracing.EndSpan(ctx, sc, err)
52		}()
53	}
54	if err := validation.Validate([]validation.Validation{
55		{TargetValue: resourceGroupName,
56			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
57				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
58				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
59		return result, validation.NewError("automation.SourceControlSyncJobStreamsClient", "Get", err.Error())
60	}
61
62	req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, sourceControlName, sourceControlSyncJobID, streamID)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "automation.SourceControlSyncJobStreamsClient", "Get", nil, "Failure preparing request")
65		return
66	}
67
68	resp, err := client.GetSender(req)
69	if err != nil {
70		result.Response = autorest.Response{Response: resp}
71		err = autorest.NewErrorWithError(err, "automation.SourceControlSyncJobStreamsClient", "Get", resp, "Failure sending request")
72		return
73	}
74
75	result, err = client.GetResponder(resp)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "automation.SourceControlSyncJobStreamsClient", "Get", resp, "Failure responding to request")
78		return
79	}
80
81	return
82}
83
84// GetPreparer prepares the Get request.
85func (client SourceControlSyncJobStreamsClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string, sourceControlSyncJobID uuid.UUID, streamID string) (*http.Request, error) {
86	pathParameters := map[string]interface{}{
87		"automationAccountName":  autorest.Encode("path", automationAccountName),
88		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
89		"sourceControlName":      autorest.Encode("path", sourceControlName),
90		"sourceControlSyncJobId": autorest.Encode("path", sourceControlSyncJobID),
91		"streamId":               autorest.Encode("path", streamID),
92		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
93	}
94
95	const APIVersion = "2017-05-15-preview"
96	queryParameters := map[string]interface{}{
97		"api-version": APIVersion,
98	}
99
100	preparer := autorest.CreatePreparer(
101		autorest.AsGet(),
102		autorest.WithBaseURL(client.BaseURI),
103		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/sourceControls/{sourceControlName}/sourceControlSyncJobs/{sourceControlSyncJobId}/streams/{streamId}", pathParameters),
104		autorest.WithQueryParameters(queryParameters))
105	return preparer.Prepare((&http.Request{}).WithContext(ctx))
106}
107
108// GetSender sends the Get request. The method will close the
109// http.Response Body if it receives an error.
110func (client SourceControlSyncJobStreamsClient) GetSender(req *http.Request) (*http.Response, error) {
111	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
112}
113
114// GetResponder handles the response to the Get request. The method always
115// closes the http.Response Body.
116func (client SourceControlSyncJobStreamsClient) GetResponder(resp *http.Response) (result SourceControlSyncJobStreamByID, err error) {
117	err = autorest.Respond(
118		resp,
119		azure.WithErrorUnlessStatusCode(http.StatusOK),
120		autorest.ByUnmarshallingJSON(&result),
121		autorest.ByClosing())
122	result.Response = autorest.Response{Response: resp}
123	return
124}
125
126// ListBySyncJob retrieve a list of sync job streams identified by sync job id.
127// Parameters:
128// resourceGroupName - name of an Azure Resource group.
129// automationAccountName - the name of the automation account.
130// sourceControlName - the source control name.
131// sourceControlSyncJobID - the source control sync job id.
132// filter - the filter to apply on the operation.
133func (client SourceControlSyncJobStreamsClient) ListBySyncJob(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string, sourceControlSyncJobID uuid.UUID, filter string) (result SourceControlSyncJobStreamsListBySyncJobPage, err error) {
134	if tracing.IsEnabled() {
135		ctx = tracing.StartSpan(ctx, fqdn+"/SourceControlSyncJobStreamsClient.ListBySyncJob")
136		defer func() {
137			sc := -1
138			if result.scsjslbsj.Response.Response != nil {
139				sc = result.scsjslbsj.Response.Response.StatusCode
140			}
141			tracing.EndSpan(ctx, sc, err)
142		}()
143	}
144	if err := validation.Validate([]validation.Validation{
145		{TargetValue: resourceGroupName,
146			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
147				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
148				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
149		return result, validation.NewError("automation.SourceControlSyncJobStreamsClient", "ListBySyncJob", err.Error())
150	}
151
152	result.fn = client.listBySyncJobNextResults
153	req, err := client.ListBySyncJobPreparer(ctx, resourceGroupName, automationAccountName, sourceControlName, sourceControlSyncJobID, filter)
154	if err != nil {
155		err = autorest.NewErrorWithError(err, "automation.SourceControlSyncJobStreamsClient", "ListBySyncJob", nil, "Failure preparing request")
156		return
157	}
158
159	resp, err := client.ListBySyncJobSender(req)
160	if err != nil {
161		result.scsjslbsj.Response = autorest.Response{Response: resp}
162		err = autorest.NewErrorWithError(err, "automation.SourceControlSyncJobStreamsClient", "ListBySyncJob", resp, "Failure sending request")
163		return
164	}
165
166	result.scsjslbsj, err = client.ListBySyncJobResponder(resp)
167	if err != nil {
168		err = autorest.NewErrorWithError(err, "automation.SourceControlSyncJobStreamsClient", "ListBySyncJob", resp, "Failure responding to request")
169		return
170	}
171	if result.scsjslbsj.hasNextLink() && result.scsjslbsj.IsEmpty() {
172		err = result.NextWithContext(ctx)
173		return
174	}
175
176	return
177}
178
179// ListBySyncJobPreparer prepares the ListBySyncJob request.
180func (client SourceControlSyncJobStreamsClient) ListBySyncJobPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string, sourceControlSyncJobID uuid.UUID, filter string) (*http.Request, error) {
181	pathParameters := map[string]interface{}{
182		"automationAccountName":  autorest.Encode("path", automationAccountName),
183		"resourceGroupName":      autorest.Encode("path", resourceGroupName),
184		"sourceControlName":      autorest.Encode("path", sourceControlName),
185		"sourceControlSyncJobId": autorest.Encode("path", sourceControlSyncJobID),
186		"subscriptionId":         autorest.Encode("path", client.SubscriptionID),
187	}
188
189	const APIVersion = "2017-05-15-preview"
190	queryParameters := map[string]interface{}{
191		"api-version": APIVersion,
192	}
193	if len(filter) > 0 {
194		queryParameters["$filter"] = autorest.Encode("query", filter)
195	}
196
197	preparer := autorest.CreatePreparer(
198		autorest.AsGet(),
199		autorest.WithBaseURL(client.BaseURI),
200		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/sourceControls/{sourceControlName}/sourceControlSyncJobs/{sourceControlSyncJobId}/streams", pathParameters),
201		autorest.WithQueryParameters(queryParameters))
202	return preparer.Prepare((&http.Request{}).WithContext(ctx))
203}
204
205// ListBySyncJobSender sends the ListBySyncJob request. The method will close the
206// http.Response Body if it receives an error.
207func (client SourceControlSyncJobStreamsClient) ListBySyncJobSender(req *http.Request) (*http.Response, error) {
208	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
209}
210
211// ListBySyncJobResponder handles the response to the ListBySyncJob request. The method always
212// closes the http.Response Body.
213func (client SourceControlSyncJobStreamsClient) ListBySyncJobResponder(resp *http.Response) (result SourceControlSyncJobStreamsListBySyncJob, err error) {
214	err = autorest.Respond(
215		resp,
216		azure.WithErrorUnlessStatusCode(http.StatusOK),
217		autorest.ByUnmarshallingJSON(&result),
218		autorest.ByClosing())
219	result.Response = autorest.Response{Response: resp}
220	return
221}
222
223// listBySyncJobNextResults retrieves the next set of results, if any.
224func (client SourceControlSyncJobStreamsClient) listBySyncJobNextResults(ctx context.Context, lastResults SourceControlSyncJobStreamsListBySyncJob) (result SourceControlSyncJobStreamsListBySyncJob, err error) {
225	req, err := lastResults.sourceControlSyncJobStreamsListBySyncJobPreparer(ctx)
226	if err != nil {
227		return result, autorest.NewErrorWithError(err, "automation.SourceControlSyncJobStreamsClient", "listBySyncJobNextResults", nil, "Failure preparing next results request")
228	}
229	if req == nil {
230		return
231	}
232	resp, err := client.ListBySyncJobSender(req)
233	if err != nil {
234		result.Response = autorest.Response{Response: resp}
235		return result, autorest.NewErrorWithError(err, "automation.SourceControlSyncJobStreamsClient", "listBySyncJobNextResults", resp, "Failure sending next results request")
236	}
237	result, err = client.ListBySyncJobResponder(resp)
238	if err != nil {
239		err = autorest.NewErrorWithError(err, "automation.SourceControlSyncJobStreamsClient", "listBySyncJobNextResults", resp, "Failure responding to next results request")
240	}
241	return
242}
243
244// ListBySyncJobComplete enumerates all values, automatically crossing page boundaries as required.
245func (client SourceControlSyncJobStreamsClient) ListBySyncJobComplete(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string, sourceControlSyncJobID uuid.UUID, filter string) (result SourceControlSyncJobStreamsListBySyncJobIterator, err error) {
246	if tracing.IsEnabled() {
247		ctx = tracing.StartSpan(ctx, fqdn+"/SourceControlSyncJobStreamsClient.ListBySyncJob")
248		defer func() {
249			sc := -1
250			if result.Response().Response.Response != nil {
251				sc = result.page.Response().Response.Response.StatusCode
252			}
253			tracing.EndSpan(ctx, sc, err)
254		}()
255	}
256	result.page, err = client.ListBySyncJob(ctx, resourceGroupName, automationAccountName, sourceControlName, sourceControlSyncJobID, filter)
257	return
258}
259