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 = "2018-06-01"
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 = "2018-06-01"
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.
234// ifNoneMatch - eTag of the dataset entity. Should only be specified for get. If the ETag matches the existing
235// entity tag, or if * was provided, then no content will be returned.
236func (client DatasetsClient) Get(ctx context.Context, resourceGroupName string, factoryName string, datasetName string, ifNoneMatch string) (result DatasetResource, err error) {
237	if err := validation.Validate([]validation.Validation{
238		{TargetValue: resourceGroupName,
239			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
240				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
241				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
242		{TargetValue: factoryName,
243			Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil},
244				{Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil},
245				{Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}},
246		{TargetValue: datasetName,
247			Constraints: []validation.Constraint{{Target: "datasetName", Name: validation.MaxLength, Rule: 260, Chain: nil},
248				{Target: "datasetName", Name: validation.MinLength, Rule: 1, Chain: nil},
249				{Target: "datasetName", Name: validation.Pattern, Rule: `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`, Chain: nil}}}}); err != nil {
250		return result, validation.NewError("datafactory.DatasetsClient", "Get", err.Error())
251	}
252
253	req, err := client.GetPreparer(ctx, resourceGroupName, factoryName, datasetName, ifNoneMatch)
254	if err != nil {
255		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Get", nil, "Failure preparing request")
256		return
257	}
258
259	resp, err := client.GetSender(req)
260	if err != nil {
261		result.Response = autorest.Response{Response: resp}
262		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Get", resp, "Failure sending request")
263		return
264	}
265
266	result, err = client.GetResponder(resp)
267	if err != nil {
268		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Get", resp, "Failure responding to request")
269	}
270
271	return
272}
273
274// GetPreparer prepares the Get request.
275func (client DatasetsClient) GetPreparer(ctx context.Context, resourceGroupName string, factoryName string, datasetName string, ifNoneMatch string) (*http.Request, error) {
276	pathParameters := map[string]interface{}{
277		"datasetName":       autorest.Encode("path", datasetName),
278		"factoryName":       autorest.Encode("path", factoryName),
279		"resourceGroupName": autorest.Encode("path", resourceGroupName),
280		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
281	}
282
283	const APIVersion = "2018-06-01"
284	queryParameters := map[string]interface{}{
285		"api-version": APIVersion,
286	}
287
288	preparer := autorest.CreatePreparer(
289		autorest.AsGet(),
290		autorest.WithBaseURL(client.BaseURI),
291		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets/{datasetName}", pathParameters),
292		autorest.WithQueryParameters(queryParameters))
293	if len(ifNoneMatch) > 0 {
294		preparer = autorest.DecoratePreparer(preparer,
295			autorest.WithHeader("If-None-Match", autorest.String(ifNoneMatch)))
296	}
297	return preparer.Prepare((&http.Request{}).WithContext(ctx))
298}
299
300// GetSender sends the Get request. The method will close the
301// http.Response Body if it receives an error.
302func (client DatasetsClient) GetSender(req *http.Request) (*http.Response, error) {
303	return autorest.SendWithSender(client, req,
304		azure.DoRetryWithRegistration(client.Client))
305}
306
307// GetResponder handles the response to the Get request. The method always
308// closes the http.Response Body.
309func (client DatasetsClient) GetResponder(resp *http.Response) (result DatasetResource, err error) {
310	err = autorest.Respond(
311		resp,
312		client.ByInspecting(),
313		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNotModified),
314		autorest.ByUnmarshallingJSON(&result),
315		autorest.ByClosing())
316	result.Response = autorest.Response{Response: resp}
317	return
318}
319
320// ListByFactory lists datasets.
321// Parameters:
322// resourceGroupName - the resource group name.
323// factoryName - the factory name.
324func (client DatasetsClient) ListByFactory(ctx context.Context, resourceGroupName string, factoryName string) (result DatasetListResponsePage, err error) {
325	if err := validation.Validate([]validation.Validation{
326		{TargetValue: resourceGroupName,
327			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
328				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
329				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
330		{TargetValue: factoryName,
331			Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil},
332				{Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil},
333				{Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}}}); err != nil {
334		return result, validation.NewError("datafactory.DatasetsClient", "ListByFactory", err.Error())
335	}
336
337	result.fn = client.listByFactoryNextResults
338	req, err := client.ListByFactoryPreparer(ctx, resourceGroupName, factoryName)
339	if err != nil {
340		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "ListByFactory", nil, "Failure preparing request")
341		return
342	}
343
344	resp, err := client.ListByFactorySender(req)
345	if err != nil {
346		result.dlr.Response = autorest.Response{Response: resp}
347		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "ListByFactory", resp, "Failure sending request")
348		return
349	}
350
351	result.dlr, err = client.ListByFactoryResponder(resp)
352	if err != nil {
353		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "ListByFactory", resp, "Failure responding to request")
354	}
355
356	return
357}
358
359// ListByFactoryPreparer prepares the ListByFactory request.
360func (client DatasetsClient) ListByFactoryPreparer(ctx context.Context, resourceGroupName string, factoryName string) (*http.Request, error) {
361	pathParameters := map[string]interface{}{
362		"factoryName":       autorest.Encode("path", factoryName),
363		"resourceGroupName": autorest.Encode("path", resourceGroupName),
364		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
365	}
366
367	const APIVersion = "2018-06-01"
368	queryParameters := map[string]interface{}{
369		"api-version": APIVersion,
370	}
371
372	preparer := autorest.CreatePreparer(
373		autorest.AsGet(),
374		autorest.WithBaseURL(client.BaseURI),
375		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets", pathParameters),
376		autorest.WithQueryParameters(queryParameters))
377	return preparer.Prepare((&http.Request{}).WithContext(ctx))
378}
379
380// ListByFactorySender sends the ListByFactory request. The method will close the
381// http.Response Body if it receives an error.
382func (client DatasetsClient) ListByFactorySender(req *http.Request) (*http.Response, error) {
383	return autorest.SendWithSender(client, req,
384		azure.DoRetryWithRegistration(client.Client))
385}
386
387// ListByFactoryResponder handles the response to the ListByFactory request. The method always
388// closes the http.Response Body.
389func (client DatasetsClient) ListByFactoryResponder(resp *http.Response) (result DatasetListResponse, err error) {
390	err = autorest.Respond(
391		resp,
392		client.ByInspecting(),
393		azure.WithErrorUnlessStatusCode(http.StatusOK),
394		autorest.ByUnmarshallingJSON(&result),
395		autorest.ByClosing())
396	result.Response = autorest.Response{Response: resp}
397	return
398}
399
400// listByFactoryNextResults retrieves the next set of results, if any.
401func (client DatasetsClient) listByFactoryNextResults(lastResults DatasetListResponse) (result DatasetListResponse, err error) {
402	req, err := lastResults.datasetListResponsePreparer()
403	if err != nil {
404		return result, autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "listByFactoryNextResults", nil, "Failure preparing next results request")
405	}
406	if req == nil {
407		return
408	}
409	resp, err := client.ListByFactorySender(req)
410	if err != nil {
411		result.Response = autorest.Response{Response: resp}
412		return result, autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "listByFactoryNextResults", resp, "Failure sending next results request")
413	}
414	result, err = client.ListByFactoryResponder(resp)
415	if err != nil {
416		err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "listByFactoryNextResults", resp, "Failure responding to next results request")
417	}
418	return
419}
420
421// ListByFactoryComplete enumerates all values, automatically crossing page boundaries as required.
422func (client DatasetsClient) ListByFactoryComplete(ctx context.Context, resourceGroupName string, factoryName string) (result DatasetListResponseIterator, err error) {
423	result.page, err = client.ListByFactory(ctx, resourceGroupName, factoryName)
424	return
425}
426