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