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