1package datafactory
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// ExposureControlClient is the the Azure Data Factory V2 management API provides a RESTful set of web services that
30// interact with Azure Data Factory V2 services.
31type ExposureControlClient struct {
32	BaseClient
33}
34
35// NewExposureControlClient creates an instance of the ExposureControlClient client.
36func NewExposureControlClient(subscriptionID string) ExposureControlClient {
37	return NewExposureControlClientWithBaseURI(DefaultBaseURI, subscriptionID)
38}
39
40// NewExposureControlClientWithBaseURI creates an instance of the ExposureControlClient client.
41func NewExposureControlClientWithBaseURI(baseURI string, subscriptionID string) ExposureControlClient {
42	return ExposureControlClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// GetFeatureValue get exposure control feature for specific location.
46// Parameters:
47// locationID - the location identifier.
48// exposureControlRequest - the exposure control request.
49func (client ExposureControlClient) GetFeatureValue(ctx context.Context, locationID string, exposureControlRequest ExposureControlRequest) (result ExposureControlResponse, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/ExposureControlClient.GetFeatureValue")
52		defer func() {
53			sc := -1
54			if result.Response.Response != nil {
55				sc = result.Response.Response.StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	req, err := client.GetFeatureValuePreparer(ctx, locationID, exposureControlRequest)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "datafactory.ExposureControlClient", "GetFeatureValue", nil, "Failure preparing request")
63		return
64	}
65
66	resp, err := client.GetFeatureValueSender(req)
67	if err != nil {
68		result.Response = autorest.Response{Response: resp}
69		err = autorest.NewErrorWithError(err, "datafactory.ExposureControlClient", "GetFeatureValue", resp, "Failure sending request")
70		return
71	}
72
73	result, err = client.GetFeatureValueResponder(resp)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "datafactory.ExposureControlClient", "GetFeatureValue", resp, "Failure responding to request")
76	}
77
78	return
79}
80
81// GetFeatureValuePreparer prepares the GetFeatureValue request.
82func (client ExposureControlClient) GetFeatureValuePreparer(ctx context.Context, locationID string, exposureControlRequest ExposureControlRequest) (*http.Request, error) {
83	pathParameters := map[string]interface{}{
84		"locationId":     autorest.Encode("path", locationID),
85		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
86	}
87
88	const APIVersion = "2018-06-01"
89	queryParameters := map[string]interface{}{
90		"api-version": APIVersion,
91	}
92
93	preparer := autorest.CreatePreparer(
94		autorest.AsContentType("application/json; charset=utf-8"),
95		autorest.AsPost(),
96		autorest.WithBaseURL(client.BaseURI),
97		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DataFactory/locations/{locationId}/getFeatureValue", pathParameters),
98		autorest.WithJSON(exposureControlRequest),
99		autorest.WithQueryParameters(queryParameters))
100	return preparer.Prepare((&http.Request{}).WithContext(ctx))
101}
102
103// GetFeatureValueSender sends the GetFeatureValue request. The method will close the
104// http.Response Body if it receives an error.
105func (client ExposureControlClient) GetFeatureValueSender(req *http.Request) (*http.Response, error) {
106	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
107	return autorest.SendWithSender(client, req, sd...)
108}
109
110// GetFeatureValueResponder handles the response to the GetFeatureValue request. The method always
111// closes the http.Response Body.
112func (client ExposureControlClient) GetFeatureValueResponder(resp *http.Response) (result ExposureControlResponse, err error) {
113	err = autorest.Respond(
114		resp,
115		client.ByInspecting(),
116		azure.WithErrorUnlessStatusCode(http.StatusOK),
117		autorest.ByUnmarshallingJSON(&result),
118		autorest.ByClosing())
119	result.Response = autorest.Response{Response: resp}
120	return
121}
122
123// GetFeatureValueByFactory get exposure control feature for specific factory.
124// Parameters:
125// resourceGroupName - the resource group name.
126// factoryName - the factory name.
127// exposureControlRequest - the exposure control request.
128func (client ExposureControlClient) GetFeatureValueByFactory(ctx context.Context, resourceGroupName string, factoryName string, exposureControlRequest ExposureControlRequest) (result ExposureControlResponse, err error) {
129	if tracing.IsEnabled() {
130		ctx = tracing.StartSpan(ctx, fqdn+"/ExposureControlClient.GetFeatureValueByFactory")
131		defer func() {
132			sc := -1
133			if result.Response.Response != nil {
134				sc = result.Response.Response.StatusCode
135			}
136			tracing.EndSpan(ctx, sc, err)
137		}()
138	}
139	if err := validation.Validate([]validation.Validation{
140		{TargetValue: resourceGroupName,
141			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
142				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
143				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
144		{TargetValue: factoryName,
145			Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil},
146				{Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil},
147				{Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}}}); err != nil {
148		return result, validation.NewError("datafactory.ExposureControlClient", "GetFeatureValueByFactory", err.Error())
149	}
150
151	req, err := client.GetFeatureValueByFactoryPreparer(ctx, resourceGroupName, factoryName, exposureControlRequest)
152	if err != nil {
153		err = autorest.NewErrorWithError(err, "datafactory.ExposureControlClient", "GetFeatureValueByFactory", nil, "Failure preparing request")
154		return
155	}
156
157	resp, err := client.GetFeatureValueByFactorySender(req)
158	if err != nil {
159		result.Response = autorest.Response{Response: resp}
160		err = autorest.NewErrorWithError(err, "datafactory.ExposureControlClient", "GetFeatureValueByFactory", resp, "Failure sending request")
161		return
162	}
163
164	result, err = client.GetFeatureValueByFactoryResponder(resp)
165	if err != nil {
166		err = autorest.NewErrorWithError(err, "datafactory.ExposureControlClient", "GetFeatureValueByFactory", resp, "Failure responding to request")
167	}
168
169	return
170}
171
172// GetFeatureValueByFactoryPreparer prepares the GetFeatureValueByFactory request.
173func (client ExposureControlClient) GetFeatureValueByFactoryPreparer(ctx context.Context, resourceGroupName string, factoryName string, exposureControlRequest ExposureControlRequest) (*http.Request, error) {
174	pathParameters := map[string]interface{}{
175		"factoryName":       autorest.Encode("path", factoryName),
176		"resourceGroupName": autorest.Encode("path", resourceGroupName),
177		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
178	}
179
180	const APIVersion = "2018-06-01"
181	queryParameters := map[string]interface{}{
182		"api-version": APIVersion,
183	}
184
185	preparer := autorest.CreatePreparer(
186		autorest.AsContentType("application/json; charset=utf-8"),
187		autorest.AsPost(),
188		autorest.WithBaseURL(client.BaseURI),
189		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/getFeatureValue", pathParameters),
190		autorest.WithJSON(exposureControlRequest),
191		autorest.WithQueryParameters(queryParameters))
192	return preparer.Prepare((&http.Request{}).WithContext(ctx))
193}
194
195// GetFeatureValueByFactorySender sends the GetFeatureValueByFactory request. The method will close the
196// http.Response Body if it receives an error.
197func (client ExposureControlClient) GetFeatureValueByFactorySender(req *http.Request) (*http.Response, error) {
198	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
199	return autorest.SendWithSender(client, req, sd...)
200}
201
202// GetFeatureValueByFactoryResponder handles the response to the GetFeatureValueByFactory request. The method always
203// closes the http.Response Body.
204func (client ExposureControlClient) GetFeatureValueByFactoryResponder(resp *http.Response) (result ExposureControlResponse, err error) {
205	err = autorest.Respond(
206		resp,
207		client.ByInspecting(),
208		azure.WithErrorUnlessStatusCode(http.StatusOK),
209		autorest.ByUnmarshallingJSON(&result),
210		autorest.ByClosing())
211	result.Response = autorest.Response{Response: resp}
212	return
213}
214