| 1 | package shares |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "net/http" |
| 6 | "strings" |
| 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 | "github.com/tombuildsstuff/giovanni/storage/internal/metadata" |
| 13 | ) |
| 14 | |
| 15 | type GetMetaDataResult struct { |
| 16 | autorest.Response |
| 17 | |
| 18 | MetaData map[string]string |
| 19 | } |
| 20 | |
| 21 | // GetMetaData returns the MetaData associated with the specified Storage Share |
| 22 | func (client Client) GetMetaData(ctx context.Context, accountName, shareName string) (result GetMetaDataResult, err error) { |
| 23 | if accountName == "" { |
| 24 | return result, validation.NewError("shares.Client", "GetMetaData", "`accountName` cannot be an empty string.") |
| 25 | } |
| 26 | if shareName == "" { |
| 27 | return result, validation.NewError("shares.Client", "GetMetaData", "`shareName` cannot be an empty string.") |
| 28 | } |
| 29 | if strings.ToLower(shareName) != shareName { |
| 30 | return result, validation.NewError("shares.Client", "GetMetaData", "`shareName` must be a lower-cased string.") |
| 31 | } |
| 32 | |
| 33 | req, err := client.GetMetaDataPreparer(ctx, accountName, shareName) |
| 34 | if err != nil { |
| 35 | err = autorest.NewErrorWithError(err, "shares.Client", "GetMetaData", nil, "Failure preparing request") |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | resp, err := client.GetMetaDataSender(req) |
| 40 | if err != nil { |
| 41 | result.Response = autorest.Response{Response: resp} |
| 42 | err = autorest.NewErrorWithError(err, "shares.Client", "GetMetaData", resp, "Failure sending request") |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | result, err = client.GetMetaDataResponder(resp) |
| 47 | if err != nil { |
| 48 | err = autorest.NewErrorWithError(err, "shares.Client", "GetMetaData", resp, "Failure responding to request") |
| 49 | return |
| 50 | } |
| 51 | |
| 52 | return |
| 53 | } |
| 54 | |
| 55 | // GetMetaDataPreparer prepares the GetMetaData request. |
| 56 | func (client Client) GetMetaDataPreparer(ctx context.Context, accountName, shareName string) (*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", "metadata"), |
| 64 | } |
| 65 | |
| 66 | headers := map[string]interface{}{ |
| 67 | "x-ms-version": APIVersion, |
| 68 | } |
| 69 | |
| 70 | preparer := autorest.CreatePreparer( |
| 71 | autorest.AsContentType("application/xml; charset=utf-8"), |
| 72 | autorest.AsGet(), |
| 73 | autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), |
| 74 | autorest.WithPathParameters("/{shareName}", pathParameters), |
| 75 | autorest.WithQueryParameters(queryParameters), |
| 76 | autorest.WithHeaders(headers)) |
| 77 | return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 78 | } |
| 79 | |
| 80 | // GetMetaDataSender sends the GetMetaData request. The method will close the |
| 81 | // http.Response Body if it receives an error. |
| 82 | func (client Client) GetMetaDataSender(req *http.Request) (*http.Response, error) { |
| 83 | return autorest.SendWithSender(client, req, |
| 84 | azure.DoRetryWithRegistration(client.Client)) |
| 85 | } |
| 86 | |
| 87 | // GetMetaDataResponder handles the response to the GetMetaData request. The method always |
| 88 | // closes the http.Response Body. |
| 89 | func (client Client) GetMetaDataResponder(resp *http.Response) (result GetMetaDataResult, err error) { |
| 90 | if resp.Header != nil { |
| 91 | result.MetaData = metadata.ParseFromHeaders(resp.Header) |
| 92 | } |
| 93 | |
| 94 | err = autorest.Respond( |
| 95 | resp, |
| 96 | client.ByInspecting(), |
| 97 | azure.WithErrorUnlessStatusCode(http.StatusOK), |
| 98 | autorest.ByClosing()) |
| 99 | result.Response = autorest.Response{Response: resp} |
| 100 | |
| 101 | return |
| 102 | } |