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