Debian Codegraph @

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