1package paths
2
3import (
4	"context"
5	"net/http"
6
7	"github.com/Azure/go-autorest/autorest"
8	"github.com/Azure/go-autorest/autorest/azure"
9	"github.com/Azure/go-autorest/autorest/validation"
10	"github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
11)
12
13// Delete deletes a Data Lake Store Gen2 FileSystem within a Storage Account
14func (client Client) Delete(ctx context.Context, accountName string, fileSystemName string, path string) (result autorest.Response, err error) {
15	if accountName == "" {
16		return result, validation.NewError("datalakestore.Client", "Delete", "`accountName` cannot be an empty string.")
17	}
18	if fileSystemName == "" {
19		return result, validation.NewError("datalakestore.Client", "Delete", "`fileSystemName` cannot be an empty string.")
20	}
21
22	req, err := client.DeletePreparer(ctx, accountName, fileSystemName, path)
23	if err != nil {
24		err = autorest.NewErrorWithError(err, "datalakestore.Client", "Delete", nil, "Failure preparing request")
25		return
26	}
27
28	resp, err := client.DeleteSender(req)
29	if err != nil {
30		result = autorest.Response{Response: resp}
31		err = autorest.NewErrorWithError(err, "datalakestore.Client", "Delete", resp, "Failure sending request")
32		return
33	}
34
35	result, err = client.DeleteResponder(resp)
36	if err != nil {
37		err = autorest.NewErrorWithError(err, "datalakestore.Client", "Delete", resp, "Failure responding to request")
38	}
39
40	return
41}
42
43// DeletePreparer prepares the Delete request.
44func (client Client) DeletePreparer(ctx context.Context, accountName string, fileSystemName string, path string) (*http.Request, error) {
45	pathParameters := map[string]interface{}{
46		"fileSystemName": autorest.Encode("path", fileSystemName),
47		"path":           autorest.Encode("path", path),
48	}
49
50	headers := map[string]interface{}{
51		"x-ms-version": APIVersion,
52	}
53
54	preparer := autorest.CreatePreparer(
55		autorest.AsDelete(),
56		autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)),
57		autorest.WithPathParameters("/{fileSystemName}/{path}", pathParameters),
58		autorest.WithHeaders(headers))
59
60	return preparer.Prepare((&http.Request{}).WithContext(ctx))
61}
62
63// DeleteSender sends the Delete request. The method will close the
64// http.Response Body if it receives an error.
65func (client Client) DeleteSender(req *http.Request) (*http.Response, error) {
66	return autorest.SendWithSender(client, req,
67		azure.DoRetryWithRegistration(client.Client))
68}
69
70// DeleteResponder handles the response to the Delete request. The method always
71// closes the http.Response Body.
72func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
73	err = autorest.Respond(
74		resp,
75		client.ByInspecting(),
76		azure.WithErrorUnlessStatusCode(http.StatusOK),
77		autorest.ByClosing())
78	result = autorest.Response{Response: resp}
79
80	return
81}
82