1package filesystems 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 13type CreateInput struct { 14 // A map of base64-encoded strings to store as user-defined properties with the File System 15 // Note that items may only contain ASCII characters in the ISO-8859-1 character set. 16 // This automatically gets converted to a comma-separated list of name and 17 // value pairs before sending to the API 18 Properties map[string]string 19} 20 21// Create creates a Data Lake Store Gen2 FileSystem within a Storage Account 22func (client Client) Create(ctx context.Context, accountName string, fileSystemName string, input CreateInput) (result autorest.Response, err error) { 23 if accountName == "" { 24 return result, validation.NewError("datalakestore.Client", "Create", "`accountName` cannot be an empty string.") 25 } 26 if fileSystemName == "" { 27 return result, validation.NewError("datalakestore.Client", "Create", "`fileSystemName` cannot be an empty string.") 28 } 29 30 req, err := client.CreatePreparer(ctx, accountName, fileSystemName, input) 31 if err != nil { 32 err = autorest.NewErrorWithError(err, "datalakestore.Client", "Create", nil, "Failure preparing request") 33 return 34 } 35 36 resp, err := client.CreateSender(req) 37 if err != nil { 38 result = autorest.Response{Response: resp} 39 err = autorest.NewErrorWithError(err, "datalakestore.Client", "Create", resp, "Failure sending request") 40 return 41 } 42 43 result, err = client.CreateResponder(resp) 44 if err != nil { 45 err = autorest.NewErrorWithError(err, "datalakestore.Client", "Create", resp, "Failure responding to request") 46 } 47 48 return 49} 50 51// CreatePreparer prepares the Create request. 52func (client Client) CreatePreparer(ctx context.Context, accountName string, fileSystemName string, input CreateInput) (*http.Request, error) { 53 pathParameters := map[string]interface{}{ 54 "fileSystemName": autorest.Encode("path", fileSystemName), 55 } 56 57 queryParameters := map[string]interface{}{ 58 "resource": autorest.Encode("query", "filesystem"), 59 } 60 61 headers := map[string]interface{}{ 62 "x-ms-properties": buildProperties(input.Properties), 63 "x-ms-version": APIVersion, 64 } 65 66 preparer := autorest.CreatePreparer( 67 autorest.AsPut(), 68 autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), 69 autorest.WithPathParameters("/{fileSystemName}", pathParameters), 70 autorest.WithQueryParameters(queryParameters), 71 autorest.WithHeaders(headers)) 72 73 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 74} 75 76// CreateSender sends the Create request. The method will close the 77// http.Response Body if it receives an error. 78func (client Client) CreateSender(req *http.Request) (*http.Response, error) { 79 return autorest.SendWithSender(client, req, 80 azure.DoRetryWithRegistration(client.Client)) 81} 82 83// CreateResponder handles the response to the Create request. The method always 84// closes the http.Response Body. 85func (client Client) CreateResponder(resp *http.Response) (result autorest.Response, err error) { 86 err = autorest.Respond( 87 resp, 88 client.ByInspecting(), 89 azure.WithErrorUnlessStatusCode(http.StatusCreated), 90 autorest.ByClosing()) 91 result = autorest.Response{Response: resp} 92 93 return 94} 95