Debian Codegraph @

storage/2020-08-04/file/shares/properties_get.go

raw
1 package shares
2
3 import (
4 "context"
5 "fmt"
6 "net/http"
7 "strconv"
8 "strings"
9
10 "github.com/Azure/go-autorest/autorest"
11 "github.com/Azure/go-autorest/autorest/azure"
12 "github.com/Azure/go-autorest/autorest/validation"
13 "github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
14 "github.com/tombuildsstuff/giovanni/storage/internal/metadata"
15 )
16
17 type GetPropertiesResult struct {
18 autorest.Response
19
20 MetaData map[string]string
21 QuotaInGB int
22 EnabledProtocol ShareProtocol
23 AccessTier *AccessTier
24 }
25
26 // GetProperties returns the properties about the specified Storage Share
27 func (client Client) GetProperties(ctx context.Context, accountName, shareName string) (result GetPropertiesResult, err error) {
28 if accountName == "" {
29 return result, validation.NewError("shares.Client", "GetProperties", "`accountName` cannot be an empty string.")
30 }
31 if shareName == "" {
32 return result, validation.NewError("shares.Client", "GetProperties", "`shareName` cannot be an empty string.")
33 }
34 if strings.ToLower(shareName) != shareName {
35 return result, validation.NewError("shares.Client", "GetProperties", "`shareName` must be a lower-cased string.")
36 }
37
38 req, err := client.GetPropertiesPreparer(ctx, accountName, shareName)
39 if err != nil {
40 err = autorest.NewErrorWithError(err, "shares.Client", "GetProperties", nil, "Failure preparing request")
41 return
42 }
43
44 resp, err := client.GetPropertiesSender(req)
45 if err != nil {
46 result.Response = autorest.Response{Response: resp}
47 err = autorest.NewErrorWithError(err, "shares.Client", "GetProperties", resp, "Failure sending request")
48 return
49 }
50
51 result, err = client.GetPropertiesResponder(resp)
52 if err != nil {
53 err = autorest.NewErrorWithError(err, "shares.Client", "GetProperties", resp, "Failure responding to request")
54 return
55 }
56
57 return
58 }
59
60 // GetPropertiesPreparer prepares the GetProperties request.
61 func (client Client) GetPropertiesPreparer(ctx context.Context, accountName, shareName string) (*http.Request, error) {
62 pathParameters := map[string]interface{}{
63 "shareName": autorest.Encode("path", shareName),
64 }
65
66 queryParameters := map[string]interface{}{
67 "restype": autorest.Encode("query", "share"),
68 }
69
70 headers := map[string]interface{}{
71 "x-ms-version": APIVersion,
72 }
73
74 preparer := autorest.CreatePreparer(
75 autorest.AsContentType("application/xml; charset=utf-8"),
76 autorest.AsGet(),
77 autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)),
78 autorest.WithPathParameters("/{shareName}", pathParameters),
79 autorest.WithQueryParameters(queryParameters),
80 autorest.WithHeaders(headers))
81 return preparer.Prepare((&http.Request{}).WithContext(ctx))
82 }
83
84 // GetPropertiesSender sends the GetProperties request. The method will close the
85 // http.Response Body if it receives an error.
86 func (client Client) GetPropertiesSender(req *http.Request) (*http.Response, error) {
87 return autorest.SendWithSender(client, req,
88 azure.DoRetryWithRegistration(client.Client))
89 }
90
91 // GetPropertiesResponder handles the response to the GetProperties request. The method always
92 // closes the http.Response Body.
93 func (client Client) GetPropertiesResponder(resp *http.Response) (result GetPropertiesResult, err error) {
94 if resp.Header != nil {
95 result.MetaData = metadata.ParseFromHeaders(resp.Header)
96
97 quotaRaw := resp.Header.Get("x-ms-share-quota")
98 if quotaRaw != "" {
99 quota, e := strconv.Atoi(quotaRaw)
100 if e != nil {
101 return result, fmt.Errorf("Error converting %q to an integer: %s", quotaRaw, err)
102 }
103 result.QuotaInGB = quota
104 }
105
106 protocol := SMB
107 if protocolRaw := resp.Header.Get("x-ms-enabled-protocols"); protocolRaw != "" {
108 protocol = ShareProtocol(protocolRaw)
109 }
110
111 if accessTierRaw := resp.Header.Get("x-ms-access-tier"); accessTierRaw != "" {
112 tier := AccessTier(accessTierRaw)
113 result.AccessTier = &tier
114 }
115 result.EnabledProtocol = protocol
116 }
117
118 err = autorest.Respond(
119 resp,
120 client.ByInspecting(),
121 azure.WithErrorUnlessStatusCode(http.StatusOK),
122 autorest.ByClosing())
123 result.Response = autorest.Response{Response: resp}
124
125 return
126 }