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