1package datashare
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/tracing"
25	"net/http"
26)
27
28// DataSetsClient is the creates a Microsoft.DataShare management client.
29type DataSetsClient struct {
30	BaseClient
31}
32
33// NewDataSetsClient creates an instance of the DataSetsClient client.
34func NewDataSetsClient(subscriptionID string) DataSetsClient {
35	return NewDataSetsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewDataSetsClientWithBaseURI creates an instance of the DataSetsClient client using a custom endpoint.  Use this
39// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewDataSetsClientWithBaseURI(baseURI string, subscriptionID string) DataSetsClient {
41	return DataSetsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// Create create a DataSet
45// Parameters:
46// resourceGroupName - the resource group name.
47// accountName - the name of the share account.
48// shareName - the name of the share to add the data set to.
49// dataSetName - the name of the dataSet.
50// dataSet - the new data set information.
51func (client DataSetsClient) Create(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string, dataSet BasicDataSet) (result DataSetModel, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/DataSetsClient.Create")
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	req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, shareName, dataSetName, dataSet)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "Create", nil, "Failure preparing request")
65		return
66	}
67
68	resp, err := client.CreateSender(req)
69	if err != nil {
70		result.Response = autorest.Response{Response: resp}
71		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "Create", resp, "Failure sending request")
72		return
73	}
74
75	result, err = client.CreateResponder(resp)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "Create", resp, "Failure responding to request")
78	}
79
80	return
81}
82
83// CreatePreparer prepares the Create request.
84func (client DataSetsClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string, dataSet BasicDataSet) (*http.Request, error) {
85	pathParameters := map[string]interface{}{
86		"accountName":       autorest.Encode("path", accountName),
87		"dataSetName":       autorest.Encode("path", dataSetName),
88		"resourceGroupName": autorest.Encode("path", resourceGroupName),
89		"shareName":         autorest.Encode("path", shareName),
90		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
91	}
92
93	const APIVersion = "2018-11-01-preview"
94	queryParameters := map[string]interface{}{
95		"api-version": APIVersion,
96	}
97
98	preparer := autorest.CreatePreparer(
99		autorest.AsContentType("application/json; charset=utf-8"),
100		autorest.AsPut(),
101		autorest.WithBaseURL(client.BaseURI),
102		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataShare/accounts/{accountName}/shares/{shareName}/dataSets/{dataSetName}", pathParameters),
103		autorest.WithJSON(dataSet),
104		autorest.WithQueryParameters(queryParameters))
105	return preparer.Prepare((&http.Request{}).WithContext(ctx))
106}
107
108// CreateSender sends the Create request. The method will close the
109// http.Response Body if it receives an error.
110func (client DataSetsClient) CreateSender(req *http.Request) (*http.Response, error) {
111	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
112}
113
114// CreateResponder handles the response to the Create request. The method always
115// closes the http.Response Body.
116func (client DataSetsClient) CreateResponder(resp *http.Response) (result DataSetModel, err error) {
117	err = autorest.Respond(
118		resp,
119		client.ByInspecting(),
120		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
121		autorest.ByUnmarshallingJSON(&result),
122		autorest.ByClosing())
123	result.Response = autorest.Response{Response: resp}
124	return
125}
126
127// Delete delete a DataSet in a share
128// Parameters:
129// resourceGroupName - the resource group name.
130// accountName - the name of the share account.
131// shareName - the name of the share.
132// dataSetName - the name of the dataSet.
133func (client DataSetsClient) Delete(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string) (result DataSetsDeleteFuture, err error) {
134	if tracing.IsEnabled() {
135		ctx = tracing.StartSpan(ctx, fqdn+"/DataSetsClient.Delete")
136		defer func() {
137			sc := -1
138			if result.Response() != nil {
139				sc = result.Response().StatusCode
140			}
141			tracing.EndSpan(ctx, sc, err)
142		}()
143	}
144	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, shareName, dataSetName)
145	if err != nil {
146		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "Delete", nil, "Failure preparing request")
147		return
148	}
149
150	result, err = client.DeleteSender(req)
151	if err != nil {
152		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "Delete", result.Response(), "Failure sending request")
153		return
154	}
155
156	return
157}
158
159// DeletePreparer prepares the Delete request.
160func (client DataSetsClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string) (*http.Request, error) {
161	pathParameters := map[string]interface{}{
162		"accountName":       autorest.Encode("path", accountName),
163		"dataSetName":       autorest.Encode("path", dataSetName),
164		"resourceGroupName": autorest.Encode("path", resourceGroupName),
165		"shareName":         autorest.Encode("path", shareName),
166		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
167	}
168
169	const APIVersion = "2018-11-01-preview"
170	queryParameters := map[string]interface{}{
171		"api-version": APIVersion,
172	}
173
174	preparer := autorest.CreatePreparer(
175		autorest.AsDelete(),
176		autorest.WithBaseURL(client.BaseURI),
177		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataShare/accounts/{accountName}/shares/{shareName}/dataSets/{dataSetName}", pathParameters),
178		autorest.WithQueryParameters(queryParameters))
179	return preparer.Prepare((&http.Request{}).WithContext(ctx))
180}
181
182// DeleteSender sends the Delete request. The method will close the
183// http.Response Body if it receives an error.
184func (client DataSetsClient) DeleteSender(req *http.Request) (future DataSetsDeleteFuture, err error) {
185	var resp *http.Response
186	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
187	if err != nil {
188		return
189	}
190	future.Future, err = azure.NewFutureFromResponse(resp)
191	return
192}
193
194// DeleteResponder handles the response to the Delete request. The method always
195// closes the http.Response Body.
196func (client DataSetsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
197	err = autorest.Respond(
198		resp,
199		client.ByInspecting(),
200		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
201		autorest.ByClosing())
202	result.Response = resp
203	return
204}
205
206// Get get a DataSet in a share
207// Parameters:
208// resourceGroupName - the resource group name.
209// accountName - the name of the share account.
210// shareName - the name of the share.
211// dataSetName - the name of the dataSet.
212func (client DataSetsClient) Get(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string) (result DataSetModel, err error) {
213	if tracing.IsEnabled() {
214		ctx = tracing.StartSpan(ctx, fqdn+"/DataSetsClient.Get")
215		defer func() {
216			sc := -1
217			if result.Response.Response != nil {
218				sc = result.Response.Response.StatusCode
219			}
220			tracing.EndSpan(ctx, sc, err)
221		}()
222	}
223	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, shareName, dataSetName)
224	if err != nil {
225		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "Get", nil, "Failure preparing request")
226		return
227	}
228
229	resp, err := client.GetSender(req)
230	if err != nil {
231		result.Response = autorest.Response{Response: resp}
232		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "Get", resp, "Failure sending request")
233		return
234	}
235
236	result, err = client.GetResponder(resp)
237	if err != nil {
238		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "Get", resp, "Failure responding to request")
239	}
240
241	return
242}
243
244// GetPreparer prepares the Get request.
245func (client DataSetsClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, shareName string, dataSetName string) (*http.Request, error) {
246	pathParameters := map[string]interface{}{
247		"accountName":       autorest.Encode("path", accountName),
248		"dataSetName":       autorest.Encode("path", dataSetName),
249		"resourceGroupName": autorest.Encode("path", resourceGroupName),
250		"shareName":         autorest.Encode("path", shareName),
251		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
252	}
253
254	const APIVersion = "2018-11-01-preview"
255	queryParameters := map[string]interface{}{
256		"api-version": APIVersion,
257	}
258
259	preparer := autorest.CreatePreparer(
260		autorest.AsGet(),
261		autorest.WithBaseURL(client.BaseURI),
262		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataShare/accounts/{accountName}/shares/{shareName}/dataSets/{dataSetName}", pathParameters),
263		autorest.WithQueryParameters(queryParameters))
264	return preparer.Prepare((&http.Request{}).WithContext(ctx))
265}
266
267// GetSender sends the Get request. The method will close the
268// http.Response Body if it receives an error.
269func (client DataSetsClient) GetSender(req *http.Request) (*http.Response, error) {
270	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
271}
272
273// GetResponder handles the response to the Get request. The method always
274// closes the http.Response Body.
275func (client DataSetsClient) GetResponder(resp *http.Response) (result DataSetModel, err error) {
276	err = autorest.Respond(
277		resp,
278		client.ByInspecting(),
279		azure.WithErrorUnlessStatusCode(http.StatusOK),
280		autorest.ByUnmarshallingJSON(&result),
281		autorest.ByClosing())
282	result.Response = autorest.Response{Response: resp}
283	return
284}
285
286// ListByShare list DataSets in a share
287// Parameters:
288// resourceGroupName - the resource group name.
289// accountName - the name of the share account.
290// shareName - the name of the share.
291// skipToken - continuation token
292func (client DataSetsClient) ListByShare(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result DataSetListPage, err error) {
293	if tracing.IsEnabled() {
294		ctx = tracing.StartSpan(ctx, fqdn+"/DataSetsClient.ListByShare")
295		defer func() {
296			sc := -1
297			if result.dsl.Response.Response != nil {
298				sc = result.dsl.Response.Response.StatusCode
299			}
300			tracing.EndSpan(ctx, sc, err)
301		}()
302	}
303	result.fn = client.listByShareNextResults
304	req, err := client.ListBySharePreparer(ctx, resourceGroupName, accountName, shareName, skipToken)
305	if err != nil {
306		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "ListByShare", nil, "Failure preparing request")
307		return
308	}
309
310	resp, err := client.ListByShareSender(req)
311	if err != nil {
312		result.dsl.Response = autorest.Response{Response: resp}
313		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "ListByShare", resp, "Failure sending request")
314		return
315	}
316
317	result.dsl, err = client.ListByShareResponder(resp)
318	if err != nil {
319		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "ListByShare", resp, "Failure responding to request")
320	}
321
322	return
323}
324
325// ListBySharePreparer prepares the ListByShare request.
326func (client DataSetsClient) ListBySharePreparer(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (*http.Request, error) {
327	pathParameters := map[string]interface{}{
328		"accountName":       autorest.Encode("path", accountName),
329		"resourceGroupName": autorest.Encode("path", resourceGroupName),
330		"shareName":         autorest.Encode("path", shareName),
331		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
332	}
333
334	const APIVersion = "2018-11-01-preview"
335	queryParameters := map[string]interface{}{
336		"api-version": APIVersion,
337	}
338	if len(skipToken) > 0 {
339		queryParameters["$skipToken"] = autorest.Encode("query", skipToken)
340	}
341
342	preparer := autorest.CreatePreparer(
343		autorest.AsGet(),
344		autorest.WithBaseURL(client.BaseURI),
345		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataShare/accounts/{accountName}/shares/{shareName}/dataSets", pathParameters),
346		autorest.WithQueryParameters(queryParameters))
347	return preparer.Prepare((&http.Request{}).WithContext(ctx))
348}
349
350// ListByShareSender sends the ListByShare request. The method will close the
351// http.Response Body if it receives an error.
352func (client DataSetsClient) ListByShareSender(req *http.Request) (*http.Response, error) {
353	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
354}
355
356// ListByShareResponder handles the response to the ListByShare request. The method always
357// closes the http.Response Body.
358func (client DataSetsClient) ListByShareResponder(resp *http.Response) (result DataSetList, err error) {
359	err = autorest.Respond(
360		resp,
361		client.ByInspecting(),
362		azure.WithErrorUnlessStatusCode(http.StatusOK),
363		autorest.ByUnmarshallingJSON(&result),
364		autorest.ByClosing())
365	result.Response = autorest.Response{Response: resp}
366	return
367}
368
369// listByShareNextResults retrieves the next set of results, if any.
370func (client DataSetsClient) listByShareNextResults(ctx context.Context, lastResults DataSetList) (result DataSetList, err error) {
371	req, err := lastResults.dataSetListPreparer(ctx)
372	if err != nil {
373		return result, autorest.NewErrorWithError(err, "datashare.DataSetsClient", "listByShareNextResults", nil, "Failure preparing next results request")
374	}
375	if req == nil {
376		return
377	}
378	resp, err := client.ListByShareSender(req)
379	if err != nil {
380		result.Response = autorest.Response{Response: resp}
381		return result, autorest.NewErrorWithError(err, "datashare.DataSetsClient", "listByShareNextResults", resp, "Failure sending next results request")
382	}
383	result, err = client.ListByShareResponder(resp)
384	if err != nil {
385		err = autorest.NewErrorWithError(err, "datashare.DataSetsClient", "listByShareNextResults", resp, "Failure responding to next results request")
386	}
387	return
388}
389
390// ListByShareComplete enumerates all values, automatically crossing page boundaries as required.
391func (client DataSetsClient) ListByShareComplete(ctx context.Context, resourceGroupName string, accountName string, shareName string, skipToken string) (result DataSetListIterator, err error) {
392	if tracing.IsEnabled() {
393		ctx = tracing.StartSpan(ctx, fqdn+"/DataSetsClient.ListByShare")
394		defer func() {
395			sc := -1
396			if result.Response().Response.Response != nil {
397				sc = result.page.Response().Response.Response.StatusCode
398			}
399			tracing.EndSpan(ctx, sc, err)
400		}()
401	}
402	result.page, err = client.ListByShare(ctx, resourceGroupName, accountName, shareName, skipToken)
403	return
404}
405