| 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 |
type SetPropertiesInput struct { |
| 15 |
CacheControl *string |
| 16 |
ContentType *string |
| 17 |
ContentMD5 *string |
| 18 |
ContentEncoding *string |
| 19 |
ContentLanguage *string |
| 20 |
LeaseID *string |
| 21 |
ContentDisposition *string |
| 22 |
ContentLength *int64 |
| 23 |
SequenceNumberAction *SequenceNumberAction |
| 24 |
BlobSequenceNumber *string |
| 25 |
} |
| 26 |
|
| 27 |
type SetPropertiesResult struct { |
| 28 |
autorest.Response |
| 29 |
|
| 30 |
BlobSequenceNumber string |
| 31 |
Etag string |
| 32 |
} |
| 33 |
|
| 34 |
// SetProperties sets system properties on the blob. |
| 35 |
func (client Client) SetProperties(ctx context.Context, accountName, containerName, blobName string, input SetPropertiesInput) (result SetPropertiesResult, err error) { |
| 36 |
if accountName == "" { |
| 37 |
return result, validation.NewError("blobs.Client", "SetProperties", "`accountName` cannot be an empty string.") |
| 38 |
} |
| 39 |
if containerName == "" { |
| 40 |
return result, validation.NewError("blobs.Client", "SetProperties", "`containerName` cannot be an empty string.") |
| 41 |
} |
| 42 |
if strings.ToLower(containerName) != containerName { |
| 43 |
return result, validation.NewError("blobs.Client", "SetProperties", "`containerName` must be a lower-cased string.") |
| 44 |
} |
| 45 |
if blobName == "" { |
| 46 |
return result, validation.NewError("blobs.Client", "SetProperties", "`blobName` cannot be an empty string.") |
| 47 |
} |
| 48 |
|
| 49 |
req, err := client.SetPropertiesPreparer(ctx, accountName, containerName, blobName, input) |
| 50 |
if err != nil { |
| 51 |
err = autorest.NewErrorWithError(err, "blobs.Client", "SetProperties", nil, "Failure preparing request") |
| 52 |
return |
| 53 |
} |
| 54 |
|
| 55 |
resp, err := client.SetPropertiesSender(req) |
| 56 |
if err != nil { |
| 57 |
result.Response = autorest.Response{Response: resp} |
| 58 |
err = autorest.NewErrorWithError(err, "blobs.Client", "SetProperties", resp, "Failure sending request") |
| 59 |
return |
| 60 |
} |
| 61 |
|
| 62 |
result, err = client.SetPropertiesResponder(resp) |
| 63 |
if err != nil { |
| 64 |
err = autorest.NewErrorWithError(err, "blobs.Client", "SetProperties", resp, "Failure responding to request") |
| 65 |
return |
| 66 |
} |
| 67 |
|
| 68 |
return |
| 69 |
} |
| 70 |
|
| 71 |
type SequenceNumberAction string |
| 72 |
|
| 73 |
var ( |
| 74 |
Increment SequenceNumberAction = "increment" |
| 75 |
Max SequenceNumberAction = "max" |
| 76 |
Update SequenceNumberAction = "update" |
| 77 |
) |
| 78 |
|
| 79 |
// SetPropertiesPreparer prepares the SetProperties request. |
| 80 |
func (client Client) SetPropertiesPreparer(ctx context.Context, accountName, containerName, blobName string, input SetPropertiesInput) (*http.Request, error) { |
| 81 |
pathParameters := map[string]interface{}{ |
| 82 |
"containerName": autorest.Encode("path", containerName), |
| 83 |
"blobName": autorest.Encode("path", blobName), |
| 84 |
} |
| 85 |
|
| 86 |
queryParameters := map[string]interface{}{ |
| 87 |
"comp": autorest.Encode("query", "properties"), |
| 88 |
} |
| 89 |
|
| 90 |
headers := map[string]interface{}{ |
| 91 |
"x-ms-version": APIVersion, |
| 92 |
} |
| 93 |
|
| 94 |
if input.CacheControl != nil { |
| 95 |
headers["x-ms-blob-cache-control"] = *input.CacheControl |
| 96 |
} |
| 97 |
if input.ContentDisposition != nil { |
| 98 |
headers["x-ms-blob-content-disposition"] = *input.ContentDisposition |
| 99 |
} |
| 100 |
if input.ContentEncoding != nil { |
| 101 |
headers["x-ms-blob-content-encoding"] = *input.ContentEncoding |
| 102 |
} |
| 103 |
if input.ContentLanguage != nil { |
| 104 |
headers["x-ms-blob-content-language"] = *input.ContentLanguage |
| 105 |
} |
| 106 |
if input.ContentMD5 != nil { |
| 107 |
headers["x-ms-blob-content-md5"] = *input.ContentMD5 |
| 108 |
} |
| 109 |
if input.ContentType != nil { |
| 110 |
headers["x-ms-blob-content-type"] = *input.ContentType |
| 111 |
} |
| 112 |
if input.ContentLength != nil { |
| 113 |
headers["x-ms-blob-content-length"] = *input.ContentLength |
| 114 |
} |
| 115 |
if input.LeaseID != nil { |
| 116 |
headers["x-ms-lease-id"] = *input.LeaseID |
| 117 |
} |
| 118 |
if input.SequenceNumberAction != nil { |
| 119 |
headers["x-ms-sequence-number-action"] = string(*input.SequenceNumberAction) |
| 120 |
} |
| 121 |
if input.BlobSequenceNumber != nil { |
| 122 |
headers["x-ms-blob-sequence-number"] = *input.BlobSequenceNumber |
| 123 |
} |
| 124 |
|
| 125 |
preparer := autorest.CreatePreparer( |
| 126 |
autorest.AsPut(), |
| 127 |
autorest.WithBaseURL(endpoints.GetBlobEndpoint(client.BaseURI, accountName)), |
| 128 |
autorest.WithPathParameters("/{containerName}/{blobName}", pathParameters), |
| 129 |
autorest.WithHeaders(headers), |
| 130 |
autorest.WithQueryParameters(queryParameters)) |
| 131 |
return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 132 |
} |
| 133 |
|
| 134 |
// SetPropertiesSender sends the SetProperties request. The method will close the |
| 135 |
// http.Response Body if it receives an error. |
| 136 |
func (client Client) SetPropertiesSender(req *http.Request) (*http.Response, error) { |
| 137 |
return autorest.SendWithSender(client, req, |
| 138 |
azure.DoRetryWithRegistration(client.Client)) |
| 139 |
} |
| 140 |
|
| 141 |
// SetPropertiesResponder handles the response to the SetProperties request. The method always |
| 142 |
// closes the http.Response Body. |
| 143 |
func (client Client) SetPropertiesResponder(resp *http.Response) (result SetPropertiesResult, err error) { |
| 144 |
if resp != nil && resp.Header != nil { |
| 145 |
result.BlobSequenceNumber = resp.Header.Get("x-ms-blob-sequence-number") |
| 146 |
result.Etag = resp.Header.Get("Etag") |
| 147 |
} |
| 148 |
|
| 149 |
err = autorest.Respond( |
| 150 |
resp, |
| 151 |
client.ByInspecting(), |
| 152 |
azure.WithErrorUnlessStatusCode(http.StatusOK), |
| 153 |
autorest.ByClosing()) |
| 154 |
result.Response = autorest.Response{Response: resp} |
| 155 |
return |
| 156 |
} |