Debian Codegraph @

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

raw
1 package shares
2
3 import (
4 "context"
5 "encoding/xml"
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 )
14
15 type setAcl struct {
16 SignedIdentifiers []SignedIdentifier `xml:"SignedIdentifier"`
17
18 XMLName xml.Name `xml:"SignedIdentifiers"`
19 }
20
21 // SetACL sets the specified Access Control List on the specified Storage Share
22 func (client Client) SetACL(ctx context.Context, accountName, shareName string, acls []SignedIdentifier) (result autorest.Response, err error) {
23 if accountName == "" {
24 return result, validation.NewError("shares.Client", "SetACL", "`accountName` cannot be an empty string.")
25 }
26 if shareName == "" {
27 return result, validation.NewError("shares.Client", "SetACL", "`shareName` cannot be an empty string.")
28 }
29 if strings.ToLower(shareName) != shareName {
30 return result, validation.NewError("shares.Client", "SetACL", "`shareName` must be a lower-cased string.")
31 }
32
33 req, err := client.SetACLPreparer(ctx, accountName, shareName, acls)
34 if err != nil {
35 err = autorest.NewErrorWithError(err, "shares.Client", "SetACL", nil, "Failure preparing request")
36 return
37 }
38
39 resp, err := client.SetACLSender(req)
40 if err != nil {
41 result = autorest.Response{Response: resp}
42 err = autorest.NewErrorWithError(err, "shares.Client", "SetACL", resp, "Failure sending request")
43 return
44 }
45
46 result, err = client.SetACLResponder(resp)
47 if err != nil {
48 err = autorest.NewErrorWithError(err, "shares.Client", "SetACL", resp, "Failure responding to request")
49 return
50 }
51
52 return
53 }
54
55 // SetACLPreparer prepares the SetACL request.
56 func (client Client) SetACLPreparer(ctx context.Context, accountName, shareName string, acls []SignedIdentifier) (*http.Request, error) {
57 pathParameters := map[string]interface{}{
58 "shareName": autorest.Encode("path", shareName),
59 }
60
61 queryParameters := map[string]interface{}{
62 "restype": autorest.Encode("query", "share"),
63 "comp": autorest.Encode("query", "acl"),
64 }
65
66 headers := map[string]interface{}{
67 "x-ms-version": APIVersion,
68 }
69
70 input := setAcl{
71 SignedIdentifiers: acls,
72 }
73
74 preparer := autorest.CreatePreparer(
75 autorest.AsContentType("application/xml; charset=utf-8"),
76 autorest.AsPut(),
77 autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)),
78 autorest.WithPathParameters("/{shareName}", pathParameters),
79 autorest.WithQueryParameters(queryParameters),
80 autorest.WithHeaders(headers),
81 autorest.WithXML(&input))
82 return preparer.Prepare((&http.Request{}).WithContext(ctx))
83 }
84
85 // SetACLSender sends the SetACL request. The method will close the
86 // http.Response Body if it receives an error.
87 func (client Client) SetACLSender(req *http.Request) (*http.Response, error) {
88 return autorest.SendWithSender(client, req,
89 azure.DoRetryWithRegistration(client.Client))
90 }
91
92 // SetACLResponder handles the response to the SetACL request. The method always
93 // closes the http.Response Body.
94 func (client Client) SetACLResponder(resp *http.Response) (result autorest.Response, err error) {
95 err = autorest.Respond(
96 resp,
97 client.ByInspecting(),
98 azure.WithErrorUnlessStatusCode(http.StatusOK),
99 autorest.ByClosing())
100 result = autorest.Response{Response: resp}
101
102 return
103 }