| 1 | package paths |
| 2 | |
| 3 | import ( |
| 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 | type PathResource string |
| 14 | |
| 15 | const PathResourceFile PathResource = "file" |
| 16 | const PathResourceDirectory PathResource = "directory" |
| 17 | |
| 18 | type CreateInput struct { |
| 19 | Resource PathResource |
| 20 | } |
| 21 | |
| 22 | // Create creates a Data Lake Store Gen2 Path within a Storage Account |
| 23 | func (client Client) Create(ctx context.Context, accountName string, fileSystemName string, path string, input CreateInput) (result autorest.Response, err error) { |
| 24 | if accountName == "" { |
| 25 | return result, validation.NewError("datalakestore.Client", "Create", "`accountName` cannot be an empty string.") |
| 26 | } |
| 27 | if fileSystemName == "" { |
| 28 | return result, validation.NewError("datalakestore.Client", "Create", "`fileSystemName` cannot be an empty string.") |
| 29 | } |
| 30 | |
| 31 | req, err := client.CreatePreparer(ctx, accountName, fileSystemName, path, input) |
| 32 | if err != nil { |
| 33 | err = autorest.NewErrorWithError(err, "datalakestore.Client", "Create", nil, "Failure preparing request") |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | resp, err := client.CreateSender(req) |
| 38 | if err != nil { |
| 39 | result = autorest.Response{Response: resp} |
| 40 | err = autorest.NewErrorWithError(err, "datalakestore.Client", "Create", resp, "Failure sending request") |
| 41 | return |
| 42 | } |
| 43 | |
| 44 | result, err = client.CreateResponder(resp) |
| 45 | if err != nil { |
| 46 | err = autorest.NewErrorWithError(err, "datalakestore.Client", "Create", resp, "Failure responding to request") |
| 47 | } |
| 48 | |
| 49 | return |
| 50 | } |
| 51 | |
| 52 | // CreatePreparer prepares the Create request. |
| 53 | func (client Client) CreatePreparer(ctx context.Context, accountName string, fileSystemName string, path string, input CreateInput) (*http.Request, error) { |
| 54 | pathParameters := map[string]interface{}{ |
| 55 | "fileSystemName": autorest.Encode("path", fileSystemName), |
| 56 | "path": autorest.Encode("path", path), |
| 57 | } |
| 58 | |
| 59 | queryParameters := map[string]interface{}{ |
| 60 | "resource": autorest.Encode("query", input.Resource), |
| 61 | } |
| 62 | |
| 63 | headers := map[string]interface{}{ |
| 64 | "x-ms-version": APIVersion, |
| 65 | } |
| 66 | |
| 67 | preparer := autorest.CreatePreparer( |
| 68 | autorest.AsPut(), |
| 69 | autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), |
| 70 | autorest.WithPathParameters("/{fileSystemName}/{path}", pathParameters), |
| 71 | autorest.WithQueryParameters(queryParameters), |
| 72 | autorest.WithHeaders(headers)) |
| 73 | |
| 74 | return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 75 | } |
| 76 | |
| 77 | // CreateSender sends the Create request. The method will close the |
| 78 | // http.Response Body if it receives an error. |
| 79 | func (client Client) CreateSender(req *http.Request) (*http.Response, error) { |
| 80 | return autorest.SendWithSender(client, req, |
| 81 | azure.DoRetryWithRegistration(client.Client)) |
| 82 | } |
| 83 | |
| 84 | // CreateResponder handles the response to the Create request. The method always |
| 85 | // closes the http.Response Body. |
| 86 | func (client Client) CreateResponder(resp *http.Response) (result autorest.Response, err error) { |
| 87 | err = autorest.Respond( |
| 88 | resp, |
| 89 | client.ByInspecting(), |
| 90 | azure.WithErrorUnlessStatusCode(http.StatusCreated), |
| 91 | autorest.ByClosing()) |
| 92 | result = autorest.Response{Response: resp} |
| 93 | |
| 94 | return |
| 95 | } |