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