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// ObjectDataTypesClient is the automation Client
30type ObjectDataTypesClient struct {
31	BaseClient
32}
33
34// NewObjectDataTypesClient creates an instance of the ObjectDataTypesClient client.
35func NewObjectDataTypesClient(subscriptionID string) ObjectDataTypesClient {
36	return NewObjectDataTypesClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewObjectDataTypesClientWithBaseURI creates an instance of the ObjectDataTypesClient 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 NewObjectDataTypesClientWithBaseURI(baseURI string, subscriptionID string) ObjectDataTypesClient {
42	return ObjectDataTypesClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// ListFieldsByModuleAndType retrieve a list of fields of a given type identified by module name.
46// Parameters:
47// resourceGroupName - name of an Azure Resource group.
48// automationAccountName - the name of the automation account.
49// moduleName - the name of module.
50// typeName - the name of type.
51func (client ObjectDataTypesClient) ListFieldsByModuleAndType(ctx context.Context, resourceGroupName string, automationAccountName string, moduleName string, typeName string) (result TypeFieldListResult, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/ObjectDataTypesClient.ListFieldsByModuleAndType")
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}}}}); err != nil {
67		return result, validation.NewError("automation.ObjectDataTypesClient", "ListFieldsByModuleAndType", err.Error())
68	}
69
70	req, err := client.ListFieldsByModuleAndTypePreparer(ctx, resourceGroupName, automationAccountName, moduleName, typeName)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "automation.ObjectDataTypesClient", "ListFieldsByModuleAndType", nil, "Failure preparing request")
73		return
74	}
75
76	resp, err := client.ListFieldsByModuleAndTypeSender(req)
77	if err != nil {
78		result.Response = autorest.Response{Response: resp}
79		err = autorest.NewErrorWithError(err, "automation.ObjectDataTypesClient", "ListFieldsByModuleAndType", resp, "Failure sending request")
80		return
81	}
82
83	result, err = client.ListFieldsByModuleAndTypeResponder(resp)
84	if err != nil {
85		err = autorest.NewErrorWithError(err, "automation.ObjectDataTypesClient", "ListFieldsByModuleAndType", resp, "Failure responding to request")
86	}
87
88	return
89}
90
91// ListFieldsByModuleAndTypePreparer prepares the ListFieldsByModuleAndType request.
92func (client ObjectDataTypesClient) ListFieldsByModuleAndTypePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, moduleName string, typeName string) (*http.Request, error) {
93	pathParameters := map[string]interface{}{
94		"automationAccountName": autorest.Encode("path", automationAccountName),
95		"moduleName":            autorest.Encode("path", moduleName),
96		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
97		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
98		"typeName":              autorest.Encode("path", typeName),
99	}
100
101	const APIVersion = "2015-10-31"
102	queryParameters := map[string]interface{}{
103		"api-version": APIVersion,
104	}
105
106	preparer := autorest.CreatePreparer(
107		autorest.AsGet(),
108		autorest.WithBaseURL(client.BaseURI),
109		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/modules/{moduleName}/objectDataTypes/{typeName}/fields", pathParameters),
110		autorest.WithQueryParameters(queryParameters))
111	return preparer.Prepare((&http.Request{}).WithContext(ctx))
112}
113
114// ListFieldsByModuleAndTypeSender sends the ListFieldsByModuleAndType request. The method will close the
115// http.Response Body if it receives an error.
116func (client ObjectDataTypesClient) ListFieldsByModuleAndTypeSender(req *http.Request) (*http.Response, error) {
117	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
118}
119
120// ListFieldsByModuleAndTypeResponder handles the response to the ListFieldsByModuleAndType request. The method always
121// closes the http.Response Body.
122func (client ObjectDataTypesClient) ListFieldsByModuleAndTypeResponder(resp *http.Response) (result TypeFieldListResult, err error) {
123	err = autorest.Respond(
124		resp,
125		client.ByInspecting(),
126		azure.WithErrorUnlessStatusCode(http.StatusOK),
127		autorest.ByUnmarshallingJSON(&result),
128		autorest.ByClosing())
129	result.Response = autorest.Response{Response: resp}
130	return
131}
132
133// ListFieldsByType retrieve a list of fields of a given type across all accessible modules.
134// Parameters:
135// resourceGroupName - name of an Azure Resource group.
136// automationAccountName - the name of the automation account.
137// typeName - the name of type.
138func (client ObjectDataTypesClient) ListFieldsByType(ctx context.Context, resourceGroupName string, automationAccountName string, typeName string) (result TypeFieldListResult, err error) {
139	if tracing.IsEnabled() {
140		ctx = tracing.StartSpan(ctx, fqdn+"/ObjectDataTypesClient.ListFieldsByType")
141		defer func() {
142			sc := -1
143			if result.Response.Response != nil {
144				sc = result.Response.Response.StatusCode
145			}
146			tracing.EndSpan(ctx, sc, err)
147		}()
148	}
149	if err := validation.Validate([]validation.Validation{
150		{TargetValue: resourceGroupName,
151			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
152				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
153				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
154		return result, validation.NewError("automation.ObjectDataTypesClient", "ListFieldsByType", err.Error())
155	}
156
157	req, err := client.ListFieldsByTypePreparer(ctx, resourceGroupName, automationAccountName, typeName)
158	if err != nil {
159		err = autorest.NewErrorWithError(err, "automation.ObjectDataTypesClient", "ListFieldsByType", nil, "Failure preparing request")
160		return
161	}
162
163	resp, err := client.ListFieldsByTypeSender(req)
164	if err != nil {
165		result.Response = autorest.Response{Response: resp}
166		err = autorest.NewErrorWithError(err, "automation.ObjectDataTypesClient", "ListFieldsByType", resp, "Failure sending request")
167		return
168	}
169
170	result, err = client.ListFieldsByTypeResponder(resp)
171	if err != nil {
172		err = autorest.NewErrorWithError(err, "automation.ObjectDataTypesClient", "ListFieldsByType", resp, "Failure responding to request")
173	}
174
175	return
176}
177
178// ListFieldsByTypePreparer prepares the ListFieldsByType request.
179func (client ObjectDataTypesClient) ListFieldsByTypePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, typeName string) (*http.Request, error) {
180	pathParameters := map[string]interface{}{
181		"automationAccountName": autorest.Encode("path", automationAccountName),
182		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
183		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
184		"typeName":              autorest.Encode("path", typeName),
185	}
186
187	const APIVersion = "2015-10-31"
188	queryParameters := map[string]interface{}{
189		"api-version": APIVersion,
190	}
191
192	preparer := autorest.CreatePreparer(
193		autorest.AsGet(),
194		autorest.WithBaseURL(client.BaseURI),
195		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/objectDataTypes/{typeName}/fields", pathParameters),
196		autorest.WithQueryParameters(queryParameters))
197	return preparer.Prepare((&http.Request{}).WithContext(ctx))
198}
199
200// ListFieldsByTypeSender sends the ListFieldsByType request. The method will close the
201// http.Response Body if it receives an error.
202func (client ObjectDataTypesClient) ListFieldsByTypeSender(req *http.Request) (*http.Response, error) {
203	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
204}
205
206// ListFieldsByTypeResponder handles the response to the ListFieldsByType request. The method always
207// closes the http.Response Body.
208func (client ObjectDataTypesClient) ListFieldsByTypeResponder(resp *http.Response) (result TypeFieldListResult, err error) {
209	err = autorest.Respond(
210		resp,
211		client.ByInspecting(),
212		azure.WithErrorUnlessStatusCode(http.StatusOK),
213		autorest.ByUnmarshallingJSON(&result),
214		autorest.ByClosing())
215	result.Response = autorest.Response{Response: resp}
216	return
217}
218