1package azblob 2 3// Code generated by Microsoft (R) AutoRest Code Generator. 4// Changes may cause incorrect behavior and will be lost if the code is regenerated. 5 6import ( 7 "context" 8 "encoding/base64" 9 "github.com/Azure/azure-pipeline-go/pipeline" 10 "io" 11 "io/ioutil" 12 "net/http" 13 "net/url" 14 "strconv" 15 "time" 16) 17 18// appendBlobClient is the client for the AppendBlob methods of the Azblob service. 19type appendBlobClient struct { 20 managementClient 21} 22 23// newAppendBlobClient creates an instance of the appendBlobClient client. 24func newAppendBlobClient(url url.URL, p pipeline.Pipeline) appendBlobClient { 25 return appendBlobClient{newManagementClient(url, p)} 26} 27 28// AppendBlock the Append Block operation commits a new block of data to the end of an existing append blob. The Append 29// Block operation is permitted only if the blob was created with x-ms-blob-type set to AppendBlob. Append Block is 30// supported only on version 2015-02-21 version or later. 31// 32// body is initial data body will be closed upon successful return. Callers should ensure closure when receiving an 33// error.contentLength is the length of the request. timeout is the timeout parameter is expressed in seconds. For more 34// information, see <a 35// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 36// Timeouts for Blob Service Operations.</a> transactionalContentMD5 is specify the transactional md5 for the body, to 37// be validated by the service. leaseID is if specified, the operation only succeeds if the resource's lease is active 38// and matches this ID. maxSize is optional conditional header. The max length in bytes permitted for the append blob. 39// If the Append Block operation would cause the blob to exceed that limit or if the blob size is already greater than 40// the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error (HTTP status code 41// 412 - Precondition Failed). appendPosition is optional conditional header, used only for the Append Block operation. 42// A number indicating the byte offset to compare. Append Block will succeed only if the append position is equal to 43// this number. If it is not, the request will fail with the AppendPositionConditionNotMet error (HTTP status code 412 44// - Precondition Failed). ifModifiedSince is specify this header value to operate only on a blob if it has been 45// modified since the specified date/time. ifUnmodifiedSince is specify this header value to operate only on a blob if 46// it has not been modified since the specified date/time. ifMatch is specify an ETag value to operate only on blobs 47// with a matching value. ifNoneMatch is specify an ETag value to operate only on blobs without a matching value. 48// requestID is provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics 49// logs when storage analytics logging is enabled. 50func (client appendBlobClient) AppendBlock(ctx context.Context, body io.ReadSeeker, contentLength int64, timeout *int32, transactionalContentMD5 []byte, leaseID *string, maxSize *int64, appendPosition *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, requestID *string) (*AppendBlobAppendBlockResponse, error) { 51 if err := validate([]validation{ 52 {targetValue: body, 53 constraints: []constraint{{target: "body", name: null, rule: true, chain: nil}}}, 54 {targetValue: timeout, 55 constraints: []constraint{{target: "timeout", name: null, rule: false, 56 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 57 return nil, err 58 } 59 req, err := client.appendBlockPreparer(body, contentLength, timeout, transactionalContentMD5, leaseID, maxSize, appendPosition, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, requestID) 60 if err != nil { 61 return nil, err 62 } 63 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.appendBlockResponder}, req) 64 if err != nil { 65 return nil, err 66 } 67 return resp.(*AppendBlobAppendBlockResponse), err 68} 69 70// appendBlockPreparer prepares the AppendBlock request. 71func (client appendBlobClient) appendBlockPreparer(body io.ReadSeeker, contentLength int64, timeout *int32, transactionalContentMD5 []byte, leaseID *string, maxSize *int64, appendPosition *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, requestID *string) (pipeline.Request, error) { 72 req, err := pipeline.NewRequest("PUT", client.url, body) 73 if err != nil { 74 return req, pipeline.NewError(err, "failed to create request") 75 } 76 params := req.URL.Query() 77 if timeout != nil { 78 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 79 } 80 params.Set("comp", "appendblock") 81 req.URL.RawQuery = params.Encode() 82 req.Header.Set("Content-Length", strconv.FormatInt(contentLength, 10)) 83 if transactionalContentMD5 != nil { 84 req.Header.Set("Content-MD5", base64.StdEncoding.EncodeToString(transactionalContentMD5)) 85 } 86 if leaseID != nil { 87 req.Header.Set("x-ms-lease-id", *leaseID) 88 } 89 if maxSize != nil { 90 req.Header.Set("x-ms-blob-condition-maxsize", strconv.FormatInt(*maxSize, 10)) 91 } 92 if appendPosition != nil { 93 req.Header.Set("x-ms-blob-condition-appendpos", strconv.FormatInt(*appendPosition, 10)) 94 } 95 if ifModifiedSince != nil { 96 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 97 } 98 if ifUnmodifiedSince != nil { 99 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 100 } 101 if ifMatch != nil { 102 req.Header.Set("If-Match", string(*ifMatch)) 103 } 104 if ifNoneMatch != nil { 105 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 106 } 107 req.Header.Set("x-ms-version", ServiceVersion) 108 if requestID != nil { 109 req.Header.Set("x-ms-client-request-id", *requestID) 110 } 111 return req, nil 112} 113 114// appendBlockResponder handles the response to the AppendBlock request. 115func (client appendBlobClient) appendBlockResponder(resp pipeline.Response) (pipeline.Response, error) { 116 err := validateResponse(resp, http.StatusOK, http.StatusCreated) 117 if resp == nil { 118 return nil, err 119 } 120 io.Copy(ioutil.Discard, resp.Response().Body) 121 resp.Response().Body.Close() 122 return &AppendBlobAppendBlockResponse{rawResponse: resp.Response()}, err 123} 124 125// AppendBlockFromURL the Append Block operation commits a new block of data to the end of an existing append blob 126// where the contents are read from a source url. The Append Block operation is permitted only if the blob was created 127// with x-ms-blob-type set to AppendBlob. Append Block is supported only on version 2015-02-21 version or later. 128// 129// sourceURL is specify a URL to the copy source. contentLength is the length of the request. sourceRange is bytes of 130// source data in the specified range. sourceContentMD5 is specify the md5 calculated for the range of bytes that must 131// be read from the copy source. timeout is the timeout parameter is expressed in seconds. For more information, see <a 132// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 133// Timeouts for Blob Service Operations.</a> leaseID is if specified, the operation only succeeds if the resource's 134// lease is active and matches this ID. maxSize is optional conditional header. The max length in bytes permitted for 135// the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is 136// already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error 137// (HTTP status code 412 - Precondition Failed). appendPosition is optional conditional header, used only for the 138// Append Block operation. A number indicating the byte offset to compare. Append Block will succeed only if the append 139// position is equal to this number. If it is not, the request will fail with the AppendPositionConditionNotMet error 140// (HTTP status code 412 - Precondition Failed). ifModifiedSince is specify this header value to operate only on a blob 141// if it has been modified since the specified date/time. ifUnmodifiedSince is specify this header value to operate 142// only on a blob if it has not been modified since the specified date/time. ifMatch is specify an ETag value to 143// operate only on blobs with a matching value. ifNoneMatch is specify an ETag value to operate only on blobs without a 144// matching value. sourceIfModifiedSince is specify this header value to operate only on a blob if it has been modified 145// since the specified date/time. sourceIfUnmodifiedSince is specify this header value to operate only on a blob if it 146// has not been modified since the specified date/time. sourceIfMatch is specify an ETag value to operate only on blobs 147// with a matching value. sourceIfNoneMatch is specify an ETag value to operate only on blobs without a matching value. 148// requestID is provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics 149// logs when storage analytics logging is enabled. 150func (client appendBlobClient) AppendBlockFromURL(ctx context.Context, sourceURL string, contentLength int64, sourceRange *string, sourceContentMD5 []byte, timeout *int32, leaseID *string, maxSize *int64, appendPosition *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, sourceIfModifiedSince *time.Time, sourceIfUnmodifiedSince *time.Time, sourceIfMatch *ETag, sourceIfNoneMatch *ETag, requestID *string) (*AppendBlobAppendBlockFromURLResponse, error) { 151 if err := validate([]validation{ 152 {targetValue: timeout, 153 constraints: []constraint{{target: "timeout", name: null, rule: false, 154 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 155 return nil, err 156 } 157 req, err := client.appendBlockFromURLPreparer(sourceURL, contentLength, sourceRange, sourceContentMD5, timeout, leaseID, maxSize, appendPosition, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, sourceIfModifiedSince, sourceIfUnmodifiedSince, sourceIfMatch, sourceIfNoneMatch, requestID) 158 if err != nil { 159 return nil, err 160 } 161 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.appendBlockFromURLResponder}, req) 162 if err != nil { 163 return nil, err 164 } 165 return resp.(*AppendBlobAppendBlockFromURLResponse), err 166} 167 168// appendBlockFromURLPreparer prepares the AppendBlockFromURL request. 169func (client appendBlobClient) appendBlockFromURLPreparer(sourceURL string, contentLength int64, sourceRange *string, sourceContentMD5 []byte, timeout *int32, leaseID *string, maxSize *int64, appendPosition *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, sourceIfModifiedSince *time.Time, sourceIfUnmodifiedSince *time.Time, sourceIfMatch *ETag, sourceIfNoneMatch *ETag, requestID *string) (pipeline.Request, error) { 170 req, err := pipeline.NewRequest("PUT", client.url, nil) 171 if err != nil { 172 return req, pipeline.NewError(err, "failed to create request") 173 } 174 params := req.URL.Query() 175 if timeout != nil { 176 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 177 } 178 params.Set("comp", "appendblock") 179 req.URL.RawQuery = params.Encode() 180 req.Header.Set("x-ms-copy-source", sourceURL) 181 if sourceRange != nil { 182 req.Header.Set("x-ms-source-range", *sourceRange) 183 } 184 if sourceContentMD5 != nil { 185 req.Header.Set("x-ms-source-content-md5", base64.StdEncoding.EncodeToString(sourceContentMD5)) 186 } 187 req.Header.Set("Content-Length", strconv.FormatInt(contentLength, 10)) 188 if leaseID != nil { 189 req.Header.Set("x-ms-lease-id", *leaseID) 190 } 191 if maxSize != nil { 192 req.Header.Set("x-ms-blob-condition-maxsize", strconv.FormatInt(*maxSize, 10)) 193 } 194 if appendPosition != nil { 195 req.Header.Set("x-ms-blob-condition-appendpos", strconv.FormatInt(*appendPosition, 10)) 196 } 197 if ifModifiedSince != nil { 198 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 199 } 200 if ifUnmodifiedSince != nil { 201 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 202 } 203 if ifMatch != nil { 204 req.Header.Set("If-Match", string(*ifMatch)) 205 } 206 if ifNoneMatch != nil { 207 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 208 } 209 if sourceIfModifiedSince != nil { 210 req.Header.Set("x-ms-source-if-modified-since", (*sourceIfModifiedSince).In(gmt).Format(time.RFC1123)) 211 } 212 if sourceIfUnmodifiedSince != nil { 213 req.Header.Set("x-ms-source-if-unmodified-since", (*sourceIfUnmodifiedSince).In(gmt).Format(time.RFC1123)) 214 } 215 if sourceIfMatch != nil { 216 req.Header.Set("x-ms-source-if-match", string(*sourceIfMatch)) 217 } 218 if sourceIfNoneMatch != nil { 219 req.Header.Set("x-ms-source-if-none-match", string(*sourceIfNoneMatch)) 220 } 221 req.Header.Set("x-ms-version", ServiceVersion) 222 if requestID != nil { 223 req.Header.Set("x-ms-client-request-id", *requestID) 224 } 225 return req, nil 226} 227 228// appendBlockFromURLResponder handles the response to the AppendBlockFromURL request. 229func (client appendBlobClient) appendBlockFromURLResponder(resp pipeline.Response) (pipeline.Response, error) { 230 err := validateResponse(resp, http.StatusOK, http.StatusCreated) 231 if resp == nil { 232 return nil, err 233 } 234 io.Copy(ioutil.Discard, resp.Response().Body) 235 resp.Response().Body.Close() 236 return &AppendBlobAppendBlockFromURLResponse{rawResponse: resp.Response()}, err 237} 238 239// Create the Create Append Blob operation creates a new append blob. 240// 241// contentLength is the length of the request. timeout is the timeout parameter is expressed in seconds. For more 242// information, see <a 243// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 244// Timeouts for Blob Service Operations.</a> blobContentType is optional. Sets the blob's content type. If specified, 245// this property is stored with the blob and returned with a read request. blobContentEncoding is optional. Sets the 246// blob's content encoding. If specified, this property is stored with the blob and returned with a read request. 247// blobContentLanguage is optional. Set the blob's content language. If specified, this property is stored with the 248// blob and returned with a read request. blobContentMD5 is optional. An MD5 hash of the blob content. Note that this 249// hash is not validated, as the hashes for the individual blocks were validated when each was uploaded. 250// blobCacheControl is optional. Sets the blob's cache control. If specified, this property is stored with the blob and 251// returned with a read request. metadata is optional. Specifies a user-defined name-value pair associated with the 252// blob. If no name-value pairs are specified, the operation will copy the metadata from the source blob or file to the 253// destination blob. If one or more name-value pairs are specified, the destination blob is created with the specified 254// metadata, and metadata is not copied from the source blob or file. Note that beginning with version 2009-09-19, 255// metadata names must adhere to the naming rules for C# identifiers. See Naming and Referencing Containers, Blobs, and 256// Metadata for more information. leaseID is if specified, the operation only succeeds if the resource's lease is 257// active and matches this ID. blobContentDisposition is optional. Sets the blob's Content-Disposition header. 258// ifModifiedSince is specify this header value to operate only on a blob if it has been modified since the specified 259// date/time. ifUnmodifiedSince is specify this header value to operate only on a blob if it has not been modified 260// since the specified date/time. ifMatch is specify an ETag value to operate only on blobs with a matching value. 261// ifNoneMatch is specify an ETag value to operate only on blobs without a matching value. requestID is provides a 262// client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage 263// analytics logging is enabled. 264func (client appendBlobClient) Create(ctx context.Context, contentLength int64, timeout *int32, blobContentType *string, blobContentEncoding *string, blobContentLanguage *string, blobContentMD5 []byte, blobCacheControl *string, metadata map[string]string, leaseID *string, blobContentDisposition *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, requestID *string) (*AppendBlobCreateResponse, error) { 265 if err := validate([]validation{ 266 {targetValue: timeout, 267 constraints: []constraint{{target: "timeout", name: null, rule: false, 268 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 269 return nil, err 270 } 271 req, err := client.createPreparer(contentLength, timeout, blobContentType, blobContentEncoding, blobContentLanguage, blobContentMD5, blobCacheControl, metadata, leaseID, blobContentDisposition, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, requestID) 272 if err != nil { 273 return nil, err 274 } 275 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.createResponder}, req) 276 if err != nil { 277 return nil, err 278 } 279 return resp.(*AppendBlobCreateResponse), err 280} 281 282// createPreparer prepares the Create request. 283func (client appendBlobClient) createPreparer(contentLength int64, timeout *int32, blobContentType *string, blobContentEncoding *string, blobContentLanguage *string, blobContentMD5 []byte, blobCacheControl *string, metadata map[string]string, leaseID *string, blobContentDisposition *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, requestID *string) (pipeline.Request, error) { 284 req, err := pipeline.NewRequest("PUT", client.url, nil) 285 if err != nil { 286 return req, pipeline.NewError(err, "failed to create request") 287 } 288 params := req.URL.Query() 289 if timeout != nil { 290 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 291 } 292 req.URL.RawQuery = params.Encode() 293 req.Header.Set("Content-Length", strconv.FormatInt(contentLength, 10)) 294 if blobContentType != nil { 295 req.Header.Set("x-ms-blob-content-type", *blobContentType) 296 } 297 if blobContentEncoding != nil { 298 req.Header.Set("x-ms-blob-content-encoding", *blobContentEncoding) 299 } 300 if blobContentLanguage != nil { 301 req.Header.Set("x-ms-blob-content-language", *blobContentLanguage) 302 } 303 if blobContentMD5 != nil { 304 req.Header.Set("x-ms-blob-content-md5", base64.StdEncoding.EncodeToString(blobContentMD5)) 305 } 306 if blobCacheControl != nil { 307 req.Header.Set("x-ms-blob-cache-control", *blobCacheControl) 308 } 309 if metadata != nil { 310 for k, v := range metadata { 311 req.Header.Set("x-ms-meta-"+k, v) 312 } 313 } 314 if leaseID != nil { 315 req.Header.Set("x-ms-lease-id", *leaseID) 316 } 317 if blobContentDisposition != nil { 318 req.Header.Set("x-ms-blob-content-disposition", *blobContentDisposition) 319 } 320 if ifModifiedSince != nil { 321 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 322 } 323 if ifUnmodifiedSince != nil { 324 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 325 } 326 if ifMatch != nil { 327 req.Header.Set("If-Match", string(*ifMatch)) 328 } 329 if ifNoneMatch != nil { 330 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 331 } 332 req.Header.Set("x-ms-version", ServiceVersion) 333 if requestID != nil { 334 req.Header.Set("x-ms-client-request-id", *requestID) 335 } 336 req.Header.Set("x-ms-blob-type", "AppendBlob") 337 return req, nil 338} 339 340// createResponder handles the response to the Create request. 341func (client appendBlobClient) createResponder(resp pipeline.Response) (pipeline.Response, error) { 342 err := validateResponse(resp, http.StatusOK, http.StatusCreated) 343 if resp == nil { 344 return nil, err 345 } 346 io.Copy(ioutil.Discard, resp.Response().Body) 347 resp.Response().Body.Close() 348 return &AppendBlobCreateResponse{rawResponse: resp.Response()}, err 349} 350