Debian Codegraph @

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

raw
1 package shares
2
3 import (
4 "context"
5 "fmt"
6 "net/http"
7 "strings"
8
9 "github.com/Azure/go-autorest/autorest"
10 "github.com/Azure/go-autorest/autorest/azure"
11 "github.com/Azure/go-autorest/autorest/validation"
12 "github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
13 "github.com/tombuildsstuff/giovanni/storage/internal/metadata"
14 )
15
16 // SetMetaData sets the MetaData on the specified Storage Share
17 func (client Client) SetMetaData(ctx context.Context, accountName, shareName string, metaData map[string]string) (result autorest.Response, err error) {
18 if accountName == "" {
19 return result, validation.NewError("shares.Client", "SetMetaData", "`accountName` cannot be an empty string.")
20 }
21 if shareName == "" {
22 return result, validation.NewError("shares.Client", "SetMetaData", "`shareName` cannot be an empty string.")
23 }
24 if strings.ToLower(shareName) != shareName {
25 return result, validation.NewError("shares.Client", "SetMetaData", "`shareName` must be a lower-cased string.")
26 }
27 if err := metadata.Validate(metaData); err != nil {
28 return result, validation.NewError("shares.Client", "SetMetaData", fmt.Sprintf("`metadata` is not valid: %s.", err))
29 }
30
31 req, err := client.SetMetaDataPreparer(ctx, accountName, shareName, metaData)
32 if err != nil {
33 err = autorest.NewErrorWithError(err, "shares.Client", "SetMetaData", nil, "Failure preparing request")
34 return
35 }
36
37 resp, err := client.SetMetaDataSender(req)
38 if err != nil {
39 result = autorest.Response{Response: resp}
40 err = autorest.NewErrorWithError(err, "shares.Client", "SetMetaData", resp, "Failure sending request")
41 return
42 }
43
44 result, err = client.SetMetaDataResponder(resp)
45 if err != nil {
46 err = autorest.NewErrorWithError(err, "shares.Client", "SetMetaData", resp, "Failure responding to request")
47 return
48 }
49
50 return
51 }
52
53 // SetMetaDataPreparer prepares the SetMetaData request.
54 func (client Client) SetMetaDataPreparer(ctx context.Context, accountName, shareName string, metaData map[string]string) (*http.Request, error) {
55 pathParameters := map[string]interface{}{
56 "shareName": autorest.Encode("path", shareName),
57 }
58
59 queryParameters := map[string]interface{}{
60 "restype": autorest.Encode("query", "share"),
61 "comp": autorest.Encode("query", "metadata"),
62 }
63
64 headers := map[string]interface{}{
65 "x-ms-version": APIVersion,
66 }
67 headers = metadata.SetIntoHeaders(headers, metaData)
68
69 preparer := autorest.CreatePreparer(
70 autorest.AsContentType("application/xml; charset=utf-8"),
71 autorest.AsPut(),
72 autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)),
73 autorest.WithPathParameters("/{shareName}", pathParameters),
74 autorest.WithQueryParameters(queryParameters),
75 autorest.WithHeaders(headers))
76 return preparer.Prepare((&http.Request{}).WithContext(ctx))
77 }
78
79 // SetPropertiesSetMetaDataSender sends the SetMetaData request. The method will close the
80 // http.Response Body if it receives an error.
81 func (client Client) SetMetaDataSender(req *http.Request) (*http.Response, error) {
82 return autorest.SendWithSender(client, req,
83 azure.DoRetryWithRegistration(client.Client))
84 }
85
86 // SetMetaDataResponder handles the response to the SetMetaData request. The method always
87 // closes the http.Response Body.
88 func (client Client) SetMetaDataResponder(resp *http.Response) (result autorest.Response, err error) {
89 err = autorest.Respond(
90 resp,
91 client.ByInspecting(),
92 azure.WithErrorUnlessStatusCode(http.StatusOK),
93 autorest.ByClosing())
94 result = autorest.Response{Response: resp}
95
96 return
97 }