| 1 | package paths |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "net/http" |
| 6 | |
| 7 | "github.com/Azure/go-autorest/autorest" |
| 8 | "github.com/Azure/go-autorest/autorest/azure" |
| 9 | "github.com/Azure/go-autorest/autorest/validation" |
| 10 | "github.com/tombuildsstuff/giovanni/storage/internal/endpoints" |
| 11 | ) |
| 12 | |
| 13 | type SetAccessControlInput struct { |
| 14 | Owner *string |
| 15 | Group *string |
| 16 | ACL *string |
| 17 | |
| 18 | // Optional - A date and time value. |
| 19 | // Specify this header to perform the operation only if the resource has been modified since the specified date and time. |
| 20 | IfModifiedSince *string |
| 21 | |
| 22 | // Optional - A date and time value. |
| 23 | // Specify this header to perform the operation only if the resource has not been modified since the specified date and time. |
| 24 | IfUnmodifiedSince *string |
| 25 | } |
| 26 | |
| 27 | // SetProperties sets the access control properties for a Data Lake Store Gen2 Path within a Storage Account File System |
| 28 | func (client Client) SetAccessControl(ctx context.Context, accountName string, fileSystemName string, path string, input SetAccessControlInput) (result autorest.Response, err error) { |
| 29 | if accountName == "" { |
| 30 | return result, validation.NewError("datalakestore.Client", "SetAccessControl", "`accountName` cannot be an empty string.") |
| 31 | } |
| 32 | if fileSystemName == "" { |
| 33 | return result, validation.NewError("datalakestore.Client", "SetAccessControl", "`fileSystemName` cannot be an empty string.") |
| 34 | } |
| 35 | |
| 36 | req, err := client.SetAccessControlPreparer(ctx, accountName, fileSystemName, path, input) |
| 37 | if err != nil { |
| 38 | err = autorest.NewErrorWithError(err, "datalakestore.Client", "SetAccessControl", nil, "Failure preparing request") |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | resp, err := client.SetAccessControlSender(req) |
| 43 | if err != nil { |
| 44 | result = autorest.Response{Response: resp} |
| 45 | err = autorest.NewErrorWithError(err, "datalakestore.Client", "SetAccessControl", resp, "Failure sending request") |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | result, err = client.SetAccessControlResponder(resp) |
| 50 | if err != nil { |
| 51 | err = autorest.NewErrorWithError(err, "datalakestore.Client", "SetAccessControl", resp, "Failure responding to request") |
| 52 | } |
| 53 | |
| 54 | return |
| 55 | } |
| 56 | |
| 57 | // SetAccessControlPreparer prepares the SetAccessControl request. |
| 58 | func (client Client) SetAccessControlPreparer(ctx context.Context, accountName string, fileSystemName string, path string, input SetAccessControlInput) (*http.Request, error) { |
| 59 | pathParameters := map[string]interface{}{ |
| 60 | "fileSystemName": autorest.Encode("path", fileSystemName), |
| 61 | "path": autorest.Encode("path", path), |
| 62 | } |
| 63 | |
| 64 | queryParameters := map[string]interface{}{ |
| 65 | "action": autorest.Encode("query", "setAccessControl"), |
| 66 | } |
| 67 | |
| 68 | headers := map[string]interface{}{ |
| 69 | "x-ms-version": APIVersion, |
| 70 | } |
| 71 | |
| 72 | if input.Owner != nil { |
| 73 | headers["x-ms-owner"] = *input.Owner |
| 74 | } |
| 75 | if input.Group != nil { |
| 76 | headers["x-ms-group"] = *input.Group |
| 77 | } |
| 78 | if input.ACL != nil { |
| 79 | headers["x-ms-acl"] = *input.ACL |
| 80 | } |
| 81 | |
| 82 | if input.IfModifiedSince != nil { |
| 83 | headers["If-Modified-Since"] = *input.IfModifiedSince |
| 84 | } |
| 85 | if input.IfUnmodifiedSince != nil { |
| 86 | headers["If-Unmodified-Since"] = *input.IfUnmodifiedSince |
| 87 | } |
| 88 | |
| 89 | preparer := autorest.CreatePreparer( |
| 90 | autorest.AsPatch(), |
| 91 | autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), |
| 92 | autorest.WithPathParameters("/{fileSystemName}/{path}", pathParameters), |
| 93 | autorest.WithQueryParameters(queryParameters), |
| 94 | autorest.WithHeaders(headers)) |
| 95 | |
| 96 | return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 97 | } |
| 98 | |
| 99 | // SetAccessControlSender sends the SetAccessControl request. The method will close the |
| 100 | // http.Response Body if it receives an error. |
| 101 | func (client Client) SetAccessControlSender(req *http.Request) (*http.Response, error) { |
| 102 | return autorest.SendWithSender(client, req, |
| 103 | azure.DoRetryWithRegistration(client.Client)) |
| 104 | } |
| 105 | |
| 106 | // SetAccessControlResponder handles the response to the SetAccessControl request. The method always |
| 107 | // closes the http.Response Body. |
| 108 | func (client Client) SetAccessControlResponder(resp *http.Response) (result autorest.Response, err error) { |
| 109 | err = autorest.Respond( |
| 110 | resp, |
| 111 | client.ByInspecting(), |
| 112 | azure.WithErrorUnlessStatusCode(http.StatusOK), |
| 113 | autorest.ByClosing()) |
| 114 | result = autorest.Response{Response: resp} |
| 115 | return |
| 116 | } |