| 1 |
package blobs |
| 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 |
) |
| 13 |
|
| 14 |
// SetTier sets the tier on a blob. |
| 15 |
func (client Client) SetTier(ctx context.Context, accountName, containerName, blobName string, tier AccessTier) (result autorest.Response, err error) { |
| 16 |
if accountName == "" { |
| 17 |
return result, validation.NewError("blobs.Client", "SetTier", "`accountName` cannot be an empty string.") |
| 18 |
} |
| 19 |
if containerName == "" { |
| 20 |
return result, validation.NewError("blobs.Client", "SetTier", "`containerName` cannot be an empty string.") |
| 21 |
} |
| 22 |
if strings.ToLower(containerName) != containerName { |
| 23 |
return result, validation.NewError("blobs.Client", "SetTier", "`containerName` must be a lower-cased string.") |
| 24 |
} |
| 25 |
if blobName == "" { |
| 26 |
return result, validation.NewError("blobs.Client", "SetTier", "`blobName` cannot be an empty string.") |
| 27 |
} |
| 28 |
|
| 29 |
req, err := client.SetTierPreparer(ctx, accountName, containerName, blobName, tier) |
| 30 |
if err != nil { |
| 31 |
err = autorest.NewErrorWithError(err, "blobs.Client", "SetTier", nil, "Failure preparing request") |
| 32 |
return |
| 33 |
} |
| 34 |
|
| 35 |
resp, err := client.SetTierSender(req) |
| 36 |
if err != nil { |
| 37 |
result = autorest.Response{Response: resp} |
| 38 |
err = autorest.NewErrorWithError(err, "blobs.Client", "SetTier", resp, "Failure sending request") |
| 39 |
return |
| 40 |
} |
| 41 |
|
| 42 |
result, err = client.SetTierResponder(resp) |
| 43 |
if err != nil { |
| 44 |
err = autorest.NewErrorWithError(err, "blobs.Client", "SetTier", resp, "Failure responding to request") |
| 45 |
return |
| 46 |
} |
| 47 |
|
| 48 |
return |
| 49 |
} |
| 50 |
|
| 51 |
// SetTierPreparer prepares the SetTier request. |
| 52 |
func (client Client) SetTierPreparer(ctx context.Context, accountName, containerName, blobName string, tier AccessTier) (*http.Request, error) { |
| 53 |
pathParameters := map[string]interface{}{ |
| 54 |
"containerName": autorest.Encode("path", containerName), |
| 55 |
"blobName": autorest.Encode("path", blobName), |
| 56 |
} |
| 57 |
|
| 58 |
queryParameters := map[string]interface{}{ |
| 59 |
"comp": autorest.Encode("path", "tier"), |
| 60 |
} |
| 61 |
|
| 62 |
headers := map[string]interface{}{ |
| 63 |
"x-ms-version": APIVersion, |
| 64 |
"x-ms-access-tier": string(tier), |
| 65 |
} |
| 66 |
|
| 67 |
preparer := autorest.CreatePreparer( |
| 68 |
autorest.AsPut(), |
| 69 |
autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), |
| 70 |
autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), |
| 71 |
autorest.WithQueryParameters(queryParameters), |
| 72 |
autorest.WithHeaders(headers)) |
| 73 |
return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 74 |
} |
| 75 |
|
| 76 |
// SetTierSender sends the SetTier request. The method will close the |
| 77 |
// http.Response Body if it receives an error. |
| 78 |
func (client Client) SetTierSender(req *http.Request) (*http.Response, error) { |
| 79 |
return autorest.SendWithSender(client, req, |
| 80 |
azure.DoRetryWithRegistration(client.Client)) |
| 81 |
} |
| 82 |
|
| 83 |
// SetTierResponder handles the response to the SetTier request. The method always |
| 84 |
// closes the http.Response Body. |
| 85 |
func (client Client) SetTierResponder(resp *http.Response) (result autorest.Response, err error) { |
| 86 |
err = autorest.Respond( |
| 87 |
resp, |
| 88 |
client.ByInspecting(), |
| 89 |
azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), |
| 90 |
autorest.ByClosing()) |
| 91 |
result = autorest.Response{Response: resp} |
| 92 |
return |
| 93 |
} |