| 1 |
package paths |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"net/http" |
| 6 |
"time" |
| 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 GetPropertiesResponse struct { |
| 15 |
autorest.Response |
| 16 |
|
| 17 |
ETag string |
| 18 |
LastModified time.Time |
| 19 |
// ResourceType is only returned for GetPropertiesActionGetStatus requests |
| 20 |
ResourceType PathResource |
| 21 |
Owner string |
| 22 |
Group string |
| 23 |
// ACL is only returned for GetPropertiesActionGetAccessControl requests |
| 24 |
ACL string |
| 25 |
} |
| 26 |
|
| 27 |
type GetPropertiesAction string |
| 28 |
|
| 29 |
const ( |
| 30 |
GetPropertiesActionGetStatus GetPropertiesAction = "getStatus" |
| 31 |
GetPropertiesActionGetAccessControl GetPropertiesAction = "getAccessControl" |
| 32 |
) |
| 33 |
|
| 34 |
// GetProperties gets the properties for a Data Lake Store Gen2 Path in a FileSystem within a Storage Account |
| 35 |
func (client Client) GetProperties(ctx context.Context, accountName string, fileSystemName string, path string, action GetPropertiesAction) (result GetPropertiesResponse, err error) { |
| 36 |
if accountName == "" { |
| 37 |
return result, validation.NewError("datalakestore.Client", "GetProperties", "`accountName` cannot be an empty string.") |
| 38 |
} |
| 39 |
if fileSystemName == "" { |
| 40 |
return result, validation.NewError("datalakestore.Client", "GetProperties", "`fileSystemName` cannot be an empty string.") |
| 41 |
} |
| 42 |
|
| 43 |
req, err := client.GetPropertiesPreparer(ctx, accountName, fileSystemName, path, action) |
| 44 |
if err != nil { |
| 45 |
err = autorest.NewErrorWithError(err, "datalakestore.Client", "GetProperties", nil, "Failure preparing request") |
| 46 |
return |
| 47 |
} |
| 48 |
|
| 49 |
resp, err := client.GetPropertiesSender(req) |
| 50 |
if err != nil { |
| 51 |
result.Response = autorest.Response{Response: resp} |
| 52 |
err = autorest.NewErrorWithError(err, "datalakestore.Client", "GetProperties", resp, "Failure sending request") |
| 53 |
return |
| 54 |
} |
| 55 |
|
| 56 |
result, err = client.GetPropertiesResponder(resp) |
| 57 |
if err != nil { |
| 58 |
err = autorest.NewErrorWithError(err, "datalakestore.Client", "GetProperties", resp, "Failure responding to request") |
| 59 |
} |
| 60 |
|
| 61 |
return |
| 62 |
} |
| 63 |
|
| 64 |
// GetPropertiesPreparer prepares the GetProperties request. |
| 65 |
func (client Client) GetPropertiesPreparer(ctx context.Context, accountName string, fileSystemName string, path string, action GetPropertiesAction) (*http.Request, error) { |
| 66 |
pathParameters := map[string]interface{}{ |
| 67 |
"fileSystemName": autorest.Encode("path", fileSystemName), |
| 68 |
"path": autorest.Encode("path", path), |
| 69 |
} |
| 70 |
|
| 71 |
queryParameters := map[string]interface{}{ |
| 72 |
"action": autorest.Encode("query", string(action)), |
| 73 |
} |
| 74 |
|
| 75 |
headers := map[string]interface{}{ |
| 76 |
"x-ms-version": APIVersion, |
| 77 |
} |
| 78 |
|
| 79 |
preparer := autorest.CreatePreparer( |
| 80 |
autorest.AsHead(), |
| 81 |
autorest.WithBaseURL(endpoints.GetDataLakeStoreEndpoint(client.BaseURI, accountName)), |
| 82 |
autorest.WithPathParameters("/{fileSystemName}/{path}", pathParameters), |
| 83 |
autorest.WithQueryParameters(queryParameters), |
| 84 |
autorest.WithHeaders(headers)) |
| 85 |
|
| 86 |
return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 87 |
} |
| 88 |
|
| 89 |
// GetPropertiesSender sends the GetProperties request. The method will close the |
| 90 |
// http.Response Body if it receives an error. |
| 91 |
func (client Client) GetPropertiesSender(req *http.Request) (*http.Response, error) { |
| 92 |
return autorest.SendWithSender(client, req, |
| 93 |
azure.DoRetryWithRegistration(client.Client)) |
| 94 |
} |
| 95 |
|
| 96 |
// GetPropertiesResponder handles the response to the GetProperties request. The method always |
| 97 |
// closes the http.Response Body. |
| 98 |
func (client Client) GetPropertiesResponder(resp *http.Response) (result GetPropertiesResponse, err error) { |
| 99 |
result = GetPropertiesResponse{} |
| 100 |
if resp != nil && resp.Header != nil { |
| 101 |
|
| 102 |
resourceTypeRaw := resp.Header.Get("x-ms-resource-type") |
| 103 |
var resourceType PathResource |
| 104 |
if resourceTypeRaw != "" { |
| 105 |
resourceType, err = parsePathResource(resourceTypeRaw) |
| 106 |
if err != nil { |
| 107 |
return GetPropertiesResponse{}, err |
| 108 |
} |
| 109 |
result.ResourceType = resourceType |
| 110 |
} |
| 111 |
result.ETag = resp.Header.Get("ETag") |
| 112 |
|
| 113 |
if lastModifiedRaw := resp.Header.Get("Last-Modified"); lastModifiedRaw != "" { |
| 114 |
lastModified, err := time.Parse(time.RFC1123, lastModifiedRaw) |
| 115 |
if err != nil { |
| 116 |
return GetPropertiesResponse{}, err |
| 117 |
} |
| 118 |
result.LastModified = lastModified |
| 119 |
} |
| 120 |
|
| 121 |
result.Owner = resp.Header.Get("x-ms-owner") |
| 122 |
result.Group = resp.Header.Get("x-ms-group") |
| 123 |
result.ACL = resp.Header.Get("x-ms-acl") |
| 124 |
} |
| 125 |
err = autorest.Respond( |
| 126 |
resp, |
| 127 |
client.ByInspecting(), |
| 128 |
azure.WithErrorUnlessStatusCode(http.StatusOK), |
| 129 |
|
| 130 |
autorest.ByClosing()) |
| 131 |
result.Response = autorest.Response{Response: resp} |
| 132 |
|
| 133 |
return result, err |
| 134 |
} |