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	"net/http"
26)
27
28// DatasetsClient is the the Azure Data Factory V2 management API provides a RESTful set of web services that interact
29// with Azure Data Factory V2 services.
30type DatasetsClient struct {
31	BaseClient
32}
33
34// NewDatasetsClient creates an instance of the DatasetsClient client.
35func NewDatasetsClient(subscriptionID string) DatasetsClient {
36	return NewDatasetsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewDatasetsClientWithBaseURI creates an instance of the DatasetsClient client.
40func NewDatasetsClientWithBaseURI(baseURI string, subscriptionID string) DatasetsClient {
41	return DatasetsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate creates or updates a dataset.
45// Parameters:
46// resourceGroupName - the resource group name.
47// factoryName - the factory name.
48// datasetName - the dataset name.
49// dataset - dataset resource definition.
50// ifMatch - eTag of the dataset entity.  Should only be specified for update, for which it should match
51// existing entity or can be * for unconditional update.
52func (client DatasetsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, factoryName string, datasetName string, dataset DatasetResource, ifMatch string) (result DatasetResource, err error) {
53	if err := validation.Validate([]validation.Validation{
54		{TargetValue: resourceGroupName,
55			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
56				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
57				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
58		{TargetValue: factoryName,
59			Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil},
60				{Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil},
61				{Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}},
62		{TargetValue: datasetName,
63			Constraints: []validation.Constraint{{Target: "datasetName", Name: validation.MaxLength, Rule: 260, Chain: nil},
64				{Target: "datasetName", Name: validation.MinLength, Rule: 1, Chain: nil},
65				{Target: "datasetName", Name: validation.Pattern, Rule: `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`, Chain: nil}}},
66		{TargetValue: dataset,
67			Constraints: []validation.Constraint{{Target: "dataset.Properties", Name: validation.Null, Rule: true,
68				Chain: []validation.Constraint{{Target: "dataset.Properties.LinkedServiceName", Name: validation.Null, Rule: true,
69					Chain: []validation.Constraint{{Target: "dataset.Properties.LinkedServiceName.Type", Name: validation.Null, Rule: true, Chain: nil},
70						{Target: "dataset.Properties.LinkedServiceName.ReferenceName", Name: validation.Null, Rule: true, Chain: nil},
71					}},
72				}}}}}); err != nil {
73		return result, validation.NewError("datafactory.DatasetsClient", "CreateOrUpdate", err.Error())
74	}
75
76	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, factoryName, datasetName, dataset, ifMatch)
77	if err != nil {
78		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "CreateOrUpdate", nil, "Failure preparing request")
79		return
80	}
81
82	resp, err := client.CreateOrUpdateSender(req)
83	if err != nil {
84		result.Response = autorest.Response{Response: resp}
85		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "CreateOrUpdate", resp, "Failure sending request")
86		return
87	}
88
89	result, err = client.CreateOrUpdateResponder(resp)
90	if err != nil {
91		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "CreateOrUpdate", resp, "Failure responding to request")
92	}
93
94	return
95}
96
97// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
98func (client DatasetsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, factoryName string, datasetName string, dataset DatasetResource, ifMatch string) (*http.Request, error) {
99	pathParameters := map[string]interface{}{
100		"datasetName":       autorest.Encode("path", datasetName),
101		"factoryName":       autorest.Encode("path", factoryName),
102		"resourceGroupName": autorest.Encode("path", resourceGroupName),
103		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
104	}
105
106	const APIVersion = "2017-09-01-preview"
107	queryParameters := map[string]interface{}{
108		"api-version": APIVersion,
109	}
110
111	preparer := autorest.CreatePreparer(
112		autorest.AsContentType("application/json; charset=utf-8"),
113		autorest.AsPut(),
114		autorest.WithBaseURL(client.BaseURI),
115		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets/{datasetName}", pathParameters),
116		autorest.WithJSON(dataset),
117		autorest.WithQueryParameters(queryParameters))
118	if len(ifMatch) > 0 {
119		preparer = autorest.DecoratePreparer(preparer,
120			autorest.WithHeader("If-Match", autorest.String(ifMatch)))
121	}
122	return preparer.Prepare((&http.Request{}).WithContext(ctx))
123}
124
125// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
126// http.Response Body if it receives an error.
127func (client DatasetsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
128	return autorest.SendWithSender(client, req,
129		azure.DoRetryWithRegistration(client.Client))
130}
131
132// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
133// closes the http.Response Body.
134func (client DatasetsClient) CreateOrUpdateResponder(resp *http.Response) (result DatasetResource, err error) {
135	err = autorest.Respond(
136		resp,
137		client.ByInspecting(),
138		azure.WithErrorUnlessStatusCode(http.StatusOK),
139		autorest.ByUnmarshallingJSON(&result),
140		autorest.ByClosing())
141	result.Response = autorest.Response{Response: resp}
142	return
143}
144
145// Delete deletes a dataset.
146// Parameters:
147// resourceGroupName - the resource group name.
148// factoryName - the factory name.
149// datasetName - the dataset name.
150func (client DatasetsClient) Delete(ctx context.Context, resourceGroupName string, factoryName string, datasetName string) (result autorest.Response, err error) {
151	if err := validation.Validate([]validation.Validation{
152		{TargetValue: resourceGroupName,
153			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
154				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
155				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
156		{TargetValue: factoryName,
157			Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil},
158				{Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil},
159				{Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}},
160		{TargetValue: datasetName,
161			Constraints: []validation.Constraint{{Target: "datasetName", Name: validation.MaxLength, Rule: 260, Chain: nil},
162				{Target: "datasetName", Name: validation.MinLength, Rule: 1, Chain: nil},
163				{Target: "datasetName", Name: validation.Pattern, Rule: `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`, Chain: nil}}}}); err != nil {
164		return result, validation.NewError("datafactory.DatasetsClient", "Delete", err.Error())
165	}
166
167	req, err := client.DeletePreparer(ctx, resourceGroupName, factoryName, datasetName)
168	if err != nil {
169		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Delete", nil, "Failure preparing request")
170		return
171	}
172
173	resp, err := client.DeleteSender(req)
174	if err != nil {
175		result.Response = resp
176		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Delete", resp, "Failure sending request")
177		return
178	}
179
180	result, err = client.DeleteResponder(resp)
181	if err != nil {
182		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Delete", resp, "Failure responding to request")
183	}
184
185	return
186}
187
188// DeletePreparer prepares the Delete request.
189func (client DatasetsClient) DeletePreparer(ctx context.Context, resourceGroupName string, factoryName string, datasetName string) (*http.Request, error) {
190	pathParameters := map[string]interface{}{
191		"datasetName":       autorest.Encode("path", datasetName),
192		"factoryName":       autorest.Encode("path", factoryName),
193		"resourceGroupName": autorest.Encode("path", resourceGroupName),
194		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
195	}
196
197	const APIVersion = "2017-09-01-preview"
198	queryParameters := map[string]interface{}{
199		"api-version": APIVersion,
200	}
201
202	preparer := autorest.CreatePreparer(
203		autorest.AsDelete(),
204		autorest.WithBaseURL(client.BaseURI),
205		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets/{datasetName}", pathParameters),
206		autorest.WithQueryParameters(queryParameters))
207	return preparer.Prepare((&http.Request{}).WithContext(ctx))
208}
209
210// DeleteSender sends the Delete request. The method will close the
211// http.Response Body if it receives an error.
212func (client DatasetsClient) DeleteSender(req *http.Request) (*http.Response, error) {
213	return autorest.SendWithSender(client, req,
214		azure.DoRetryWithRegistration(client.Client))
215}
216
217// DeleteResponder handles the response to the Delete request. The method always
218// closes the http.Response Body.
219func (client DatasetsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
220	err = autorest.Respond(
221		resp,
222		client.ByInspecting(),
223		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
224		autorest.ByClosing())
225	result.Response = resp
226	return
227}
228
229// Get gets a dataset.
230// Parameters:
231// resourceGroupName - the resource group name.
232// factoryName - the factory name.
233// datasetName - the dataset name.
234func (client DatasetsClient) Get(ctx context.Context, resourceGroupName string, factoryName string, datasetName string) (result DatasetResource, err error) {
235	if err := validation.Validate([]validation.Validation{
236		{TargetValue: resourceGroupName,
237			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
238				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
239				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
240		{TargetValue: factoryName,
241			Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil},
242				{Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil},
243				{Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}},
244		{TargetValue: datasetName,
245			Constraints: []validation.Constraint{{Target: "datasetName", Name: validation.MaxLength, Rule: 260, Chain: nil},
246				{Target: "datasetName", Name: validation.MinLength, Rule: 1, Chain: nil},
247				{Target: "datasetName", Name: validation.Pattern, Rule: `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`, Chain: nil}}}}); err != nil {
248		return result, validation.NewError("datafactory.DatasetsClient", "Get", err.Error())
249	}
250
251	req, err := client.GetPreparer(ctx, resourceGroupName, factoryName, datasetName)
252	if err != nil {
253		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Get", nil, "Failure preparing request")
254		return
255	}
256
257	resp, err := client.GetSender(req)
258	if err != nil {
259		result.Response = autorest.Response{Response: resp}
260		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Get", resp, "Failure sending request")
261		return
262	}
263
264	result, err = client.GetResponder(resp)
265	if err != nil {
266		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Get", resp, "Failure responding to request")
267	}
268
269	return
270}
271
272// GetPreparer prepares the Get request.
273func (client DatasetsClient) GetPreparer(ctx context.Context, resourceGroupName string, factoryName string, datasetName string) (*http.Request, error) {
274	pathParameters := map[string]interface{}{
275		"datasetName":       autorest.Encode("path", datasetName),
276		"factoryName":       autorest.Encode("path", factoryName),
277		"resourceGroupName": autorest.Encode("path", resourceGroupName),
278		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
279	}
280
281	const APIVersion = "2017-09-01-preview"
282	queryParameters := map[string]interface{}{
283		"api-version": APIVersion,
284	}
285
286	preparer := autorest.CreatePreparer(
287		autorest.AsGet(),
288		autorest.WithBaseURL(client.BaseURI),
289		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets/{datasetName}", pathParameters),
290		autorest.WithQueryParameters(queryParameters))
291	return preparer.Prepare((&http.Request{}).WithContext(ctx))
292}
293
294// GetSender sends the Get request. The method will close the
295// http.Response Body if it receives an error.
296func (client DatasetsClient) GetSender(req *http.Request) (*http.Response, error) {
297	return autorest.SendWithSender(client, req,
298		azure.DoRetryWithRegistration(client.Client))
299}
300
301// GetResponder handles the response to the Get request. The method always
302// closes the http.Response Body.
303func (client DatasetsClient) GetResponder(resp *http.Response) (result DatasetResource, err error) {
304	err = autorest.Respond(
305		resp,
306		client.ByInspecting(),
307		azure.WithErrorUnlessStatusCode(http.StatusOK),
308		autorest.ByUnmarshallingJSON(&result),
309		autorest.ByClosing())
310	result.Response = autorest.Response{Response: resp}
311	return
312}
313
314// ListByFactory lists datasets.
315// Parameters:
316// resourceGroupName - the resource group name.
317// factoryName - the factory name.
318func (client DatasetsClient) ListByFactory(ctx context.Context, resourceGroupName string, factoryName string) (result DatasetListResponsePage, err error) {
319	if err := validation.Validate([]validation.Validation{
320		{TargetValue: resourceGroupName,
321			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
322				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
323				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
324		{TargetValue: factoryName,
325			Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil},
326				{Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil},
327				{Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}}}); err != nil {
328		return result, validation.NewError("datafactory.DatasetsClient", "ListByFactory", err.Error())
329	}
330
331	result.fn = client.listByFactoryNextResults
332	req, err := client.ListByFactoryPreparer(ctx, resourceGroupName, factoryName)
333	if err != nil {
334		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "ListByFactory", nil, "Failure preparing request")
335		return
336	}
337
338	resp, err := client.ListByFactorySender(req)
339	if err != nil {
340		result.dlr.Response = autorest.Response{Response: resp}
341		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "ListByFactory", resp, "Failure sending request")
342		return
343	}
344
345	result.dlr, err = client.ListByFactoryResponder(resp)
346	if err != nil {
347		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "ListByFactory", resp, "Failure responding to request")
348	}
349
350	return
351}
352
353// ListByFactoryPreparer prepares the ListByFactory request.
354func (client DatasetsClient) ListByFactoryPreparer(ctx context.Context, resourceGroupName string, factoryName string) (*http.Request, error) {
355	pathParameters := map[string]interface{}{
356		"factoryName":       autorest.Encode("path", factoryName),
357		"resourceGroupName": autorest.Encode("path", resourceGroupName),
358		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
359	}
360
361	const APIVersion = "2017-09-01-preview"
362	queryParameters := map[string]interface{}{
363		"api-version": APIVersion,
364	}
365
366	preparer := autorest.CreatePreparer(
367		autorest.AsGet(),
368		autorest.WithBaseURL(client.BaseURI),
369		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets", pathParameters),
370		autorest.WithQueryParameters(queryParameters))
371	return preparer.Prepare((&http.Request{}).WithContext(ctx))
372}
373
374// ListByFactorySender sends the ListByFactory request. The method will close the
375// http.Response Body if it receives an error.
376func (client DatasetsClient) ListByFactorySender(req *http.Request) (*http.Response, error) {
377	return autorest.SendWithSender(client, req,
378		azure.DoRetryWithRegistration(client.Client))
379}
380
381// ListByFactoryResponder handles the response to the ListByFactory request. The method always
382// closes the http.Response Body.
383func (client DatasetsClient) ListByFactoryResponder(resp *http.Response) (result DatasetListResponse, 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// listByFactoryNextResults retrieves the next set of results, if any.
395func (client DatasetsClient) listByFactoryNextResults(lastResults DatasetListResponse) (result DatasetListResponse, err error) {
396	req, err := lastResults.datasetListResponsePreparer()
397	if err != nil {
398		return result, autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "listByFactoryNextResults", nil, "Failure preparing next results request")
399	}
400	if req == nil {
401		return
402	}
403	resp, err := client.ListByFactorySender(req)
404	if err != nil {
405		result.Response = autorest.Response{Response: resp}
406		return result, autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "listByFactoryNextResults", resp, "Failure sending next results request")
407	}
408	result, err = client.ListByFactoryResponder(resp)
409	if err != nil {
410		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "listByFactoryNextResults", resp, "Failure responding to next results request")
411	}
412	return
413}
414
415// ListByFactoryComplete enumerates all values, automatically crossing page boundaries as required.
416func (client DatasetsClient) ListByFactoryComplete(ctx context.Context, resourceGroupName string, factoryName string) (result DatasetListResponseIterator, err error) {
417	result.page, err = client.ListByFactory(ctx, resourceGroupName, factoryName)
418	return
419}
420