Debian Codegraph @

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

raw
1 package shares
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 ShareProperties struct {
15 QuotaInGb *int
16 AccessTier *AccessTier
17 }
18
19 // SetProperties lets you update the Quota for the specified Storage Share
20 func (client Client) SetProperties(ctx context.Context, accountName, shareName string, properties ShareProperties) (result autorest.Response, err error) {
21 if accountName == "" {
22 return result, validation.NewError("shares.Client", "SetProperties", "`accountName` cannot be an empty string.")
23 }
24 if shareName == "" {
25 return result, validation.NewError("shares.Client", "SetProperties", "`shareName` cannot be an empty string.")
26 }
27 if strings.ToLower(shareName) != shareName {
28 return result, validation.NewError("shares.Client", "SetProperties", "`shareName` must be a lower-cased string.")
29 }
30 if newQuotaGB := properties.QuotaInGb; newQuotaGB != nil && (*newQuotaGB <= 0 || *newQuotaGB > 102400) {
31 return result, validation.NewError("shares.Client", "SetProperties", "`newQuotaGB` must be greater than 0, and less than/equal to 100TB (102400 GB)")
32 }
33
34 req, err := client.SetPropertiesPreparer(ctx, accountName, shareName, properties)
35 if err != nil {
36 err = autorest.NewErrorWithError(err, "shares.Client", "SetProperties", nil, "Failure preparing request")
37 return
38 }
39
40 resp, err := client.SetPropertiesSender(req)
41 if err != nil {
42 result = autorest.Response{Response: resp}
43 err = autorest.NewErrorWithError(err, "shares.Client", "SetProperties", resp, "Failure sending request")
44 return
45 }
46
47 result, err = client.SetPropertiesResponder(resp)
48 if err != nil {
49 err = autorest.NewErrorWithError(err, "shares.Client", "SetProperties", resp, "Failure responding to request")
50 return
51 }
52
53 return
54 }
55
56 // SetPropertiesPreparer prepares the SetProperties request.
57 func (client Client) SetPropertiesPreparer(ctx context.Context, accountName, shareName string, properties ShareProperties) (*http.Request, error) {
58 pathParameters := map[string]interface{}{
59 "shareName": autorest.Encode("path", shareName),
60 }
61
62 queryParameters := map[string]interface{}{
63 "restype": autorest.Encode("query", "share"),
64 "comp": autorest.Encode("query", "properties"),
65 }
66
67 headers := map[string]interface{}{
68 "x-ms-version": APIVersion,
69 }
70 if properties.QuotaInGb != nil {
71 headers["x-ms-share-quota"] = *properties.QuotaInGb
72 }
73
74 if properties.AccessTier != nil {
75 headers["x-ms-access-tier"] = string(*properties.AccessTier)
76 }
77
78 preparer := autorest.CreatePreparer(
79 autorest.AsContentType("application/xml; charset=utf-8"),
80 autorest.AsPut(),
81 autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)),
82 autorest.WithPathParameters("/{shareName}", pathParameters),
83 autorest.WithQueryParameters(queryParameters),
84 autorest.WithHeaders(headers))
85 return preparer.Prepare((&http.Request{}).WithContext(ctx))
86 }
87
88 // SetPropertiesSender sends the SetProperties request. The method will close the
89 // http.Response Body if it receives an error.
90 func (client Client) SetPropertiesSender(req *http.Request) (*http.Response, error) {
91 return autorest.SendWithSender(client, req,
92 azure.DoRetryWithRegistration(client.Client))
93 }
94
95 // SetPropertiesResponder handles the response to the SetProperties request. The method always
96 // closes the http.Response Body.
97 func (client Client) SetPropertiesResponder(resp *http.Response) (result autorest.Response, err error) {
98 err = autorest.Respond(
99 resp,
100 client.ByInspecting(),
101 azure.WithErrorUnlessStatusCode(http.StatusOK),
102 autorest.ByClosing())
103 result = autorest.Response{Response: resp}
104
105 return
106 }