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 "encoding/xml" 10 "github.com/Azure/azure-pipeline-go/pipeline" 11 "io" 12 "io/ioutil" 13 "net/http" 14 "net/url" 15 "strconv" 16 "time" 17) 18 19// pageBlobClient is the client for the PageBlob methods of the Azblob service. 20type pageBlobClient struct { 21 managementClient 22} 23 24// newPageBlobClient creates an instance of the pageBlobClient client. 25func newPageBlobClient(url url.URL, p pipeline.Pipeline) pageBlobClient { 26 return pageBlobClient{newManagementClient(url, p)} 27} 28 29// ClearPages the Clear Pages operation clears a set of pages from a page blob 30// 31// contentLength is the length of the request. timeout is the timeout parameter is expressed in seconds. For more 32// information, see <a 33// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 34// Timeouts for Blob Service Operations.</a> rangeParameter is return only the bytes of the blob in the specified 35// range. leaseID is if specified, the operation only succeeds if the resource's lease is active and matches this ID. 36// encryptionKey is optional. Specifies the encryption key to use to encrypt the data provided in the request. If not 37// specified, encryption is performed with the root account encryption key. For more information, see Encryption at 38// Rest for Azure Storage Services. encryptionKeySha256 is the SHA-256 hash of the provided encryption key. Must be 39// provided if the x-ms-encryption-key header is provided. encryptionAlgorithm is the algorithm used to produce the 40// encryption key hash. Currently, the only accepted value is "AES256". Must be provided if the x-ms-encryption-key 41// header is provided. encryptionScope is optional. Version 2019-07-07 and later. Specifies the name of the encryption 42// scope to use to encrypt the data provided in the request. If not specified, encryption is performed with the default 43// account encryption scope. For more information, see Encryption at Rest for Azure Storage Services. 44// ifSequenceNumberLessThanOrEqualTo is specify this header value to operate only on a blob if it has a sequence number 45// less than or equal to the specified. ifSequenceNumberLessThan is specify this header value to operate only on a blob 46// if it has a sequence number less than the specified. ifSequenceNumberEqualTo is specify this header value to operate 47// only on a blob if it has the specified sequence number. ifModifiedSince is specify this header value to operate only 48// on a blob if it has been modified since the specified date/time. ifUnmodifiedSince is specify this header value to 49// operate only on a blob if it has not been modified since the specified date/time. ifMatch is specify an ETag value 50// to operate only on blobs with a matching value. ifNoneMatch is specify an ETag value to operate only on blobs 51// without a matching value. requestID is provides a client-generated, opaque value with a 1 KB character limit that is 52// recorded in the analytics logs when storage analytics logging is enabled. 53func (client pageBlobClient) ClearPages(ctx context.Context, contentLength int64, timeout *int32, rangeParameter *string, leaseID *string, encryptionKey *string, encryptionKeySha256 *string, encryptionAlgorithm EncryptionAlgorithmType, encryptionScope *string, ifSequenceNumberLessThanOrEqualTo *int64, ifSequenceNumberLessThan *int64, ifSequenceNumberEqualTo *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, requestID *string) (*PageBlobClearPagesResponse, error) { 54 if err := validate([]validation{ 55 {targetValue: timeout, 56 constraints: []constraint{{target: "timeout", name: null, rule: false, 57 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 58 return nil, err 59 } 60 req, err := client.clearPagesPreparer(contentLength, timeout, rangeParameter, leaseID, encryptionKey, encryptionKeySha256, encryptionAlgorithm, encryptionScope, ifSequenceNumberLessThanOrEqualTo, ifSequenceNumberLessThan, ifSequenceNumberEqualTo, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, requestID) 61 if err != nil { 62 return nil, err 63 } 64 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.clearPagesResponder}, req) 65 if err != nil { 66 return nil, err 67 } 68 return resp.(*PageBlobClearPagesResponse), err 69} 70 71// clearPagesPreparer prepares the ClearPages request. 72func (client pageBlobClient) clearPagesPreparer(contentLength int64, timeout *int32, rangeParameter *string, leaseID *string, encryptionKey *string, encryptionKeySha256 *string, encryptionAlgorithm EncryptionAlgorithmType, encryptionScope *string, ifSequenceNumberLessThanOrEqualTo *int64, ifSequenceNumberLessThan *int64, ifSequenceNumberEqualTo *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, requestID *string) (pipeline.Request, error) { 73 req, err := pipeline.NewRequest("PUT", client.url, nil) 74 if err != nil { 75 return req, pipeline.NewError(err, "failed to create request") 76 } 77 params := req.URL.Query() 78 if timeout != nil { 79 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 80 } 81 params.Set("comp", "page") 82 req.URL.RawQuery = params.Encode() 83 req.Header.Set("Content-Length", strconv.FormatInt(contentLength, 10)) 84 if rangeParameter != nil { 85 req.Header.Set("x-ms-range", *rangeParameter) 86 } 87 if leaseID != nil { 88 req.Header.Set("x-ms-lease-id", *leaseID) 89 } 90 if encryptionKey != nil { 91 req.Header.Set("x-ms-encryption-key", *encryptionKey) 92 } 93 if encryptionKeySha256 != nil { 94 req.Header.Set("x-ms-encryption-key-sha256", *encryptionKeySha256) 95 } 96 if encryptionAlgorithm != EncryptionAlgorithmNone { 97 req.Header.Set("x-ms-encryption-algorithm", string(encryptionAlgorithm)) 98 } 99 if encryptionScope != nil { 100 req.Header.Set("x-ms-encryption-scope", *encryptionScope) 101 } 102 if ifSequenceNumberLessThanOrEqualTo != nil { 103 req.Header.Set("x-ms-if-sequence-number-le", strconv.FormatInt(*ifSequenceNumberLessThanOrEqualTo, 10)) 104 } 105 if ifSequenceNumberLessThan != nil { 106 req.Header.Set("x-ms-if-sequence-number-lt", strconv.FormatInt(*ifSequenceNumberLessThan, 10)) 107 } 108 if ifSequenceNumberEqualTo != nil { 109 req.Header.Set("x-ms-if-sequence-number-eq", strconv.FormatInt(*ifSequenceNumberEqualTo, 10)) 110 } 111 if ifModifiedSince != nil { 112 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 113 } 114 if ifUnmodifiedSince != nil { 115 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 116 } 117 if ifMatch != nil { 118 req.Header.Set("If-Match", string(*ifMatch)) 119 } 120 if ifNoneMatch != nil { 121 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 122 } 123 req.Header.Set("x-ms-version", ServiceVersion) 124 if requestID != nil { 125 req.Header.Set("x-ms-client-request-id", *requestID) 126 } 127 req.Header.Set("x-ms-page-write", "clear") 128 return req, nil 129} 130 131// clearPagesResponder handles the response to the ClearPages request. 132func (client pageBlobClient) clearPagesResponder(resp pipeline.Response) (pipeline.Response, error) { 133 err := validateResponse(resp, http.StatusOK, http.StatusCreated) 134 if resp == nil { 135 return nil, err 136 } 137 io.Copy(ioutil.Discard, resp.Response().Body) 138 resp.Response().Body.Close() 139 return &PageBlobClearPagesResponse{rawResponse: resp.Response()}, err 140} 141 142// CopyIncremental the Copy Incremental operation copies a snapshot of the source page blob to a destination page blob. 143// The snapshot is copied such that only the differential changes between the previously copied snapshot are 144// transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read or 145// copied from as usual. This API is supported since REST version 2016-05-31. 146// 147// copySource is specifies the name of the source page blob snapshot. This value is a URL of up to 2 KB in length that 148// specifies a page blob snapshot. The value should be URL-encoded as it would appear in a request URI. The source blob 149// must either be public or must be authenticated via a shared access signature. timeout is the timeout parameter is 150// expressed in seconds. For more information, see <a 151// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 152// Timeouts for Blob Service Operations.</a> ifModifiedSince is specify this header value to operate only on a blob if 153// it has been modified since the specified date/time. ifUnmodifiedSince is specify this header value to operate only 154// on a blob if it has not been modified since the specified date/time. ifMatch is specify an ETag value to operate 155// only on blobs with a matching value. ifNoneMatch is specify an ETag value to operate only on blobs without a 156// matching value. requestID is provides a client-generated, opaque value with a 1 KB character limit that is recorded 157// in the analytics logs when storage analytics logging is enabled. 158func (client pageBlobClient) CopyIncremental(ctx context.Context, copySource string, timeout *int32, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, requestID *string) (*PageBlobCopyIncrementalResponse, error) { 159 if err := validate([]validation{ 160 {targetValue: timeout, 161 constraints: []constraint{{target: "timeout", name: null, rule: false, 162 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 163 return nil, err 164 } 165 req, err := client.copyIncrementalPreparer(copySource, timeout, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, requestID) 166 if err != nil { 167 return nil, err 168 } 169 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.copyIncrementalResponder}, req) 170 if err != nil { 171 return nil, err 172 } 173 return resp.(*PageBlobCopyIncrementalResponse), err 174} 175 176// copyIncrementalPreparer prepares the CopyIncremental request. 177func (client pageBlobClient) copyIncrementalPreparer(copySource string, timeout *int32, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, requestID *string) (pipeline.Request, error) { 178 req, err := pipeline.NewRequest("PUT", client.url, nil) 179 if err != nil { 180 return req, pipeline.NewError(err, "failed to create request") 181 } 182 params := req.URL.Query() 183 if timeout != nil { 184 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 185 } 186 params.Set("comp", "incrementalcopy") 187 req.URL.RawQuery = params.Encode() 188 if ifModifiedSince != nil { 189 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 190 } 191 if ifUnmodifiedSince != nil { 192 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 193 } 194 if ifMatch != nil { 195 req.Header.Set("If-Match", string(*ifMatch)) 196 } 197 if ifNoneMatch != nil { 198 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 199 } 200 req.Header.Set("x-ms-copy-source", copySource) 201 req.Header.Set("x-ms-version", ServiceVersion) 202 if requestID != nil { 203 req.Header.Set("x-ms-client-request-id", *requestID) 204 } 205 return req, nil 206} 207 208// copyIncrementalResponder handles the response to the CopyIncremental request. 209func (client pageBlobClient) copyIncrementalResponder(resp pipeline.Response) (pipeline.Response, error) { 210 err := validateResponse(resp, http.StatusOK, http.StatusAccepted) 211 if resp == nil { 212 return nil, err 213 } 214 io.Copy(ioutil.Discard, resp.Response().Body) 215 resp.Response().Body.Close() 216 return &PageBlobCopyIncrementalResponse{rawResponse: resp.Response()}, err 217} 218 219// Create the Create operation creates a new page blob. 220// 221// contentLength is the length of the request. blobContentLength is this header specifies the maximum size for the page 222// blob, up to 1 TB. The page blob size must be aligned to a 512-byte boundary. timeout is the timeout parameter is 223// expressed in seconds. For more information, see <a 224// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 225// Timeouts for Blob Service Operations.</a> tier is optional. Indicates the tier to be set on the page blob. 226// blobContentType is optional. Sets the blob's content type. If specified, this property is stored with the blob and 227// returned with a read request. blobContentEncoding is optional. Sets the blob's content encoding. If specified, this 228// property is stored with the blob and returned with a read request. blobContentLanguage is optional. Set the blob's 229// content language. If specified, this property is stored with the blob and returned with a read request. 230// blobContentMD5 is optional. An MD5 hash of the blob content. Note that this hash is not validated, as the hashes for 231// the individual blocks were validated when each was uploaded. blobCacheControl is optional. Sets the blob's cache 232// control. If specified, this property is stored with the blob and returned with a read request. metadata is optional. 233// Specifies a user-defined name-value pair associated with the blob. If no name-value pairs are specified, the 234// operation will copy the metadata from the source blob or file to the destination blob. If one or more name-value 235// pairs are specified, the destination blob is created with the specified metadata, and metadata is not copied from 236// the source blob or file. Note that beginning with version 2009-09-19, metadata names must adhere to the naming rules 237// for C# identifiers. See Naming and Referencing Containers, Blobs, and Metadata for more information. leaseID is if 238// specified, the operation only succeeds if the resource's lease is active and matches this ID. blobContentDisposition 239// is optional. Sets the blob's Content-Disposition header. encryptionKey is optional. Specifies the encryption key to 240// use to encrypt the data provided in the request. If not specified, encryption is performed with the root account 241// encryption key. For more information, see Encryption at Rest for Azure Storage Services. encryptionKeySha256 is the 242// SHA-256 hash of the provided encryption key. Must be provided if the x-ms-encryption-key header is provided. 243// encryptionAlgorithm is the algorithm used to produce the encryption key hash. Currently, the only accepted value is 244// "AES256". Must be provided if the x-ms-encryption-key header is provided. encryptionScope is optional. Version 245// 2019-07-07 and later. Specifies the name of the encryption scope to use to encrypt the data provided in the 246// request. If not specified, encryption is performed with the default account encryption scope. For more information, 247// see Encryption at Rest for Azure Storage Services. ifModifiedSince is specify this header value to operate only on a 248// blob if it has been modified since the specified date/time. ifUnmodifiedSince is specify this header value to 249// operate only on a blob if it has not been modified since the specified date/time. ifMatch is specify an ETag value 250// to operate only on blobs with a matching value. ifNoneMatch is specify an ETag value to operate only on blobs 251// without a matching value. ifTags is specify a SQL where clause on blob tags to operate only on blobs with a matching 252// value. blobSequenceNumber is set for page blobs only. The sequence number is a user-controlled value that you can 253// use to track requests. The value of the sequence number must be between 0 and 2^63 - 1. requestID is provides a 254// client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage 255// analytics logging is enabled. blobTagsString is optional. Used to set blob tags in various blob operations. 256func (client pageBlobClient) Create(ctx context.Context, contentLength int64, blobContentLength int64, timeout *int32, tier PremiumPageBlobAccessTierType, blobContentType *string, blobContentEncoding *string, blobContentLanguage *string, blobContentMD5 []byte, blobCacheControl *string, metadata map[string]string, leaseID *string, blobContentDisposition *string, encryptionKey *string, encryptionKeySha256 *string, encryptionAlgorithm EncryptionAlgorithmType, encryptionScope *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, ifTags *string, blobSequenceNumber *int64, requestID *string, blobTagsString *string) (*PageBlobCreateResponse, error) { 257 if err := validate([]validation{ 258 {targetValue: timeout, 259 constraints: []constraint{{target: "timeout", name: null, rule: false, 260 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 261 return nil, err 262 } 263 req, err := client.createPreparer(contentLength, blobContentLength, timeout, tier, blobContentType, blobContentEncoding, blobContentLanguage, blobContentMD5, blobCacheControl, metadata, leaseID, blobContentDisposition, encryptionKey, encryptionKeySha256, encryptionAlgorithm, encryptionScope, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, ifTags, blobSequenceNumber, requestID, blobTagsString) 264 if err != nil { 265 return nil, err 266 } 267 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.createResponder}, req) 268 if err != nil { 269 return nil, err 270 } 271 return resp.(*PageBlobCreateResponse), err 272} 273 274// createPreparer prepares the Create request. 275func (client pageBlobClient) createPreparer(contentLength int64, blobContentLength int64, timeout *int32, tier PremiumPageBlobAccessTierType, blobContentType *string, blobContentEncoding *string, blobContentLanguage *string, blobContentMD5 []byte, blobCacheControl *string, metadata map[string]string, leaseID *string, blobContentDisposition *string, encryptionKey *string, encryptionKeySha256 *string, encryptionAlgorithm EncryptionAlgorithmType, encryptionScope *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, ifTags *string, blobSequenceNumber *int64, requestID *string, blobTagsString *string) (pipeline.Request, error) { 276 req, err := pipeline.NewRequest("PUT", client.url, nil) 277 if err != nil { 278 return req, pipeline.NewError(err, "failed to create request") 279 } 280 params := req.URL.Query() 281 if timeout != nil { 282 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 283 } 284 req.URL.RawQuery = params.Encode() 285 req.Header.Set("Content-Length", strconv.FormatInt(contentLength, 10)) 286 if tier != PremiumPageBlobAccessTierNone { 287 req.Header.Set("x-ms-access-tier", string(tier)) 288 } 289 if blobContentType != nil { 290 req.Header.Set("x-ms-blob-content-type", *blobContentType) 291 } 292 if blobContentEncoding != nil { 293 req.Header.Set("x-ms-blob-content-encoding", *blobContentEncoding) 294 } 295 if blobContentLanguage != nil { 296 req.Header.Set("x-ms-blob-content-language", *blobContentLanguage) 297 } 298 if blobContentMD5 != nil { 299 req.Header.Set("x-ms-blob-content-md5", base64.StdEncoding.EncodeToString(blobContentMD5)) 300 } 301 if blobCacheControl != nil { 302 req.Header.Set("x-ms-blob-cache-control", *blobCacheControl) 303 } 304 if metadata != nil { 305 for k, v := range metadata { 306 req.Header.Set("x-ms-meta-"+k, v) 307 } 308 } 309 if leaseID != nil { 310 req.Header.Set("x-ms-lease-id", *leaseID) 311 } 312 if blobContentDisposition != nil { 313 req.Header.Set("x-ms-blob-content-disposition", *blobContentDisposition) 314 } 315 if encryptionKey != nil { 316 req.Header.Set("x-ms-encryption-key", *encryptionKey) 317 } 318 if encryptionKeySha256 != nil { 319 req.Header.Set("x-ms-encryption-key-sha256", *encryptionKeySha256) 320 } 321 if encryptionAlgorithm != EncryptionAlgorithmNone { 322 req.Header.Set("x-ms-encryption-algorithm", string(encryptionAlgorithm)) 323 } 324 if encryptionScope != nil { 325 req.Header.Set("x-ms-encryption-scope", *encryptionScope) 326 } 327 if ifModifiedSince != nil { 328 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 329 } 330 if ifUnmodifiedSince != nil { 331 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 332 } 333 if ifMatch != nil { 334 req.Header.Set("If-Match", string(*ifMatch)) 335 } 336 if ifNoneMatch != nil { 337 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 338 } 339 if ifTags != nil { 340 req.Header.Set("x-ms-if-tags", *ifTags) 341 } 342 req.Header.Set("x-ms-blob-content-length", strconv.FormatInt(blobContentLength, 10)) 343 if blobSequenceNumber != nil { 344 req.Header.Set("x-ms-blob-sequence-number", strconv.FormatInt(*blobSequenceNumber, 10)) 345 } 346 req.Header.Set("x-ms-version", ServiceVersion) 347 if requestID != nil { 348 req.Header.Set("x-ms-client-request-id", *requestID) 349 } 350 if blobTagsString != nil { 351 req.Header.Set("x-ms-tags", *blobTagsString) 352 } 353 req.Header.Set("x-ms-blob-type", "PageBlob") 354 return req, nil 355} 356 357// createResponder handles the response to the Create request. 358func (client pageBlobClient) createResponder(resp pipeline.Response) (pipeline.Response, error) { 359 err := validateResponse(resp, http.StatusOK, http.StatusCreated) 360 if resp == nil { 361 return nil, err 362 } 363 io.Copy(ioutil.Discard, resp.Response().Body) 364 resp.Response().Body.Close() 365 return &PageBlobCreateResponse{rawResponse: resp.Response()}, err 366} 367 368// GetPageRanges the Get Page Ranges operation returns the list of valid page ranges for a page blob or snapshot of a 369// page blob 370// 371// snapshot is the snapshot parameter is an opaque DateTime value that, when present, specifies the blob snapshot to 372// retrieve. For more information on working with blob snapshots, see <a 373// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/creating-a-snapshot-of-a-blob">Creating 374// a Snapshot of a Blob.</a> timeout is the timeout parameter is expressed in seconds. For more information, see <a 375// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 376// Timeouts for Blob Service Operations.</a> rangeParameter is return only the bytes of the blob in the specified 377// range. leaseID is if specified, the operation only succeeds if the resource's lease is active and matches this ID. 378// ifModifiedSince is specify this header value to operate only on a blob if it has been modified since the specified 379// date/time. ifUnmodifiedSince is specify this header value to operate only on a blob if it has not been modified 380// since the specified date/time. ifMatch is specify an ETag value to operate only on blobs with a matching value. 381// ifNoneMatch is specify an ETag value to operate only on blobs without a matching value. ifTags is specify a SQL 382// where clause on blob tags to operate only on blobs with a matching value. requestID is provides a client-generated, 383// opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is 384// enabled. 385func (client pageBlobClient) GetPageRanges(ctx context.Context, snapshot *string, timeout *int32, rangeParameter *string, leaseID *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, ifTags *string, requestID *string) (*PageList, error) { 386 if err := validate([]validation{ 387 {targetValue: timeout, 388 constraints: []constraint{{target: "timeout", name: null, rule: false, 389 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 390 return nil, err 391 } 392 req, err := client.getPageRangesPreparer(snapshot, timeout, rangeParameter, leaseID, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, ifTags, requestID) 393 if err != nil { 394 return nil, err 395 } 396 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getPageRangesResponder}, req) 397 if err != nil { 398 return nil, err 399 } 400 return resp.(*PageList), err 401} 402 403// getPageRangesPreparer prepares the GetPageRanges request. 404func (client pageBlobClient) getPageRangesPreparer(snapshot *string, timeout *int32, rangeParameter *string, leaseID *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, ifTags *string, requestID *string) (pipeline.Request, error) { 405 req, err := pipeline.NewRequest("GET", client.url, nil) 406 if err != nil { 407 return req, pipeline.NewError(err, "failed to create request") 408 } 409 params := req.URL.Query() 410 if snapshot != nil && len(*snapshot) > 0 { 411 params.Set("snapshot", *snapshot) 412 } 413 if timeout != nil { 414 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 415 } 416 params.Set("comp", "pagelist") 417 req.URL.RawQuery = params.Encode() 418 if rangeParameter != nil { 419 req.Header.Set("x-ms-range", *rangeParameter) 420 } 421 if leaseID != nil { 422 req.Header.Set("x-ms-lease-id", *leaseID) 423 } 424 if ifModifiedSince != nil { 425 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 426 } 427 if ifUnmodifiedSince != nil { 428 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 429 } 430 if ifMatch != nil { 431 req.Header.Set("If-Match", string(*ifMatch)) 432 } 433 if ifNoneMatch != nil { 434 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 435 } 436 if ifTags != nil { 437 req.Header.Set("x-ms-if-tags", *ifTags) 438 } 439 req.Header.Set("x-ms-version", ServiceVersion) 440 if requestID != nil { 441 req.Header.Set("x-ms-client-request-id", *requestID) 442 } 443 return req, nil 444} 445 446// getPageRangesResponder handles the response to the GetPageRanges request. 447func (client pageBlobClient) getPageRangesResponder(resp pipeline.Response) (pipeline.Response, error) { 448 err := validateResponse(resp, http.StatusOK) 449 if resp == nil { 450 return nil, err 451 } 452 result := &PageList{rawResponse: resp.Response()} 453 if err != nil { 454 return result, err 455 } 456 defer resp.Response().Body.Close() 457 b, err := ioutil.ReadAll(resp.Response().Body) 458 if err != nil { 459 return result, err 460 } 461 if len(b) > 0 { 462 b = removeBOM(b) 463 err = xml.Unmarshal(b, result) 464 if err != nil { 465 return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") 466 } 467 } 468 return result, nil 469} 470 471// GetPageRangesDiff the Get Page Ranges Diff operation returns the list of valid page ranges for a page blob that were 472// changed between target blob and previous snapshot. 473// 474// snapshot is the snapshot parameter is an opaque DateTime value that, when present, specifies the blob snapshot to 475// retrieve. For more information on working with blob snapshots, see <a 476// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/creating-a-snapshot-of-a-blob">Creating 477// a Snapshot of a Blob.</a> timeout is the timeout parameter is expressed in seconds. For more information, see <a 478// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 479// Timeouts for Blob Service Operations.</a> prevsnapshot is optional in version 2015-07-08 and newer. The prevsnapshot 480// parameter is a DateTime value that specifies that the response will contain only pages that were changed between 481// target blob and previous snapshot. Changed pages include both updated and cleared pages. The target blob may be a 482// snapshot, as long as the snapshot specified by prevsnapshot is the older of the two. Note that incremental snapshots 483// are currently supported only for blobs created on or after January 1, 2016. prevSnapshotURL is optional. This header 484// is only supported in service versions 2019-04-19 and after and specifies the URL of a previous snapshot of the 485// target blob. The response will only contain pages that were changed between the target blob and its previous 486// snapshot. rangeParameter is return only the bytes of the blob in the specified range. leaseID is if specified, the 487// operation only succeeds if the resource's lease is active and matches this ID. ifModifiedSince is specify this 488// header value to operate only on a blob if it has been modified since the specified date/time. ifUnmodifiedSince is 489// specify this header value to operate only on a blob if it has not been modified since the specified date/time. 490// ifMatch is specify an ETag value to operate only on blobs with a matching value. ifNoneMatch is specify an ETag 491// value to operate only on blobs without a matching value. ifTags is specify a SQL where clause on blob tags to 492// operate only on blobs with a matching value. requestID is provides a client-generated, opaque value with a 1 KB 493// character limit that is recorded in the analytics logs when storage analytics logging is enabled. 494func (client pageBlobClient) GetPageRangesDiff(ctx context.Context, snapshot *string, timeout *int32, prevsnapshot *string, prevSnapshotURL *string, rangeParameter *string, leaseID *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, ifTags *string, requestID *string) (*PageList, error) { 495 if err := validate([]validation{ 496 {targetValue: timeout, 497 constraints: []constraint{{target: "timeout", name: null, rule: false, 498 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 499 return nil, err 500 } 501 req, err := client.getPageRangesDiffPreparer(snapshot, timeout, prevsnapshot, prevSnapshotURL, rangeParameter, leaseID, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, ifTags, requestID) 502 if err != nil { 503 return nil, err 504 } 505 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.getPageRangesDiffResponder}, req) 506 if err != nil { 507 return nil, err 508 } 509 return resp.(*PageList), err 510} 511 512// getPageRangesDiffPreparer prepares the GetPageRangesDiff request. 513func (client pageBlobClient) getPageRangesDiffPreparer(snapshot *string, timeout *int32, prevsnapshot *string, prevSnapshotURL *string, rangeParameter *string, leaseID *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, ifTags *string, requestID *string) (pipeline.Request, error) { 514 req, err := pipeline.NewRequest("GET", client.url, nil) 515 if err != nil { 516 return req, pipeline.NewError(err, "failed to create request") 517 } 518 params := req.URL.Query() 519 if snapshot != nil && len(*snapshot) > 0 { 520 params.Set("snapshot", *snapshot) 521 } 522 if timeout != nil { 523 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 524 } 525 if prevsnapshot != nil && len(*prevsnapshot) > 0 { 526 params.Set("prevsnapshot", *prevsnapshot) 527 } 528 params.Set("comp", "pagelist") 529 req.URL.RawQuery = params.Encode() 530 if prevSnapshotURL != nil { 531 req.Header.Set("x-ms-previous-snapshot-url", *prevSnapshotURL) 532 } 533 if rangeParameter != nil { 534 req.Header.Set("x-ms-range", *rangeParameter) 535 } 536 if leaseID != nil { 537 req.Header.Set("x-ms-lease-id", *leaseID) 538 } 539 if ifModifiedSince != nil { 540 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 541 } 542 if ifUnmodifiedSince != nil { 543 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 544 } 545 if ifMatch != nil { 546 req.Header.Set("If-Match", string(*ifMatch)) 547 } 548 if ifNoneMatch != nil { 549 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 550 } 551 if ifTags != nil { 552 req.Header.Set("x-ms-if-tags", *ifTags) 553 } 554 req.Header.Set("x-ms-version", ServiceVersion) 555 if requestID != nil { 556 req.Header.Set("x-ms-client-request-id", *requestID) 557 } 558 return req, nil 559} 560 561// getPageRangesDiffResponder handles the response to the GetPageRangesDiff request. 562func (client pageBlobClient) getPageRangesDiffResponder(resp pipeline.Response) (pipeline.Response, error) { 563 err := validateResponse(resp, http.StatusOK) 564 if resp == nil { 565 return nil, err 566 } 567 result := &PageList{rawResponse: resp.Response()} 568 if err != nil { 569 return result, err 570 } 571 defer resp.Response().Body.Close() 572 b, err := ioutil.ReadAll(resp.Response().Body) 573 if err != nil { 574 return result, err 575 } 576 if len(b) > 0 { 577 b = removeBOM(b) 578 err = xml.Unmarshal(b, result) 579 if err != nil { 580 return result, NewResponseError(err, resp.Response(), "failed to unmarshal response body") 581 } 582 } 583 return result, nil 584} 585 586// Resize resize the Blob 587// 588// blobContentLength is this header specifies the maximum size for the page blob, up to 1 TB. The page blob size must 589// be aligned to a 512-byte boundary. timeout is the timeout parameter is expressed in seconds. For more information, 590// see <a 591// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 592// Timeouts for Blob Service Operations.</a> leaseID is if specified, the operation only succeeds if the resource's 593// lease is active and matches this ID. encryptionKey is optional. Specifies the encryption key to use to encrypt the 594// data provided in the request. If not specified, encryption is performed with the root account encryption key. For 595// more information, see Encryption at Rest for Azure Storage Services. encryptionKeySha256 is the SHA-256 hash of the 596// provided encryption key. Must be provided if the x-ms-encryption-key header is provided. encryptionAlgorithm is the 597// algorithm used to produce the encryption key hash. Currently, the only accepted value is "AES256". Must be provided 598// if the x-ms-encryption-key header is provided. encryptionScope is optional. Version 2019-07-07 and later. Specifies 599// the name of the encryption scope to use to encrypt the data provided in the request. If not specified, encryption is 600// performed with the default account encryption scope. For more information, see Encryption at Rest for Azure Storage 601// Services. ifModifiedSince is specify this header value to operate only on a blob if it has been modified since the 602// specified date/time. ifUnmodifiedSince is specify this header value to operate only on a blob if it has not been 603// modified since the specified date/time. ifMatch is specify an ETag value to operate only on blobs with a matching 604// value. ifNoneMatch is specify an ETag value to operate only on blobs without a matching value. requestID is provides 605// a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage 606// analytics logging is enabled. 607func (client pageBlobClient) Resize(ctx context.Context, blobContentLength int64, timeout *int32, leaseID *string, encryptionKey *string, encryptionKeySha256 *string, encryptionAlgorithm EncryptionAlgorithmType, encryptionScope *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, requestID *string) (*PageBlobResizeResponse, error) { 608 if err := validate([]validation{ 609 {targetValue: timeout, 610 constraints: []constraint{{target: "timeout", name: null, rule: false, 611 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 612 return nil, err 613 } 614 req, err := client.resizePreparer(blobContentLength, timeout, leaseID, encryptionKey, encryptionKeySha256, encryptionAlgorithm, encryptionScope, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, requestID) 615 if err != nil { 616 return nil, err 617 } 618 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.resizeResponder}, req) 619 if err != nil { 620 return nil, err 621 } 622 return resp.(*PageBlobResizeResponse), err 623} 624 625// resizePreparer prepares the Resize request. 626func (client pageBlobClient) resizePreparer(blobContentLength int64, timeout *int32, leaseID *string, encryptionKey *string, encryptionKeySha256 *string, encryptionAlgorithm EncryptionAlgorithmType, encryptionScope *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, requestID *string) (pipeline.Request, error) { 627 req, err := pipeline.NewRequest("PUT", client.url, nil) 628 if err != nil { 629 return req, pipeline.NewError(err, "failed to create request") 630 } 631 params := req.URL.Query() 632 if timeout != nil { 633 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 634 } 635 params.Set("comp", "properties") 636 req.URL.RawQuery = params.Encode() 637 if leaseID != nil { 638 req.Header.Set("x-ms-lease-id", *leaseID) 639 } 640 if encryptionKey != nil { 641 req.Header.Set("x-ms-encryption-key", *encryptionKey) 642 } 643 if encryptionKeySha256 != nil { 644 req.Header.Set("x-ms-encryption-key-sha256", *encryptionKeySha256) 645 } 646 if encryptionAlgorithm != EncryptionAlgorithmNone { 647 req.Header.Set("x-ms-encryption-algorithm", string(encryptionAlgorithm)) 648 } 649 if encryptionScope != nil { 650 req.Header.Set("x-ms-encryption-scope", *encryptionScope) 651 } 652 if ifModifiedSince != nil { 653 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 654 } 655 if ifUnmodifiedSince != nil { 656 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 657 } 658 if ifMatch != nil { 659 req.Header.Set("If-Match", string(*ifMatch)) 660 } 661 if ifNoneMatch != nil { 662 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 663 } 664 req.Header.Set("x-ms-blob-content-length", strconv.FormatInt(blobContentLength, 10)) 665 req.Header.Set("x-ms-version", ServiceVersion) 666 if requestID != nil { 667 req.Header.Set("x-ms-client-request-id", *requestID) 668 } 669 return req, nil 670} 671 672// resizeResponder handles the response to the Resize request. 673func (client pageBlobClient) resizeResponder(resp pipeline.Response) (pipeline.Response, error) { 674 err := validateResponse(resp, http.StatusOK) 675 if resp == nil { 676 return nil, err 677 } 678 io.Copy(ioutil.Discard, resp.Response().Body) 679 resp.Response().Body.Close() 680 return &PageBlobResizeResponse{rawResponse: resp.Response()}, err 681} 682 683// UpdateSequenceNumber update the sequence number of the blob 684// 685// sequenceNumberAction is required if the x-ms-blob-sequence-number header is set for the request. This property 686// applies to page blobs only. This property indicates how the service should modify the blob's sequence number timeout 687// is the timeout parameter is expressed in seconds. For more information, see <a 688// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 689// Timeouts for Blob Service Operations.</a> leaseID is if specified, the operation only succeeds if the resource's 690// lease is active and matches this ID. ifModifiedSince is specify this header value to operate only on a blob if it 691// has been modified since the specified date/time. ifUnmodifiedSince is specify this header value to operate only on a 692// blob if it has not been modified since the specified date/time. ifMatch is specify an ETag value to operate only on 693// blobs with a matching value. ifNoneMatch is specify an ETag value to operate only on blobs without a matching value. 694// blobSequenceNumber is set for page blobs only. The sequence number is a user-controlled value that you can use to 695// track requests. The value of the sequence number must be between 0 and 2^63 - 1. requestID is provides a 696// client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage 697// analytics logging is enabled. 698func (client pageBlobClient) UpdateSequenceNumber(ctx context.Context, sequenceNumberAction SequenceNumberActionType, timeout *int32, leaseID *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, blobSequenceNumber *int64, requestID *string) (*PageBlobUpdateSequenceNumberResponse, error) { 699 if err := validate([]validation{ 700 {targetValue: timeout, 701 constraints: []constraint{{target: "timeout", name: null, rule: false, 702 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 703 return nil, err 704 } 705 req, err := client.updateSequenceNumberPreparer(sequenceNumberAction, timeout, leaseID, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, blobSequenceNumber, requestID) 706 if err != nil { 707 return nil, err 708 } 709 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.updateSequenceNumberResponder}, req) 710 if err != nil { 711 return nil, err 712 } 713 return resp.(*PageBlobUpdateSequenceNumberResponse), err 714} 715 716// updateSequenceNumberPreparer prepares the UpdateSequenceNumber request. 717func (client pageBlobClient) updateSequenceNumberPreparer(sequenceNumberAction SequenceNumberActionType, timeout *int32, leaseID *string, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, blobSequenceNumber *int64, requestID *string) (pipeline.Request, error) { 718 req, err := pipeline.NewRequest("PUT", client.url, nil) 719 if err != nil { 720 return req, pipeline.NewError(err, "failed to create request") 721 } 722 params := req.URL.Query() 723 if timeout != nil { 724 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 725 } 726 params.Set("comp", "properties") 727 req.URL.RawQuery = params.Encode() 728 if leaseID != nil { 729 req.Header.Set("x-ms-lease-id", *leaseID) 730 } 731 if ifModifiedSince != nil { 732 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 733 } 734 if ifUnmodifiedSince != nil { 735 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 736 } 737 if ifMatch != nil { 738 req.Header.Set("If-Match", string(*ifMatch)) 739 } 740 if ifNoneMatch != nil { 741 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 742 } 743 req.Header.Set("x-ms-sequence-number-action", string(sequenceNumberAction)) 744 if blobSequenceNumber != nil { 745 req.Header.Set("x-ms-blob-sequence-number", strconv.FormatInt(*blobSequenceNumber, 10)) 746 } 747 req.Header.Set("x-ms-version", ServiceVersion) 748 if requestID != nil { 749 req.Header.Set("x-ms-client-request-id", *requestID) 750 } 751 return req, nil 752} 753 754// updateSequenceNumberResponder handles the response to the UpdateSequenceNumber request. 755func (client pageBlobClient) updateSequenceNumberResponder(resp pipeline.Response) (pipeline.Response, error) { 756 err := validateResponse(resp, http.StatusOK) 757 if resp == nil { 758 return nil, err 759 } 760 io.Copy(ioutil.Discard, resp.Response().Body) 761 resp.Response().Body.Close() 762 return &PageBlobUpdateSequenceNumberResponse{rawResponse: resp.Response()}, err 763} 764 765// UploadPages the Upload Pages operation writes a range of pages to a page blob 766// 767// body is initial data body will be closed upon successful return. Callers should ensure closure when receiving an 768// error.contentLength is the length of the request. transactionalContentMD5 is specify the transactional md5 for the 769// body, to be validated by the service. transactionalContentCrc64 is specify the transactional crc64 for the body, to 770// be validated by the service. timeout is the timeout parameter is expressed in seconds. For more information, see <a 771// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 772// Timeouts for Blob Service Operations.</a> rangeParameter is return only the bytes of the blob in the specified 773// range. leaseID is if specified, the operation only succeeds if the resource's lease is active and matches this ID. 774// encryptionKey is optional. Specifies the encryption key to use to encrypt the data provided in the request. If not 775// specified, encryption is performed with the root account encryption key. For more information, see Encryption at 776// Rest for Azure Storage Services. encryptionKeySha256 is the SHA-256 hash of the provided encryption key. Must be 777// provided if the x-ms-encryption-key header is provided. encryptionAlgorithm is the algorithm used to produce the 778// encryption key hash. Currently, the only accepted value is "AES256". Must be provided if the x-ms-encryption-key 779// header is provided. encryptionScope is optional. Version 2019-07-07 and later. Specifies the name of the encryption 780// scope to use to encrypt the data provided in the request. If not specified, encryption is performed with the default 781// account encryption scope. For more information, see Encryption at Rest for Azure Storage Services. 782// ifSequenceNumberLessThanOrEqualTo is specify this header value to operate only on a blob if it has a sequence number 783// less than or equal to the specified. ifSequenceNumberLessThan is specify this header value to operate only on a blob 784// if it has a sequence number less than the specified. ifSequenceNumberEqualTo is specify this header value to operate 785// only on a blob if it has the specified sequence number. ifModifiedSince is specify this header value to operate only 786// on a blob if it has been modified since the specified date/time. ifUnmodifiedSince is specify this header value to 787// operate only on a blob if it has not been modified since the specified date/time. ifMatch is specify an ETag value 788// to operate only on blobs with a matching value. ifNoneMatch is specify an ETag value to operate only on blobs 789// without a matching value. ifTags is specify a SQL where clause on blob tags to operate only on blobs with a matching 790// value. requestID is provides a client-generated, opaque value with a 1 KB character limit that is recorded in the 791// analytics logs when storage analytics logging is enabled. 792func (client pageBlobClient) UploadPages(ctx context.Context, body io.ReadSeeker, contentLength int64, transactionalContentMD5 []byte, transactionalContentCrc64 []byte, timeout *int32, rangeParameter *string, leaseID *string, encryptionKey *string, encryptionKeySha256 *string, encryptionAlgorithm EncryptionAlgorithmType, encryptionScope *string, ifSequenceNumberLessThanOrEqualTo *int64, ifSequenceNumberLessThan *int64, ifSequenceNumberEqualTo *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, ifTags *string, requestID *string) (*PageBlobUploadPagesResponse, error) { 793 if err := validate([]validation{ 794 {targetValue: body, 795 constraints: []constraint{{target: "body", name: null, rule: true, chain: nil}}}, 796 {targetValue: timeout, 797 constraints: []constraint{{target: "timeout", name: null, rule: false, 798 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 799 return nil, err 800 } 801 req, err := client.uploadPagesPreparer(body, contentLength, transactionalContentMD5, transactionalContentCrc64, timeout, rangeParameter, leaseID, encryptionKey, encryptionKeySha256, encryptionAlgorithm, encryptionScope, ifSequenceNumberLessThanOrEqualTo, ifSequenceNumberLessThan, ifSequenceNumberEqualTo, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, ifTags, requestID) 802 if err != nil { 803 return nil, err 804 } 805 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.uploadPagesResponder}, req) 806 if err != nil { 807 return nil, err 808 } 809 return resp.(*PageBlobUploadPagesResponse), err 810} 811 812// uploadPagesPreparer prepares the UploadPages request. 813func (client pageBlobClient) uploadPagesPreparer(body io.ReadSeeker, contentLength int64, transactionalContentMD5 []byte, transactionalContentCrc64 []byte, timeout *int32, rangeParameter *string, leaseID *string, encryptionKey *string, encryptionKeySha256 *string, encryptionAlgorithm EncryptionAlgorithmType, encryptionScope *string, ifSequenceNumberLessThanOrEqualTo *int64, ifSequenceNumberLessThan *int64, ifSequenceNumberEqualTo *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, ifTags *string, requestID *string) (pipeline.Request, error) { 814 req, err := pipeline.NewRequest("PUT", client.url, body) 815 if err != nil { 816 return req, pipeline.NewError(err, "failed to create request") 817 } 818 params := req.URL.Query() 819 if timeout != nil { 820 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 821 } 822 params.Set("comp", "page") 823 req.URL.RawQuery = params.Encode() 824 req.Header.Set("Content-Length", strconv.FormatInt(contentLength, 10)) 825 if transactionalContentMD5 != nil { 826 req.Header.Set("Content-MD5", base64.StdEncoding.EncodeToString(transactionalContentMD5)) 827 } 828 if transactionalContentCrc64 != nil { 829 req.Header.Set("x-ms-content-crc64", base64.StdEncoding.EncodeToString(transactionalContentCrc64)) 830 } 831 if rangeParameter != nil { 832 req.Header.Set("x-ms-range", *rangeParameter) 833 } 834 if leaseID != nil { 835 req.Header.Set("x-ms-lease-id", *leaseID) 836 } 837 if encryptionKey != nil { 838 req.Header.Set("x-ms-encryption-key", *encryptionKey) 839 } 840 if encryptionKeySha256 != nil { 841 req.Header.Set("x-ms-encryption-key-sha256", *encryptionKeySha256) 842 } 843 if encryptionAlgorithm != EncryptionAlgorithmNone { 844 req.Header.Set("x-ms-encryption-algorithm", string(encryptionAlgorithm)) 845 } 846 if encryptionScope != nil { 847 req.Header.Set("x-ms-encryption-scope", *encryptionScope) 848 } 849 if ifSequenceNumberLessThanOrEqualTo != nil { 850 req.Header.Set("x-ms-if-sequence-number-le", strconv.FormatInt(*ifSequenceNumberLessThanOrEqualTo, 10)) 851 } 852 if ifSequenceNumberLessThan != nil { 853 req.Header.Set("x-ms-if-sequence-number-lt", strconv.FormatInt(*ifSequenceNumberLessThan, 10)) 854 } 855 if ifSequenceNumberEqualTo != nil { 856 req.Header.Set("x-ms-if-sequence-number-eq", strconv.FormatInt(*ifSequenceNumberEqualTo, 10)) 857 } 858 if ifModifiedSince != nil { 859 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 860 } 861 if ifUnmodifiedSince != nil { 862 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 863 } 864 if ifMatch != nil { 865 req.Header.Set("If-Match", string(*ifMatch)) 866 } 867 if ifNoneMatch != nil { 868 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 869 } 870 if ifTags != nil { 871 req.Header.Set("x-ms-if-tags", *ifTags) 872 } 873 req.Header.Set("x-ms-version", ServiceVersion) 874 if requestID != nil { 875 req.Header.Set("x-ms-client-request-id", *requestID) 876 } 877 req.Header.Set("x-ms-page-write", "update") 878 return req, nil 879} 880 881// uploadPagesResponder handles the response to the UploadPages request. 882func (client pageBlobClient) uploadPagesResponder(resp pipeline.Response) (pipeline.Response, error) { 883 err := validateResponse(resp, http.StatusOK, http.StatusCreated) 884 if resp == nil { 885 return nil, err 886 } 887 io.Copy(ioutil.Discard, resp.Response().Body) 888 resp.Response().Body.Close() 889 return &PageBlobUploadPagesResponse{rawResponse: resp.Response()}, err 890} 891 892// UploadPagesFromURL the Upload Pages operation writes a range of pages to a page blob where the contents are read 893// from a URL 894// 895// sourceURL is specify a URL to the copy source. sourceRange is bytes of source data in the specified range. The 896// length of this range should match the ContentLength header and x-ms-range/Range destination range header. 897// contentLength is the length of the request. rangeParameter is the range of bytes to which the source range would be 898// written. The range should be 512 aligned and range-end is required. sourceContentMD5 is specify the md5 calculated 899// for the range of bytes that must be read from the copy source. sourceContentcrc64 is specify the crc64 calculated 900// for the range of bytes that must be read from the copy source. timeout is the timeout parameter is expressed in 901// seconds. For more information, see <a 902// href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations">Setting 903// Timeouts for Blob Service Operations.</a> encryptionKey is optional. Specifies the encryption key to use to encrypt 904// the data provided in the request. If not specified, encryption is performed with the root account encryption key. 905// For more information, see Encryption at Rest for Azure Storage Services. encryptionKeySha256 is the SHA-256 hash of 906// the provided encryption key. Must be provided if the x-ms-encryption-key header is provided. encryptionAlgorithm is 907// the algorithm used to produce the encryption key hash. Currently, the only accepted value is "AES256". Must be 908// provided if the x-ms-encryption-key header is provided. encryptionScope is optional. Version 2019-07-07 and later. 909// Specifies the name of the encryption scope to use to encrypt the data provided in the request. If not specified, 910// encryption is performed with the default account encryption scope. For more information, see Encryption at Rest for 911// Azure Storage Services. leaseID is if specified, the operation only succeeds if the resource's lease is active and 912// matches this ID. ifSequenceNumberLessThanOrEqualTo is specify this header value to operate only on a blob if it has 913// a sequence number less than or equal to the specified. ifSequenceNumberLessThan is specify this header value to 914// operate only on a blob if it has a sequence number less than the specified. ifSequenceNumberEqualTo is specify this 915// header value to operate only on a blob if it has the specified sequence number. ifModifiedSince is specify this 916// header value to operate only on a blob if it has been modified since the specified date/time. ifUnmodifiedSince is 917// specify this header value to operate only on a blob if it has not been modified since the specified date/time. 918// ifMatch is specify an ETag value to operate only on blobs with a matching value. ifNoneMatch is specify an ETag 919// value to operate only on blobs without a matching value. ifTags is specify a SQL where clause on blob tags to 920// operate only on blobs with a matching value. sourceIfModifiedSince is specify this header value to operate only on a 921// blob if it has been modified since the specified date/time. sourceIfUnmodifiedSince is specify this header value to 922// operate only on a blob if it has not been modified since the specified date/time. sourceIfMatch is specify an ETag 923// value to operate only on blobs with a matching value. sourceIfNoneMatch is specify an ETag value to operate only on 924// blobs without a matching value. requestID is provides a client-generated, opaque value with a 1 KB character limit 925// that is recorded in the analytics logs when storage analytics logging is enabled. 926func (client pageBlobClient) UploadPagesFromURL(ctx context.Context, sourceURL string, sourceRange string, contentLength int64, rangeParameter string, sourceContentMD5 []byte, sourceContentcrc64 []byte, timeout *int32, encryptionKey *string, encryptionKeySha256 *string, encryptionAlgorithm EncryptionAlgorithmType, encryptionScope *string, leaseID *string, ifSequenceNumberLessThanOrEqualTo *int64, ifSequenceNumberLessThan *int64, ifSequenceNumberEqualTo *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, ifTags *string, sourceIfModifiedSince *time.Time, sourceIfUnmodifiedSince *time.Time, sourceIfMatch *ETag, sourceIfNoneMatch *ETag, requestID *string) (*PageBlobUploadPagesFromURLResponse, error) { 927 if err := validate([]validation{ 928 {targetValue: timeout, 929 constraints: []constraint{{target: "timeout", name: null, rule: false, 930 chain: []constraint{{target: "timeout", name: inclusiveMinimum, rule: 0, chain: nil}}}}}}); err != nil { 931 return nil, err 932 } 933 req, err := client.uploadPagesFromURLPreparer(sourceURL, sourceRange, contentLength, rangeParameter, sourceContentMD5, sourceContentcrc64, timeout, encryptionKey, encryptionKeySha256, encryptionAlgorithm, encryptionScope, leaseID, ifSequenceNumberLessThanOrEqualTo, ifSequenceNumberLessThan, ifSequenceNumberEqualTo, ifModifiedSince, ifUnmodifiedSince, ifMatch, ifNoneMatch, ifTags, sourceIfModifiedSince, sourceIfUnmodifiedSince, sourceIfMatch, sourceIfNoneMatch, requestID) 934 if err != nil { 935 return nil, err 936 } 937 resp, err := client.Pipeline().Do(ctx, responderPolicyFactory{responder: client.uploadPagesFromURLResponder}, req) 938 if err != nil { 939 return nil, err 940 } 941 return resp.(*PageBlobUploadPagesFromURLResponse), err 942} 943 944// uploadPagesFromURLPreparer prepares the UploadPagesFromURL request. 945func (client pageBlobClient) uploadPagesFromURLPreparer(sourceURL string, sourceRange string, contentLength int64, rangeParameter string, sourceContentMD5 []byte, sourceContentcrc64 []byte, timeout *int32, encryptionKey *string, encryptionKeySha256 *string, encryptionAlgorithm EncryptionAlgorithmType, encryptionScope *string, leaseID *string, ifSequenceNumberLessThanOrEqualTo *int64, ifSequenceNumberLessThan *int64, ifSequenceNumberEqualTo *int64, ifModifiedSince *time.Time, ifUnmodifiedSince *time.Time, ifMatch *ETag, ifNoneMatch *ETag, ifTags *string, sourceIfModifiedSince *time.Time, sourceIfUnmodifiedSince *time.Time, sourceIfMatch *ETag, sourceIfNoneMatch *ETag, requestID *string) (pipeline.Request, error) { 946 req, err := pipeline.NewRequest("PUT", client.url, nil) 947 if err != nil { 948 return req, pipeline.NewError(err, "failed to create request") 949 } 950 params := req.URL.Query() 951 if timeout != nil { 952 params.Set("timeout", strconv.FormatInt(int64(*timeout), 10)) 953 } 954 params.Set("comp", "page") 955 req.URL.RawQuery = params.Encode() 956 req.Header.Set("x-ms-copy-source", sourceURL) 957 req.Header.Set("x-ms-source-range", sourceRange) 958 if sourceContentMD5 != nil { 959 req.Header.Set("x-ms-source-content-md5", base64.StdEncoding.EncodeToString(sourceContentMD5)) 960 } 961 if sourceContentcrc64 != nil { 962 req.Header.Set("x-ms-source-content-crc64", base64.StdEncoding.EncodeToString(sourceContentcrc64)) 963 } 964 req.Header.Set("Content-Length", strconv.FormatInt(contentLength, 10)) 965 req.Header.Set("x-ms-range", rangeParameter) 966 if encryptionKey != nil { 967 req.Header.Set("x-ms-encryption-key", *encryptionKey) 968 } 969 if encryptionKeySha256 != nil { 970 req.Header.Set("x-ms-encryption-key-sha256", *encryptionKeySha256) 971 } 972 if encryptionAlgorithm != EncryptionAlgorithmNone { 973 req.Header.Set("x-ms-encryption-algorithm", string(encryptionAlgorithm)) 974 } 975 if encryptionScope != nil { 976 req.Header.Set("x-ms-encryption-scope", *encryptionScope) 977 } 978 if leaseID != nil { 979 req.Header.Set("x-ms-lease-id", *leaseID) 980 } 981 if ifSequenceNumberLessThanOrEqualTo != nil { 982 req.Header.Set("x-ms-if-sequence-number-le", strconv.FormatInt(*ifSequenceNumberLessThanOrEqualTo, 10)) 983 } 984 if ifSequenceNumberLessThan != nil { 985 req.Header.Set("x-ms-if-sequence-number-lt", strconv.FormatInt(*ifSequenceNumberLessThan, 10)) 986 } 987 if ifSequenceNumberEqualTo != nil { 988 req.Header.Set("x-ms-if-sequence-number-eq", strconv.FormatInt(*ifSequenceNumberEqualTo, 10)) 989 } 990 if ifModifiedSince != nil { 991 req.Header.Set("If-Modified-Since", (*ifModifiedSince).In(gmt).Format(time.RFC1123)) 992 } 993 if ifUnmodifiedSince != nil { 994 req.Header.Set("If-Unmodified-Since", (*ifUnmodifiedSince).In(gmt).Format(time.RFC1123)) 995 } 996 if ifMatch != nil { 997 req.Header.Set("If-Match", string(*ifMatch)) 998 } 999 if ifNoneMatch != nil { 1000 req.Header.Set("If-None-Match", string(*ifNoneMatch)) 1001 } 1002 if ifTags != nil { 1003 req.Header.Set("x-ms-if-tags", *ifTags) 1004 } 1005 if sourceIfModifiedSince != nil { 1006 req.Header.Set("x-ms-source-if-modified-since", (*sourceIfModifiedSince).In(gmt).Format(time.RFC1123)) 1007 } 1008 if sourceIfUnmodifiedSince != nil { 1009 req.Header.Set("x-ms-source-if-unmodified-since", (*sourceIfUnmodifiedSince).In(gmt).Format(time.RFC1123)) 1010 } 1011 if sourceIfMatch != nil { 1012 req.Header.Set("x-ms-source-if-match", string(*sourceIfMatch)) 1013 } 1014 if sourceIfNoneMatch != nil { 1015 req.Header.Set("x-ms-source-if-none-match", string(*sourceIfNoneMatch)) 1016 } 1017 req.Header.Set("x-ms-version", ServiceVersion) 1018 if requestID != nil { 1019 req.Header.Set("x-ms-client-request-id", *requestID) 1020 } 1021 req.Header.Set("x-ms-page-write", "update") 1022 return req, nil 1023} 1024 1025// uploadPagesFromURLResponder handles the response to the UploadPagesFromURL request. 1026func (client pageBlobClient) uploadPagesFromURLResponder(resp pipeline.Response) (pipeline.Response, error) { 1027 err := validateResponse(resp, http.StatusOK, http.StatusCreated) 1028 if resp == nil { 1029 return nil, err 1030 } 1031 io.Copy(ioutil.Discard, resp.Response().Body) 1032 resp.Response().Body.Close() 1033 return &PageBlobUploadPagesFromURLResponse{rawResponse: resp.Response()}, err 1034} 1035