| 1 |
package files |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"fmt" |
| 6 |
"net/http" |
| 7 |
"strings" |
| 8 |
|
| 9 |
"github.com/Azure/go-autorest/autorest" |
| 10 |
"github.com/Azure/go-autorest/autorest/azure" |
| 11 |
"github.com/Azure/go-autorest/autorest/validation" |
| 12 |
"github.com/tombuildsstuff/giovanni/storage/internal/endpoints" |
| 13 |
) |
| 14 |
|
| 15 |
type SetPropertiesInput struct { |
| 16 |
// Resizes a file to the specified size. |
| 17 |
// If the specified byte value is less than the current size of the file, |
| 18 |
// then all ranges above the specified byte value are cleared. |
| 19 |
ContentLength *int64 |
| 20 |
|
| 21 |
// Modifies the cache control string for the file. |
| 22 |
// If this property is not specified on the request, then the property will be cleared for the file. |
| 23 |
// Subsequent calls to Get File Properties will not return this property, |
| 24 |
// unless it is explicitly set on the file again. |
| 25 |
ContentControl *string |
| 26 |
|
| 27 |
// Sets the file’s Content-Disposition header. |
| 28 |
// If this property is not specified on the request, then the property will be cleared for the file. |
| 29 |
// Subsequent calls to Get File Properties will not return this property, |
| 30 |
// unless it is explicitly set on the file again. |
| 31 |
ContentDisposition *string |
| 32 |
|
| 33 |
// Sets the file's content encoding. |
| 34 |
// If this property is not specified on the request, then the property will be cleared for the file. |
| 35 |
// Subsequent calls to Get File Properties will not return this property, |
| 36 |
// unless it is explicitly set on the file again. |
| 37 |
ContentEncoding *string |
| 38 |
|
| 39 |
// Sets the file's content language. |
| 40 |
// If this property is not specified on the request, then the property will be cleared for the file. |
| 41 |
// Subsequent calls to Get File Properties will not return this property, |
| 42 |
// unless it is explicitly set on the file again. |
| 43 |
ContentLanguage *string |
| 44 |
|
| 45 |
// Sets the file's MD5 hash. |
| 46 |
// If this property is not specified on the request, then the property will be cleared for the file. |
| 47 |
// Subsequent calls to Get File Properties will not return this property, |
| 48 |
// unless it is explicitly set on the file again. |
| 49 |
ContentMD5 *string |
| 50 |
|
| 51 |
// Sets the file's content type. |
| 52 |
// If this property is not specified on the request, then the property will be cleared for the file. |
| 53 |
// Subsequent calls to Get File Properties will not return this property, |
| 54 |
// unless it is explicitly set on the file again. |
| 55 |
ContentType *string |
| 56 |
} |
| 57 |
|
| 58 |
// SetProperties sets the specified properties on the specified File |
| 59 |
func (client Client) SetProperties(ctx context.Context, accountName, shareName, path, fileName string, input SetPropertiesInput) (result autorest.Response, err error) { |
| 60 |
if accountName == "" { |
| 61 |
return result, validation.NewError("files.Client", "SetProperties", "`accountName` cannot be an empty string.") |
| 62 |
} |
| 63 |
if shareName == "" { |
| 64 |
return result, validation.NewError("files.Client", "SetProperties", "`shareName` cannot be an empty string.") |
| 65 |
} |
| 66 |
if strings.ToLower(shareName) != shareName { |
| 67 |
return result, validation.NewError("files.Client", "SetProperties", "`shareName` must be a lower-cased string.") |
| 68 |
} |
| 69 |
if fileName == "" { |
| 70 |
return result, validation.NewError("files.Client", "SetProperties", "`fileName` cannot be an empty string.") |
| 71 |
} |
| 72 |
|
| 73 |
req, err := client.SetPropertiesPreparer(ctx, accountName, shareName, path, fileName, input) |
| 74 |
if err != nil { |
| 75 |
err = autorest.NewErrorWithError(err, "files.Client", "SetProperties", nil, "Failure preparing request") |
| 76 |
return |
| 77 |
} |
| 78 |
|
| 79 |
resp, err := client.SetPropertiesSender(req) |
| 80 |
if err != nil { |
| 81 |
result = autorest.Response{Response: resp} |
| 82 |
err = autorest.NewErrorWithError(err, "files.Client", "SetProperties", resp, "Failure sending request") |
| 83 |
return |
| 84 |
} |
| 85 |
|
| 86 |
result, err = client.SetPropertiesResponder(resp) |
| 87 |
if err != nil { |
| 88 |
err = autorest.NewErrorWithError(err, "files.Client", "SetProperties", resp, "Failure responding to request") |
| 89 |
return |
| 90 |
} |
| 91 |
|
| 92 |
return |
| 93 |
} |
| 94 |
|
| 95 |
// SetPropertiesPreparer prepares the SetProperties request. |
| 96 |
func (client Client) SetPropertiesPreparer(ctx context.Context, accountName, shareName, path, fileName string, input SetPropertiesInput) (*http.Request, error) { |
| 97 |
if path != "" { |
| 98 |
path = fmt.Sprintf("%s/", path) |
| 99 |
} |
| 100 |
pathParameters := map[string]interface{}{ |
| 101 |
"shareName": autorest.Encode("path", shareName), |
| 102 |
"directory": autorest.Encode("path", path), |
| 103 |
"fileName": autorest.Encode("path", fileName), |
| 104 |
} |
| 105 |
|
| 106 |
headers := map[string]interface{}{ |
| 107 |
"x-ms-version": APIVersion, |
| 108 |
"x-ms-type": "file", |
| 109 |
} |
| 110 |
|
| 111 |
if input.ContentControl != nil { |
| 112 |
headers["x-ms-cache-control"] = *input.ContentControl |
| 113 |
} |
| 114 |
if input.ContentDisposition != nil { |
| 115 |
headers["x-ms-content-disposition"] = *input.ContentDisposition |
| 116 |
} |
| 117 |
if input.ContentEncoding != nil { |
| 118 |
headers["x-ms-content-encoding"] = *input.ContentEncoding |
| 119 |
} |
| 120 |
if input.ContentLanguage != nil { |
| 121 |
headers["x-ms-content-language"] = *input.ContentLanguage |
| 122 |
} |
| 123 |
if input.ContentLength != nil { |
| 124 |
headers["x-ms-content-length"] = *input.ContentLength |
| 125 |
} |
| 126 |
if input.ContentMD5 != nil { |
| 127 |
headers["x-ms-content-md5"] = *input.ContentMD5 |
| 128 |
} |
| 129 |
if input.ContentType != nil { |
| 130 |
headers["x-ms-content-type"] = *input.ContentType |
| 131 |
} |
| 132 |
|
| 133 |
preparer := autorest.CreatePreparer( |
| 134 |
autorest.AsContentType("application/xml; charset=utf-8"), |
| 135 |
autorest.AsPut(), |
| 136 |
autorest.WithBaseURL(endpoints.GetFileEndpoint(client.BaseURI, accountName)), |
| 137 |
autorest.WithPathParameters("/{shareName}/{directory}{fileName}", pathParameters), |
| 138 |
autorest.WithHeaders(headers)) |
| 139 |
return preparer.Prepare((&http.Request{}).WithContext(ctx)) |
| 140 |
} |
| 141 |
|
| 142 |
// SetPropertiesSender sends the SetProperties request. The method will close the |
| 143 |
// http.Response Body if it receives an error. |
| 144 |
func (client Client) SetPropertiesSender(req *http.Request) (*http.Response, error) { |
| 145 |
return autorest.SendWithSender(client, req, |
| 146 |
azure.DoRetryWithRegistration(client.Client)) |
| 147 |
} |
| 148 |
|
| 149 |
// SetPropertiesResponder handles the response to the SetProperties request. The method always |
| 150 |
// closes the http.Response Body. |
| 151 |
func (client Client) SetPropertiesResponder(resp *http.Response) (result autorest.Response, err error) { |
| 152 |
err = autorest.Respond( |
| 153 |
resp, |
| 154 |
client.ByInspecting(), |
| 155 |
azure.WithErrorUnlessStatusCode(http.StatusCreated), |
| 156 |
autorest.ByClosing()) |
| 157 |
result = autorest.Response{Response: resp} |
| 158 |
|
| 159 |
return |
| 160 |
} |