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	"net/http"
26)
27
28// SourceControlClient is the automation Client
29type SourceControlClient struct {
30	BaseClient
31}
32
33// NewSourceControlClient creates an instance of the SourceControlClient client.
34func NewSourceControlClient(subscriptionID string) SourceControlClient {
35	return NewSourceControlClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewSourceControlClientWithBaseURI creates an instance of the SourceControlClient client.
39func NewSourceControlClientWithBaseURI(baseURI string, subscriptionID string) SourceControlClient {
40	return SourceControlClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// CreateOrUpdate create a source control.
44// Parameters:
45// resourceGroupName - name of an Azure Resource group.
46// automationAccountName - the name of the automation account.
47// sourceControlName - the source control name.
48// parameters - the parameters supplied to the create or update source control operation.
49func (client SourceControlClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string, parameters SourceControlCreateOrUpdateParameters) (result SourceControl, err error) {
50	if err := validation.Validate([]validation.Validation{
51		{TargetValue: resourceGroupName,
52			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
53				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
54				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
55		{TargetValue: parameters,
56			Constraints: []validation.Constraint{{Target: "parameters.SourceControlCreateOrUpdateProperties", Name: validation.Null, Rule: true,
57				Chain: []validation.Constraint{{Target: "parameters.SourceControlCreateOrUpdateProperties.RepoURL", Name: validation.Null, Rule: false,
58					Chain: []validation.Constraint{{Target: "parameters.SourceControlCreateOrUpdateProperties.RepoURL", Name: validation.MaxLength, Rule: 2000, Chain: nil}}},
59					{Target: "parameters.SourceControlCreateOrUpdateProperties.Branch", Name: validation.Null, Rule: false,
60						Chain: []validation.Constraint{{Target: "parameters.SourceControlCreateOrUpdateProperties.Branch", Name: validation.MaxLength, Rule: 255, Chain: nil}}},
61					{Target: "parameters.SourceControlCreateOrUpdateProperties.FolderPath", Name: validation.Null, Rule: false,
62						Chain: []validation.Constraint{{Target: "parameters.SourceControlCreateOrUpdateProperties.FolderPath", Name: validation.MaxLength, Rule: 255, Chain: nil}}},
63					{Target: "parameters.SourceControlCreateOrUpdateProperties.SecurityToken", Name: validation.Null, Rule: false,
64						Chain: []validation.Constraint{{Target: "parameters.SourceControlCreateOrUpdateProperties.SecurityToken.AccessToken", Name: validation.Null, Rule: false,
65							Chain: []validation.Constraint{{Target: "parameters.SourceControlCreateOrUpdateProperties.SecurityToken.AccessToken", Name: validation.MaxLength, Rule: 1024, Chain: nil}}},
66							{Target: "parameters.SourceControlCreateOrUpdateProperties.SecurityToken.RefreshToken", Name: validation.Null, Rule: false,
67								Chain: []validation.Constraint{{Target: "parameters.SourceControlCreateOrUpdateProperties.SecurityToken.RefreshToken", Name: validation.MaxLength, Rule: 1024, Chain: nil}}},
68						}},
69					{Target: "parameters.SourceControlCreateOrUpdateProperties.Description", Name: validation.Null, Rule: false,
70						Chain: []validation.Constraint{{Target: "parameters.SourceControlCreateOrUpdateProperties.Description", Name: validation.MaxLength, Rule: 512, Chain: nil}}},
71				}}}}}); err != nil {
72		return result, validation.NewError("automation.SourceControlClient", "CreateOrUpdate", err.Error())
73	}
74
75	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, automationAccountName, sourceControlName, parameters)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "CreateOrUpdate", nil, "Failure preparing request")
78		return
79	}
80
81	resp, err := client.CreateOrUpdateSender(req)
82	if err != nil {
83		result.Response = autorest.Response{Response: resp}
84		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "CreateOrUpdate", resp, "Failure sending request")
85		return
86	}
87
88	result, err = client.CreateOrUpdateResponder(resp)
89	if err != nil {
90		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "CreateOrUpdate", resp, "Failure responding to request")
91	}
92
93	return
94}
95
96// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
97func (client SourceControlClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string, parameters SourceControlCreateOrUpdateParameters) (*http.Request, error) {
98	pathParameters := map[string]interface{}{
99		"automationAccountName": autorest.Encode("path", automationAccountName),
100		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
101		"sourceControlName":     autorest.Encode("path", sourceControlName),
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.AsContentType("application/json; charset=utf-8"),
112		autorest.AsPut(),
113		autorest.WithBaseURL(client.BaseURI),
114		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/sourceControls/{sourceControlName}", pathParameters),
115		autorest.WithJSON(parameters),
116		autorest.WithQueryParameters(queryParameters))
117	return preparer.Prepare((&http.Request{}).WithContext(ctx))
118}
119
120// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
121// http.Response Body if it receives an error.
122func (client SourceControlClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
123	return autorest.SendWithSender(client, req,
124		azure.DoRetryWithRegistration(client.Client))
125}
126
127// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
128// closes the http.Response Body.
129func (client SourceControlClient) CreateOrUpdateResponder(resp *http.Response) (result SourceControl, err error) {
130	err = autorest.Respond(
131		resp,
132		client.ByInspecting(),
133		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
134		autorest.ByUnmarshallingJSON(&result),
135		autorest.ByClosing())
136	result.Response = autorest.Response{Response: resp}
137	return
138}
139
140// Delete delete the source control.
141// Parameters:
142// resourceGroupName - name of an Azure Resource group.
143// automationAccountName - the name of the automation account.
144// sourceControlName - the name of source control.
145func (client SourceControlClient) Delete(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string) (result autorest.Response, err error) {
146	if err := validation.Validate([]validation.Validation{
147		{TargetValue: resourceGroupName,
148			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
149				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
150				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
151		return result, validation.NewError("automation.SourceControlClient", "Delete", err.Error())
152	}
153
154	req, err := client.DeletePreparer(ctx, resourceGroupName, automationAccountName, sourceControlName)
155	if err != nil {
156		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "Delete", nil, "Failure preparing request")
157		return
158	}
159
160	resp, err := client.DeleteSender(req)
161	if err != nil {
162		result.Response = resp
163		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "Delete", resp, "Failure sending request")
164		return
165	}
166
167	result, err = client.DeleteResponder(resp)
168	if err != nil {
169		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "Delete", resp, "Failure responding to request")
170	}
171
172	return
173}
174
175// DeletePreparer prepares the Delete request.
176func (client SourceControlClient) DeletePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string) (*http.Request, error) {
177	pathParameters := map[string]interface{}{
178		"automationAccountName": autorest.Encode("path", automationAccountName),
179		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
180		"sourceControlName":     autorest.Encode("path", sourceControlName),
181		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
182	}
183
184	const APIVersion = "2017-05-15-preview"
185	queryParameters := map[string]interface{}{
186		"api-version": APIVersion,
187	}
188
189	preparer := autorest.CreatePreparer(
190		autorest.AsDelete(),
191		autorest.WithBaseURL(client.BaseURI),
192		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/sourceControls/{sourceControlName}", pathParameters),
193		autorest.WithQueryParameters(queryParameters))
194	return preparer.Prepare((&http.Request{}).WithContext(ctx))
195}
196
197// DeleteSender sends the Delete request. The method will close the
198// http.Response Body if it receives an error.
199func (client SourceControlClient) DeleteSender(req *http.Request) (*http.Response, error) {
200	return autorest.SendWithSender(client, req,
201		azure.DoRetryWithRegistration(client.Client))
202}
203
204// DeleteResponder handles the response to the Delete request. The method always
205// closes the http.Response Body.
206func (client SourceControlClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
207	err = autorest.Respond(
208		resp,
209		client.ByInspecting(),
210		azure.WithErrorUnlessStatusCode(http.StatusOK),
211		autorest.ByClosing())
212	result.Response = resp
213	return
214}
215
216// Get retrieve the source control identified by source control name.
217// Parameters:
218// resourceGroupName - name of an Azure Resource group.
219// automationAccountName - the name of the automation account.
220// sourceControlName - the name of source control.
221func (client SourceControlClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string) (result SourceControl, err error) {
222	if err := validation.Validate([]validation.Validation{
223		{TargetValue: resourceGroupName,
224			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
225				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
226				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
227		return result, validation.NewError("automation.SourceControlClient", "Get", err.Error())
228	}
229
230	req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, sourceControlName)
231	if err != nil {
232		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "Get", nil, "Failure preparing request")
233		return
234	}
235
236	resp, err := client.GetSender(req)
237	if err != nil {
238		result.Response = autorest.Response{Response: resp}
239		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "Get", resp, "Failure sending request")
240		return
241	}
242
243	result, err = client.GetResponder(resp)
244	if err != nil {
245		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "Get", resp, "Failure responding to request")
246	}
247
248	return
249}
250
251// GetPreparer prepares the Get request.
252func (client SourceControlClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string) (*http.Request, error) {
253	pathParameters := map[string]interface{}{
254		"automationAccountName": autorest.Encode("path", automationAccountName),
255		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
256		"sourceControlName":     autorest.Encode("path", sourceControlName),
257		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
258	}
259
260	const APIVersion = "2017-05-15-preview"
261	queryParameters := map[string]interface{}{
262		"api-version": APIVersion,
263	}
264
265	preparer := autorest.CreatePreparer(
266		autorest.AsGet(),
267		autorest.WithBaseURL(client.BaseURI),
268		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/sourceControls/{sourceControlName}", pathParameters),
269		autorest.WithQueryParameters(queryParameters))
270	return preparer.Prepare((&http.Request{}).WithContext(ctx))
271}
272
273// GetSender sends the Get request. The method will close the
274// http.Response Body if it receives an error.
275func (client SourceControlClient) GetSender(req *http.Request) (*http.Response, error) {
276	return autorest.SendWithSender(client, req,
277		azure.DoRetryWithRegistration(client.Client))
278}
279
280// GetResponder handles the response to the Get request. The method always
281// closes the http.Response Body.
282func (client SourceControlClient) GetResponder(resp *http.Response) (result SourceControl, err error) {
283	err = autorest.Respond(
284		resp,
285		client.ByInspecting(),
286		azure.WithErrorUnlessStatusCode(http.StatusOK),
287		autorest.ByUnmarshallingJSON(&result),
288		autorest.ByClosing())
289	result.Response = autorest.Response{Response: resp}
290	return
291}
292
293// ListByAutomationAccount retrieve a list of source controls.
294// Parameters:
295// resourceGroupName - name of an Azure Resource group.
296// automationAccountName - the name of the automation account.
297// filter - the filter to apply on the operation.
298func (client SourceControlClient) ListByAutomationAccount(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (result SourceControlListResultPage, err error) {
299	if err := validation.Validate([]validation.Validation{
300		{TargetValue: resourceGroupName,
301			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
302				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
303				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
304		return result, validation.NewError("automation.SourceControlClient", "ListByAutomationAccount", err.Error())
305	}
306
307	result.fn = client.listByAutomationAccountNextResults
308	req, err := client.ListByAutomationAccountPreparer(ctx, resourceGroupName, automationAccountName, filter)
309	if err != nil {
310		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "ListByAutomationAccount", nil, "Failure preparing request")
311		return
312	}
313
314	resp, err := client.ListByAutomationAccountSender(req)
315	if err != nil {
316		result.sclr.Response = autorest.Response{Response: resp}
317		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "ListByAutomationAccount", resp, "Failure sending request")
318		return
319	}
320
321	result.sclr, err = client.ListByAutomationAccountResponder(resp)
322	if err != nil {
323		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "ListByAutomationAccount", resp, "Failure responding to request")
324	}
325
326	return
327}
328
329// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request.
330func (client SourceControlClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (*http.Request, error) {
331	pathParameters := map[string]interface{}{
332		"automationAccountName": autorest.Encode("path", automationAccountName),
333		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
334		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
335	}
336
337	const APIVersion = "2017-05-15-preview"
338	queryParameters := map[string]interface{}{
339		"api-version": APIVersion,
340	}
341	if len(filter) > 0 {
342		queryParameters["$filter"] = autorest.Encode("query", filter)
343	}
344
345	preparer := autorest.CreatePreparer(
346		autorest.AsGet(),
347		autorest.WithBaseURL(client.BaseURI),
348		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/sourceControls", pathParameters),
349		autorest.WithQueryParameters(queryParameters))
350	return preparer.Prepare((&http.Request{}).WithContext(ctx))
351}
352
353// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the
354// http.Response Body if it receives an error.
355func (client SourceControlClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) {
356	return autorest.SendWithSender(client, req,
357		azure.DoRetryWithRegistration(client.Client))
358}
359
360// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always
361// closes the http.Response Body.
362func (client SourceControlClient) ListByAutomationAccountResponder(resp *http.Response) (result SourceControlListResult, err error) {
363	err = autorest.Respond(
364		resp,
365		client.ByInspecting(),
366		azure.WithErrorUnlessStatusCode(http.StatusOK),
367		autorest.ByUnmarshallingJSON(&result),
368		autorest.ByClosing())
369	result.Response = autorest.Response{Response: resp}
370	return
371}
372
373// listByAutomationAccountNextResults retrieves the next set of results, if any.
374func (client SourceControlClient) listByAutomationAccountNextResults(lastResults SourceControlListResult) (result SourceControlListResult, err error) {
375	req, err := lastResults.sourceControlListResultPreparer()
376	if err != nil {
377		return result, autorest.NewErrorWithError(err, "automation.SourceControlClient", "listByAutomationAccountNextResults", nil, "Failure preparing next results request")
378	}
379	if req == nil {
380		return
381	}
382	resp, err := client.ListByAutomationAccountSender(req)
383	if err != nil {
384		result.Response = autorest.Response{Response: resp}
385		return result, autorest.NewErrorWithError(err, "automation.SourceControlClient", "listByAutomationAccountNextResults", resp, "Failure sending next results request")
386	}
387	result, err = client.ListByAutomationAccountResponder(resp)
388	if err != nil {
389		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "listByAutomationAccountNextResults", resp, "Failure responding to next results request")
390	}
391	return
392}
393
394// ListByAutomationAccountComplete enumerates all values, automatically crossing page boundaries as required.
395func (client SourceControlClient) ListByAutomationAccountComplete(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (result SourceControlListResultIterator, err error) {
396	result.page, err = client.ListByAutomationAccount(ctx, resourceGroupName, automationAccountName, filter)
397	return
398}
399
400// Update update a source control.
401// Parameters:
402// resourceGroupName - name of an Azure Resource group.
403// automationAccountName - the name of the automation account.
404// sourceControlName - the source control name.
405// parameters - the parameters supplied to the update source control operation.
406func (client SourceControlClient) Update(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string, parameters SourceControlUpdateParameters) (result SourceControl, err error) {
407	if err := validation.Validate([]validation.Validation{
408		{TargetValue: resourceGroupName,
409			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
410				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
411				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
412		return result, validation.NewError("automation.SourceControlClient", "Update", err.Error())
413	}
414
415	req, err := client.UpdatePreparer(ctx, resourceGroupName, automationAccountName, sourceControlName, parameters)
416	if err != nil {
417		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "Update", nil, "Failure preparing request")
418		return
419	}
420
421	resp, err := client.UpdateSender(req)
422	if err != nil {
423		result.Response = autorest.Response{Response: resp}
424		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "Update", resp, "Failure sending request")
425		return
426	}
427
428	result, err = client.UpdateResponder(resp)
429	if err != nil {
430		err = autorest.NewErrorWithError(err, "automation.SourceControlClient", "Update", resp, "Failure responding to request")
431	}
432
433	return
434}
435
436// UpdatePreparer prepares the Update request.
437func (client SourceControlClient) UpdatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, sourceControlName string, parameters SourceControlUpdateParameters) (*http.Request, error) {
438	pathParameters := map[string]interface{}{
439		"automationAccountName": autorest.Encode("path", automationAccountName),
440		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
441		"sourceControlName":     autorest.Encode("path", sourceControlName),
442		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
443	}
444
445	const APIVersion = "2017-05-15-preview"
446	queryParameters := map[string]interface{}{
447		"api-version": APIVersion,
448	}
449
450	preparer := autorest.CreatePreparer(
451		autorest.AsContentType("application/json; charset=utf-8"),
452		autorest.AsPatch(),
453		autorest.WithBaseURL(client.BaseURI),
454		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/sourceControls/{sourceControlName}", pathParameters),
455		autorest.WithJSON(parameters),
456		autorest.WithQueryParameters(queryParameters))
457	return preparer.Prepare((&http.Request{}).WithContext(ctx))
458}
459
460// UpdateSender sends the Update request. The method will close the
461// http.Response Body if it receives an error.
462func (client SourceControlClient) UpdateSender(req *http.Request) (*http.Response, error) {
463	return autorest.SendWithSender(client, req,
464		azure.DoRetryWithRegistration(client.Client))
465}
466
467// UpdateResponder handles the response to the Update request. The method always
468// closes the http.Response Body.
469func (client SourceControlClient) UpdateResponder(resp *http.Response) (result SourceControl, err error) {
470	err = autorest.Respond(
471		resp,
472		client.ByInspecting(),
473		azure.WithErrorUnlessStatusCode(http.StatusOK),
474		autorest.ByUnmarshallingJSON(&result),
475		autorest.ByClosing())
476	result.Response = autorest.Response{Response: resp}
477	return
478}
479