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// FieldsClient is the automation Client
19type FieldsClient struct {
20	BaseClient
21}
22
23// NewFieldsClient creates an instance of the FieldsClient client.
24func NewFieldsClient(subscriptionID string) FieldsClient {
25	return NewFieldsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewFieldsClientWithBaseURI creates an instance of the FieldsClient client using a custom endpoint.  Use this when
29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewFieldsClientWithBaseURI(baseURI string, subscriptionID string) FieldsClient {
31	return FieldsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// ListByType retrieve a list of fields of a given type identified by module name.
35// Parameters:
36// resourceGroupName - name of an Azure Resource group.
37// automationAccountName - the name of the automation account.
38// moduleName - the name of module.
39// typeName - the name of type.
40func (client FieldsClient) ListByType(ctx context.Context, resourceGroupName string, automationAccountName string, moduleName string, typeName string) (result TypeFieldListResult, err error) {
41	if tracing.IsEnabled() {
42		ctx = tracing.StartSpan(ctx, fqdn+"/FieldsClient.ListByType")
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}}}}); err != nil {
56		return result, validation.NewError("automation.FieldsClient", "ListByType", err.Error())
57	}
58
59	req, err := client.ListByTypePreparer(ctx, resourceGroupName, automationAccountName, moduleName, typeName)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "automation.FieldsClient", "ListByType", nil, "Failure preparing request")
62		return
63	}
64
65	resp, err := client.ListByTypeSender(req)
66	if err != nil {
67		result.Response = autorest.Response{Response: resp}
68		err = autorest.NewErrorWithError(err, "automation.FieldsClient", "ListByType", resp, "Failure sending request")
69		return
70	}
71
72	result, err = client.ListByTypeResponder(resp)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "automation.FieldsClient", "ListByType", resp, "Failure responding to request")
75		return
76	}
77
78	return
79}
80
81// ListByTypePreparer prepares the ListByType request.
82func (client FieldsClient) ListByTypePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, moduleName string, typeName string) (*http.Request, error) {
83	pathParameters := map[string]interface{}{
84		"automationAccountName": autorest.Encode("path", automationAccountName),
85		"moduleName":            autorest.Encode("path", moduleName),
86		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
87		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
88		"typeName":              autorest.Encode("path", typeName),
89	}
90
91	const APIVersion = "2015-10-31"
92	queryParameters := map[string]interface{}{
93		"api-version": APIVersion,
94	}
95
96	preparer := autorest.CreatePreparer(
97		autorest.AsGet(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/modules/{moduleName}/types/{typeName}/fields", pathParameters),
100		autorest.WithQueryParameters(queryParameters))
101	return preparer.Prepare((&http.Request{}).WithContext(ctx))
102}
103
104// ListByTypeSender sends the ListByType request. The method will close the
105// http.Response Body if it receives an error.
106func (client FieldsClient) ListByTypeSender(req *http.Request) (*http.Response, error) {
107	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
108}
109
110// ListByTypeResponder handles the response to the ListByType request. The method always
111// closes the http.Response Body.
112func (client FieldsClient) ListByTypeResponder(resp *http.Response) (result TypeFieldListResult, err error) {
113	err = autorest.Respond(
114		resp,
115		azure.WithErrorUnlessStatusCode(http.StatusOK),
116		autorest.ByUnmarshallingJSON(&result),
117		autorest.ByClosing())
118	result.Response = autorest.Response{Response: resp}
119	return
120}
121