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