Debian Codegraph @

storage/2018-03-28/datalakestore/filesystems/properties_get.go

raw
1 package filesystems
2
3 import (
4 "context"
5 "net/http"
6 "strings"
7
8 "github.com/Azure/go-autorest/autorest"
9 "github.com/Azure/go-autorest/autorest/azure"
10 "github.com/Azure/go-autorest/autorest/validation"
11 "github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
12 )
13
14 type GetPropertiesResponse struct {
15 autorest.Response
16
17 // A map of base64-encoded strings to store as user-defined properties with the File System
18 // Note that items may only contain ASCII characters in the ISO-8859-1 character set.
19 // This automatically gets converted to a comma-separated list of name and
20 // value pairs before sending to the API
21 Properties map[string]string
22
23 // Is Hierarchical Namespace Enabled?
24 NamespaceEnabled bool
25 }
26
27 // GetProperties gets the properties for a Data Lake Store Gen2 FileSystem within a Storage Account
28 func (client Client) GetProperties(ctx context.Context, accountName string, fileSystemName string) (result GetPropertiesResponse, err error) {
29 if accountName == "" {
30 return result, validation.NewError("datalakestore.Client", "GetProperties", "`accountName` cannot be an empty string.")
31 }
32 if fileSystemName == "" {
33 return result, validation.NewError("datalakestore.Client", "GetProperties", "`fileSystemName` cannot be an empty string.")
34 }
35
36 req, err := client.GetPropertiesPreparer(ctx, accountName, fileSystemName)
37 if err != nil {
38 err = autorest.NewErrorWithError(err, "datalakestore.Client", "GetProperties", nil, "Failure preparing request")
39 return
40 }
41
42 resp, err := client.GetPropertiesSender(req)
43 if err != nil {
44 result.Response = autorest.Response{Response: resp}
45 err = autorest.NewErrorWithError(err, "datalakestore.Client", "GetProperties", resp, "Failure sending request")
46 return
47 }
48
49 result, err = client.GetPropertiesResponder(resp)
50 if err != nil {
51 err = autorest.NewErrorWithError(err, "datalakestore.Client", "GetProperties", resp, "Failure responding to request")
52 }
53
54 return
55 }
56
57 // GetPropertiesPreparer prepares the GetProperties request.
58 func (client Client) GetPropertiesPreparer(ctx context.Context, accountName string, fileSystemName string) (*http.Request, error) {
59 pathParameters := map[string]interface{}{
60 "fileSystemName": autorest.Encode("path", fileSystemName),
61 }
62
63 queryParameters := map[string]interface{}{
64 "resource": autorest.Encode("query", "filesystem"),
65 }
66
67 headers := map[string]interface{}{
68 "x-ms-version": APIVersion,
69 }
70
71 preparer := autorest.CreatePreparer(
72 autorest.AsHead(),
73 autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)),
74 autorest.WithPathParameters("/{fileSystemName}", pathParameters),
75 autorest.WithQueryParameters(queryParameters),
76 autorest.WithHeaders(headers))
77
78 return preparer.Prepare((&http.Request{}).WithContext(ctx))
79 }
80
81 // GetPropertiesSender sends the GetProperties request. The method will close the
82 // http.Response Body if it receives an error.
83 func (client Client) GetPropertiesSender(req *http.Request) (*http.Response, error) {
84 return autorest.SendWithSender(client, req,
85 azure.DoRetryWithRegistration(client.Client))
86 }
87
88 // GetPropertiesResponder handles the response to the GetProperties request. The method always
89 // closes the http.Response Body.
90 func (client Client) GetPropertiesResponder(resp *http.Response) (result GetPropertiesResponse, err error) {
91 if resp != nil && resp.Header != nil {
92
93 propertiesRaw := resp.Header.Get("x-ms-properties")
94 var properties *map[string]string
95 properties, err = parseProperties(propertiesRaw)
96 if err != nil {
97 return
98 }
99
100 result.Properties = *properties
101 result.NamespaceEnabled = strings.EqualFold(resp.Header.Get("x-ms-namespace-enabled"), "tru")
102 }
103
104 err = autorest.Respond(
105 resp,
106 client.ByInspecting(),
107 azure.WithErrorUnlessStatusCode(http.StatusOK),
108 autorest.ByClosing())
109 result.Response = autorest.Response{Response: resp}
110
111 return
112 }