From 7e23aab822a1e376e1b7527df65def6595fbd31a Mon Sep 17 00:00:00 2001 From: Jeremy Meng Date: Mon, 21 Oct 2019 08:54:02 -0700 Subject: [PATCH] [Storage][Blob] Flatten and simplify access conditions (#5672) * [Storage][Blob] Flatten and simplify access conditions Use a flattened conditions type `BlobRequestConditions` instead of current nested one. It replaces `ContainerAccessConditions` and `BlobAccessConditions`. In addition, various conditions fields are renamed into simply `conditions`. This makes it more convenient to pass in conditional request options. the example ```js { blobAccessConditions: { modifiedAccessConditions: { ifMatch: uploadResponse.eTag } } ``` after this change becomes ```js { conditions: { ifMatch: uploadResponse.eTag } ``` --- .../storage-blob/src/AppendBlobClient.ts | 50 +++--- sdk/storage/storage-blob/src/BlobClient.ts | 149 +++++++++--------- .../storage-blob/src/BlobServiceClient.ts | 2 +- .../storage-blob/src/BlockBlobClient.ts | 62 ++++---- .../storage-blob/src/ContainerClient.ts | 92 +++++------ sdk/storage/storage-blob/src/LeaseClient.ts | 12 +- .../storage-blob/src/PageBlobClient.ts | 106 ++++++------- sdk/storage/storage-blob/src/models.ts | 22 +-- .../storage-blob/test/blobbatch.spec.ts | 21 +-- .../test/node/highlevel.node.spec.ts | 30 ++-- 10 files changed, 253 insertions(+), 293 deletions(-) diff --git a/sdk/storage/storage-blob/src/AppendBlobClient.ts b/sdk/storage/storage-blob/src/AppendBlobClient.ts index 1f16cdbf82f0..a7798a03664b 100644 --- a/sdk/storage/storage-blob/src/AppendBlobClient.ts +++ b/sdk/storage/storage-blob/src/AppendBlobClient.ts @@ -21,8 +21,8 @@ import { AbortSignalLike } from "@azure/abort-controller"; import { BlobClient, CommonOptions } from "./internal"; import { AppendBlob } from "./generated/src/operations"; import { - AppendBlobAccessConditions, - BlobAccessConditions, + AppendBlobRequestConditions, + BlobRequestConditions, Metadata, ensureCpkIfSpecified } from "./models"; @@ -57,10 +57,10 @@ export interface AppendBlobCreateOptions extends CommonOptions { /** * Conditions to meet when creating append blobs. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof AppendBlobCreateOptions */ - accessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * HTTP headers to set when creating append blobs. * @@ -102,10 +102,10 @@ export interface AppendBlobAppendBlockOptions extends CommonOptions { /** * Conditions to meet when appending append blob blocks. * - * @type {AppendBlobAccessConditions} + * @type {AppendBlobRequestConditions} * @memberof AppendBlobAppendBlockOptions */ - accessConditions?: AppendBlobAccessConditions; + conditions?: AppendBlobRequestConditions; /** * Callback to receive events on the progress of append block operation. * @@ -153,17 +153,17 @@ export interface AppendBlobAppendBlockFromURLOptions extends CommonOptions { /** * Conditions to meet when appending append blob blocks. * - * @type {AppendBlobAccessConditions} + * @type {AppendBlobRequestConditions} * @memberof AppendBlobAppendBlockFromURLOptions */ - accessConditions?: AppendBlobAccessConditions; + conditions?: AppendBlobRequestConditions; /** * Conditions to meet for the source Azure Blob/File when copying from a URL to the blob. * * @type {ModifiedAccessConditions} * @memberof AppendBlobAppendBlockFromURLOptions */ - sourceModifiedAccessConditions?: ModifiedAccessConditions; + sourceConditions?: ModifiedAccessConditions; /** * An MD5 hash of the append block content from the URI. * This hash is used to verify the integrity of the append block during transport of the data from the URI. @@ -391,16 +391,16 @@ export class AppendBlobClient extends BlobClient { */ public async create(options: AppendBlobCreateOptions = {}): Promise { const { span, spanOptions } = createSpan("AppendBlobClient-create", options.spanOptions); - options.accessConditions = options.accessConditions || {}; + options.conditions = options.conditions || {}; try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return this.appendBlobContext.create(0, { abortSignal: options.abortSignal, blobHTTPHeaders: options.blobHTTPHeaders, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, + leaseAccessConditions: options.conditions, metadata: options.metadata, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, cpkInfo: options.customerProvidedKey, spanOptions }); @@ -431,15 +431,15 @@ export class AppendBlobClient extends BlobClient { options: AppendBlobAppendBlockOptions = {} ): Promise { const { span, spanOptions } = createSpan("AppendBlobClient-appendBlock", options.spanOptions); - options.accessConditions = options.accessConditions || {}; + options.conditions = options.conditions || {}; try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return this.appendBlobContext.appendBlock(body, contentLength, { abortSignal: options.abortSignal, - appendPositionAccessConditions: options.accessConditions.appendPositionAccessConditions, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + appendPositionAccessConditions: options.conditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, onUploadProgress: options.onProgress, transactionalContentMD5: options.transactionalContentMD5, transactionalContentCrc64: options.transactionalContentCrc64, @@ -483,8 +483,8 @@ export class AppendBlobClient extends BlobClient { "AppendBlobClient-appendBlockFromURL", options.spanOptions ); - options.accessConditions = options.accessConditions || {}; - options.sourceModifiedAccessConditions = options.sourceModifiedAccessConditions || {}; + options.conditions = options.conditions || {}; + options.sourceConditions = options.sourceConditions || {}; try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); @@ -493,14 +493,14 @@ export class AppendBlobClient extends BlobClient { sourceRange: rangeToString({ offset: sourceOffset, count }), sourceContentMD5: options.sourceContentMD5, sourceContentCrc64: options.sourceContentCrc64, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, - appendPositionAccessConditions: options.accessConditions.appendPositionAccessConditions, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + appendPositionAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, sourceModifiedAccessConditions: { - sourceIfMatch: options.sourceModifiedAccessConditions.ifMatch, - sourceIfModifiedSince: options.sourceModifiedAccessConditions.ifModifiedSince, - sourceIfNoneMatch: options.sourceModifiedAccessConditions.ifNoneMatch, - sourceIfUnmodifiedSince: options.sourceModifiedAccessConditions.ifUnmodifiedSince + sourceIfMatch: options.sourceConditions.ifMatch, + sourceIfModifiedSince: options.sourceConditions.ifModifiedSince, + sourceIfNoneMatch: options.sourceConditions.ifNoneMatch, + sourceIfUnmodifiedSince: options.sourceConditions.ifUnmodifiedSince }, cpkInfo: options.customerProvidedKey, spanOptions diff --git a/sdk/storage/storage-blob/src/BlobClient.ts b/sdk/storage/storage-blob/src/BlobClient.ts index 863fa2e6127c..566a017a994b 100644 --- a/sdk/storage/storage-blob/src/BlobClient.ts +++ b/sdk/storage/storage-blob/src/BlobClient.ts @@ -33,7 +33,7 @@ import { BlobDownloadResponse } from "./BlobDownloadResponse"; import { Blob } from "./generated/src/operations"; import { rangeToString } from "./Range"; import { - BlobAccessConditions, + BlobRequestConditions, Metadata, ensureCpkIfSpecified, BlockBlobTier, @@ -109,10 +109,10 @@ export interface BlobDownloadOptions extends CommonOptions { /** * Conditions to meet when downloading blobs. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlobDownloadOptions */ - blobAccessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * Call back to receive events on the progress of download operation. * @@ -187,10 +187,10 @@ export interface BlobGetPropertiesOptions extends CommonOptions { /** * Conditions to meet when getting blob properties. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlobGetPropertiesOptions */ - blobAccessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * Customer Provided Key Info. * @@ -218,10 +218,10 @@ export interface BlobDeleteOptions extends CommonOptions { /** * Conditions to meet when deleting blobs. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlobDeleteOptions */ - blobAccessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * Specifies options to delete blobs that have associated snapshots. * - `include`: Delete the base blob and all of its snapshots. @@ -282,10 +282,10 @@ export interface BlobSetHTTPHeadersOptions extends CommonOptions { /** * Conditions to meet when setting blob HTTP headers. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlobSetHTTPHeadersOptions */ - blobAccessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * Customer Provided Key Info. * @@ -313,10 +313,10 @@ export interface BlobSetMetadataOptions extends CommonOptions { /** * Conditions to meet when setting blob metadata. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlobSetMetadataOptions */ - blobAccessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * Customer Provided Key Info. * @@ -347,7 +347,7 @@ export interface BlobAcquireLeaseOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof BlobAcquireLeaseOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } /** @@ -371,7 +371,7 @@ export interface BlobReleaseLeaseOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof BlobReleaseLeaseOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } /** @@ -395,7 +395,7 @@ export interface BlobRenewLeaseOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof BlobRenewLeaseOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } /** @@ -419,7 +419,7 @@ export interface BlobChangeLeaseOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof BlobChangeLeaseOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } /** @@ -443,7 +443,7 @@ export interface BlobBreakLeaseOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof BlobBreakLeaseOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } /** @@ -471,10 +471,10 @@ export interface BlobCreateSnapshotOptions extends CommonOptions { /** * Conditions to meet when creating blob snapshots. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlobCreateSnapshotOptions */ - blobAccessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * Customer Provided Key Info. * @@ -509,17 +509,17 @@ export interface BlobStartCopyFromURLOptions extends CommonOptions { /** * Conditions to meet for the destination blob when copying from a URL to the blob. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlobStartCopyFromURLOptions */ - blobAccessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * Conditions to meet for the source Azure Blob/File when copying from a URL to the blob. * * @type {ModifiedAccessConditions} * @memberof BlobStartCopyFromURLOptions */ - sourceModifiedAccessConditions?: ModifiedAccessConditions; + sourceConditions?: ModifiedAccessConditions; /** * Access tier. * More Details - https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers @@ -560,7 +560,7 @@ export interface BlobAbortCopyFromURLOptions extends CommonOptions { * @type {LeaseAccessConditions} * @memberof BlobAbortCopyFromURLOptions */ - leaseAccessConditions?: LeaseAccessConditions; + conditions?: LeaseAccessConditions; } /** @@ -588,17 +588,17 @@ export interface BlobSyncCopyFromURLOptions extends CommonOptions { /** * Conditions to meet for the destination blob when copying from a URL to the blob. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlobSyncCopyFromURLOptions */ - blobAccessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * Conditions to meet for the source Azure Blob/File when copying from a URL to the blob. * * @type {ModifiedAccessConditions} * @memberof BlobSyncCopyFromURLOptions */ - sourceModifiedAccessConditions?: ModifiedAccessConditions; + sourceConditions?: ModifiedAccessConditions; } /** @@ -623,7 +623,7 @@ export interface BlobSetTierOptions extends CommonOptions { * @type {LeaseAccessConditions} * @memberof BlobSetTierOptions */ - leaseAccessConditions?: LeaseAccessConditions; + conditions?: LeaseAccessConditions; /** * Rehydrate Priority - possible values include 'High', 'Standard'. * More Details - https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-rehydration#rehydrate-an-archived-blob-to-an-online-tier @@ -688,10 +688,10 @@ export interface BlobDownloadToBufferOptions extends CommonOptions { /** * Access conditions headers. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlobDownloadToBufferOptions */ - blobAccessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * Concurrency of parallel download. @@ -945,9 +945,8 @@ export class BlobClient extends StorageClient { count?: number, options: BlobDownloadOptions = {} ): Promise { - options.blobAccessConditions = options.blobAccessConditions || {}; - options.blobAccessConditions.modifiedAccessConditions = - options.blobAccessConditions.modifiedAccessConditions || {}; + options.conditions = options.conditions || {}; + options.conditions = options.conditions || {}; ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); const { span, spanOptions } = createSpan("BlobClient-download", options.spanOptions); @@ -955,8 +954,8 @@ export class BlobClient extends StorageClient { try { const res = await this.blobContext.download({ abortSignal: options.abortSignal, - leaseAccessConditions: options.blobAccessConditions.leaseAccessConditions, - modifiedAccessConditions: options.blobAccessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, onDownloadProgress: isNode ? undefined : options.onProgress, range: offset === 0 && !count ? undefined : rangeToString({ offset, count }), rangeGetContentMD5: options.rangeGetContentMD5, @@ -993,14 +992,12 @@ export class BlobClient extends StorageClient { res, async (start: number): Promise => { const updatedOptions: BlobDownloadOptionalParams = { - leaseAccessConditions: options.blobAccessConditions!.leaseAccessConditions, + leaseAccessConditions: options.conditions, modifiedAccessConditions: { - ifMatch: options.blobAccessConditions!.modifiedAccessConditions!.ifMatch || res.eTag, - ifModifiedSince: options.blobAccessConditions!.modifiedAccessConditions! - .ifModifiedSince, - ifNoneMatch: options.blobAccessConditions!.modifiedAccessConditions!.ifNoneMatch, - ifUnmodifiedSince: options.blobAccessConditions!.modifiedAccessConditions! - .ifUnmodifiedSince + ifMatch: options.conditions!.ifMatch || res.eTag, + ifModifiedSince: options.conditions!.ifModifiedSince, + ifNoneMatch: options.conditions!.ifNoneMatch, + ifUnmodifiedSince: options.conditions!.ifUnmodifiedSince }, range: rangeToString({ count: offset + res.contentLength! - start, @@ -1096,12 +1093,12 @@ export class BlobClient extends StorageClient { ): Promise { const { span, spanOptions } = createSpan("BlobClient-getProperties", options.spanOptions); try { - options.blobAccessConditions = options.blobAccessConditions || {}; + options.conditions = options.conditions || {}; ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return this.blobContext.getProperties({ abortSignal: options.abortSignal, - leaseAccessConditions: options.blobAccessConditions.leaseAccessConditions, - modifiedAccessConditions: options.blobAccessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, cpkInfo: options.customerProvidedKey, spanOptions }); @@ -1129,13 +1126,13 @@ export class BlobClient extends StorageClient { */ public async delete(options: BlobDeleteOptions = {}): Promise { const { span, spanOptions } = createSpan("BlobClient-delete", options.spanOptions); - options.blobAccessConditions = options.blobAccessConditions || {}; + options.conditions = options.conditions || {}; try { return this.blobContext.deleteMethod({ abortSignal: options.abortSignal, deleteSnapshots: options.deleteSnapshots, - leaseAccessConditions: options.blobAccessConditions.leaseAccessConditions, - modifiedAccessConditions: options.blobAccessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, spanOptions }); } catch (e) { @@ -1196,14 +1193,14 @@ export class BlobClient extends StorageClient { options: BlobSetHTTPHeadersOptions = {} ): Promise { const { span, spanOptions } = createSpan("BlobClient-setHTTPHeaders", options.spanOptions); - options.blobAccessConditions = options.blobAccessConditions || {}; + options.conditions = options.conditions || {}; try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return this.blobContext.setHTTPHeaders({ abortSignal: options.abortSignal, blobHTTPHeaders, - leaseAccessConditions: options.blobAccessConditions.leaseAccessConditions, - modifiedAccessConditions: options.blobAccessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, cpkInfo: options.customerProvidedKey, spanOptions }); @@ -1236,14 +1233,14 @@ export class BlobClient extends StorageClient { options: BlobSetMetadataOptions = {} ): Promise { const { span, spanOptions } = createSpan("BlobClient-setMetadata", options.spanOptions); - options.blobAccessConditions = options.blobAccessConditions || {}; + options.conditions = options.conditions || {}; try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return this.blobContext.setMetadata({ abortSignal: options.abortSignal, - leaseAccessConditions: options.blobAccessConditions.leaseAccessConditions, + leaseAccessConditions: options.conditions, metadata, - modifiedAccessConditions: options.blobAccessConditions.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, cpkInfo: options.customerProvidedKey, spanOptions }); @@ -1281,14 +1278,14 @@ export class BlobClient extends StorageClient { options: BlobCreateSnapshotOptions = {} ): Promise { const { span, spanOptions } = createSpan("BlobClient-createSnapshot", options.spanOptions); - options.blobAccessConditions = options.blobAccessConditions || {}; + options.conditions = options.conditions || {}; try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return this.blobContext.createSnapshot({ abortSignal: options.abortSignal, - leaseAccessConditions: options.blobAccessConditions.leaseAccessConditions, + leaseAccessConditions: options.conditions, metadata: options.metadata, - modifiedAccessConditions: options.blobAccessConditions.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, cpkInfo: options.customerProvidedKey, spanOptions }); @@ -1323,20 +1320,20 @@ export class BlobClient extends StorageClient { options: BlobStartCopyFromURLOptions = {} ): Promise { const { span, spanOptions } = createSpan("BlobClient-startCopyFromURL", options.spanOptions); - options.blobAccessConditions = options.blobAccessConditions || {}; - options.sourceModifiedAccessConditions = options.sourceModifiedAccessConditions || {}; + options.conditions = options.conditions || {}; + options.sourceConditions = options.sourceConditions || {}; try { return this.blobContext.startCopyFromURL(copySource, { abortSignal: options.abortSignal, - leaseAccessConditions: options.blobAccessConditions.leaseAccessConditions, + leaseAccessConditions: options.conditions, metadata: options.metadata, - modifiedAccessConditions: options.blobAccessConditions.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, sourceModifiedAccessConditions: { - sourceIfMatch: options.sourceModifiedAccessConditions.ifMatch, - sourceIfModifiedSince: options.sourceModifiedAccessConditions.ifModifiedSince, - sourceIfNoneMatch: options.sourceModifiedAccessConditions.ifNoneMatch, - sourceIfUnmodifiedSince: options.sourceModifiedAccessConditions.ifUnmodifiedSince + sourceIfMatch: options.sourceConditions.ifMatch, + sourceIfModifiedSince: options.sourceConditions.ifModifiedSince, + sourceIfNoneMatch: options.sourceConditions.ifNoneMatch, + sourceIfUnmodifiedSince: options.sourceConditions.ifUnmodifiedSince }, rehydratePriority: options.rehydratePriority, tier: toAccessTier(options.tier), @@ -1371,7 +1368,7 @@ export class BlobClient extends StorageClient { try { return this.blobContext.abortCopyFromURL(copyId, { abortSignal: options.abortSignal, - leaseAccessConditions: options.leaseAccessConditions, + leaseAccessConditions: options.conditions, spanOptions }); } catch (e) { @@ -1400,20 +1397,20 @@ export class BlobClient extends StorageClient { options: BlobSyncCopyFromURLOptions = {} ): Promise { const { span, spanOptions } = createSpan("BlobClient-syncCopyFromURL", options.spanOptions); - options.blobAccessConditions = options.blobAccessConditions || {}; - options.sourceModifiedAccessConditions = options.sourceModifiedAccessConditions || {}; + options.conditions = options.conditions || {}; + options.sourceConditions = options.sourceConditions || {}; try { return this.blobContext.copyFromURL(copySource, { abortSignal: options.abortSignal, metadata: options.metadata, - leaseAccessConditions: options.blobAccessConditions.leaseAccessConditions, - modifiedAccessConditions: options.blobAccessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, sourceModifiedAccessConditions: { - sourceIfMatch: options.sourceModifiedAccessConditions.ifMatch, - sourceIfModifiedSince: options.sourceModifiedAccessConditions.ifModifiedSince, - sourceIfNoneMatch: options.sourceModifiedAccessConditions.ifNoneMatch, - sourceIfUnmodifiedSince: options.sourceModifiedAccessConditions.ifUnmodifiedSince + sourceIfMatch: options.sourceConditions.ifMatch, + sourceIfModifiedSince: options.sourceConditions.ifModifiedSince, + sourceIfNoneMatch: options.sourceConditions.ifNoneMatch, + sourceIfUnmodifiedSince: options.sourceConditions.ifUnmodifiedSince }, spanOptions }); @@ -1449,7 +1446,7 @@ export class BlobClient extends StorageClient { try { return await this.blobContext.setTier(toAccessTier(tier)!, { abortSignal: options.abortSignal, - leaseAccessConditions: options.leaseAccessConditions, + leaseAccessConditions: options.conditions, rehydratePriority: options.rehydratePriority, spanOptions }); @@ -1506,8 +1503,8 @@ export class BlobClient extends StorageClient { throw new RangeError("count option must be > 0"); } - if (!options.blobAccessConditions) { - options.blobAccessConditions = {}; + if (!options.conditions) { + options.conditions = {}; } // Customer doesn't specify length, get it @@ -1541,7 +1538,7 @@ export class BlobClient extends StorageClient { } const response = await this.download(off, chunkEnd - off, { abortSignal: options.abortSignal, - blobAccessConditions: options.blobAccessConditions, + conditions: options.conditions, maxRetryRequests: options.maxRetryRequestsPerBlock, spanOptions }); diff --git a/sdk/storage/storage-blob/src/BlobServiceClient.ts b/sdk/storage/storage-blob/src/BlobServiceClient.ts index e1c0a6173139..50c861b31c7c 100644 --- a/sdk/storage/storage-blob/src/BlobServiceClient.ts +++ b/sdk/storage/storage-blob/src/BlobServiceClient.ts @@ -894,7 +894,7 @@ export class BlobServiceClient extends StorageClient { * let batchSetTierRequest = new BatchSetTierRequest(); * await batchSetTierRequest.addSubRequest(blockBlobClient0, "Cool"); * await batchSetTierRequest.addSubRequest(blockBlobClient1, "Cool", { - * leaseAccessConditions: { leaseId: leaseId } + * conditions: { leaseId: leaseId } * }); * const setTierBatchResp = await blobServiceClient.submitBatch(batchSetTierRequest); * console.log(setTierBatchResp.subResponsesSucceededCount); diff --git a/sdk/storage/storage-blob/src/BlockBlobClient.ts b/sdk/storage/storage-blob/src/BlockBlobClient.ts index c71e2da1fb19..b5bcecebe929 100644 --- a/sdk/storage/storage-blob/src/BlockBlobClient.ts +++ b/sdk/storage/storage-blob/src/BlockBlobClient.ts @@ -30,7 +30,7 @@ import { BlobClient, CommonOptions } from "./internal"; import { BlockBlob } from "./generated/src/operations"; import { Range, rangeToString } from "./Range"; import { - BlobAccessConditions, + BlobRequestConditions, Metadata, ensureCpkIfSpecified, BlockBlobTier, @@ -76,10 +76,10 @@ export interface BlockBlobUploadOptions extends CommonOptions { /** * Conditions to meet when uploading to the block blob. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlockBlobUploadOptions */ - accessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * HTTP headers to set when uploading to a block blob. * @@ -139,7 +139,7 @@ export interface BlockBlobStageBlockOptions extends CommonOptions { * @type {LeaseAccessConditions} * @memberof BlockBlobStageBlockOptions */ - leaseAccessConditions?: LeaseAccessConditions; + conditions?: LeaseAccessConditions; /** * Callback to receive events on the progress of stage block operation. * @@ -206,7 +206,7 @@ export interface BlockBlobStageBlockFromURLOptions extends CommonOptions { * @type {LeaseAccessConditions} * @memberof BlockBlobStageBlockFromURLOptions */ - leaseAccessConditions?: LeaseAccessConditions; + conditions?: LeaseAccessConditions; /** * An MD5 hash of the content from the URI. * This hash is used to verify the integrity of the content during transport of the data from the URI. @@ -255,16 +255,16 @@ export interface BlockBlobCommitBlockListOptions extends CommonOptions { /** * Conditions to meet when committing the block list. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlockBlobCommitBlockListOptions */ /** * Conditions to meet when committing block list. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlockBlobCommitBlockListOptions */ - accessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * HTTP headers to set when committing block list. * @@ -318,7 +318,7 @@ export interface BlockBlobGetBlockListOptions extends CommonOptions { * @type {LeaseAccessConditions} * @memberof BlockBlobGetBlockListOptions */ - leaseAccessConditions?: LeaseAccessConditions; + conditions?: LeaseAccessConditions; } /** @@ -356,10 +356,10 @@ export interface BlockBlobUploadStreamOptions extends CommonOptions { /** * Access conditions headers. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlockBlobUploadStreamOptions */ - accessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * Progress updater. @@ -429,10 +429,10 @@ export interface BlockBlobParallelUploadOptions extends CommonOptions { /** * Access conditions headers. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof BlockBlobParallelUploadOptions */ - blobAccessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * Concurrency of parallel uploading. Must be >= 0. @@ -668,16 +668,16 @@ export class BlockBlobClient extends BlobClient { contentLength: number, options: BlockBlobUploadOptions = {} ): Promise { - options.accessConditions = options.accessConditions || {}; + options.conditions = options.conditions || {}; const { span, spanOptions } = createSpan("BlockBlobClient-upload", options.spanOptions); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return this.blockBlobContext.upload(body, contentLength, { abortSignal: options.abortSignal, blobHTTPHeaders: options.blobHTTPHeaders, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, + leaseAccessConditions: options.conditions, metadata: options.metadata, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, onUploadProgress: options.onProgress, cpkInfo: options.customerProvidedKey, tier: toAccessTier(options.tier), @@ -717,7 +717,7 @@ export class BlockBlobClient extends BlobClient { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return this.blockBlobContext.stageBlock(blockId, contentLength, body, { abortSignal: options.abortSignal, - leaseAccessConditions: options.leaseAccessConditions, + leaseAccessConditions: options.conditions, onUploadProgress: options.onProgress, transactionalContentMD5: options.transactionalContentMD5, transactionalContentCrc64: options.transactionalContentCrc64, @@ -772,7 +772,7 @@ export class BlockBlobClient extends BlobClient { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return this.blockBlobContext.stageBlockFromURL(blockId, 0, sourceURL, { abortSignal: options.abortSignal, - leaseAccessConditions: options.leaseAccessConditions, + leaseAccessConditions: options.conditions, sourceContentMD5: options.sourceContentMD5, sourceContentCrc64: options.sourceContentCrc64, sourceRange: offset === 0 && !count ? undefined : rangeToString({ offset, count }), @@ -807,7 +807,7 @@ export class BlockBlobClient extends BlobClient { blocks: string[], options: BlockBlobCommitBlockListOptions = {} ): Promise { - options.accessConditions = options.accessConditions || {}; + options.conditions = options.conditions || {}; const { span, spanOptions } = createSpan( "BlockBlobClient-commitBlockList", options.spanOptions @@ -819,9 +819,9 @@ export class BlockBlobClient extends BlobClient { { abortSignal: options.abortSignal, blobHTTPHeaders: options.blobHTTPHeaders, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, + leaseAccessConditions: options.conditions, metadata: options.metadata, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, cpkInfo: options.customerProvidedKey, tier: toAccessTier(options.tier), spanOptions @@ -857,7 +857,7 @@ export class BlockBlobClient extends BlobClient { try { const res = await this.blockBlobContext.getBlockList(listType, { abortSignal: options.abortSignal, - leaseAccessConditions: options.leaseAccessConditions, + leaseAccessConditions: options.conditions, spanOptions }); @@ -980,8 +980,8 @@ export class BlockBlobClient extends BlobClient { if (!options.blobHTTPHeaders) { options.blobHTTPHeaders = {}; } - if (!options.blobAccessConditions) { - options.blobAccessConditions = {}; + if (!options.conditions) { + options.conditions = {}; } const { span, spanOptions } = createSpan( @@ -1017,7 +1017,7 @@ export class BlockBlobClient extends BlobClient { blockList.push(blockID); await this.stageBlock(blockID, blobFactory(start, contentLength), contentLength, { abortSignal: options.abortSignal, - leaseAccessConditions: options.blobAccessConditions!.leaseAccessConditions, + conditions: options.conditions, spanOptions }); // Update progress after block is successfully uploaded to server, in case of block trying @@ -1112,8 +1112,8 @@ export class BlockBlobClient extends BlobClient { if (!options.blobHTTPHeaders) { options.blobHTTPHeaders = {}; } - if (!options.accessConditions) { - options.accessConditions = {}; + if (!options.conditions) { + options.conditions = {}; } const { span, spanOptions } = createSpan("BlockBlobClient-uploadStream", options.spanOptions); @@ -1134,7 +1134,7 @@ export class BlockBlobClient extends BlobClient { blockNum++; await this.stageBlock(blockID, buffer, buffer.length, { - leaseAccessConditions: options.accessConditions!.leaseAccessConditions, + conditions: options.conditions, spanOptions }); @@ -1222,8 +1222,8 @@ export class BlockBlobClient extends BlobClient { if (!options.blobHTTPHeaders) { options.blobHTTPHeaders = {}; } - if (!options.blobAccessConditions) { - options.blobAccessConditions = {}; + if (!options.conditions) { + options.conditions = {}; } const { span, spanOptions } = createSpan( @@ -1263,7 +1263,7 @@ export class BlockBlobClient extends BlobClient { contentLength, { abortSignal: options.abortSignal, - leaseAccessConditions: options.blobAccessConditions!.leaseAccessConditions, + conditions: options.conditions, spanOptions } ); diff --git a/sdk/storage/storage-blob/src/ContainerClient.ts b/sdk/storage/storage-blob/src/ContainerClient.ts index c15fc586e657..7252cb639f86 100644 --- a/sdk/storage/storage-blob/src/ContainerClient.ts +++ b/sdk/storage/storage-blob/src/ContainerClient.ts @@ -30,7 +30,7 @@ import { BlobPrefix } from "./generatedModels"; import { Container } from "./generated/src/operations"; -import { ContainerAccessConditions, Metadata } from "./models"; +import { BlobRequestConditions, Metadata } from "./models"; import { DevelopmentConnectionString } from "./utils/constants"; import { newPipeline, StoragePipelineOptions, Pipeline } from "./Pipeline"; import { ETagNone } from "./utils/constants"; @@ -112,7 +112,7 @@ export interface ContainerGetPropertiesOptions extends CommonOptions { * @type {LeaseAccessConditions} * @memberof ContainerGetPropertiesOptions */ - leaseAccessConditions?: LeaseAccessConditions; + conditions?: LeaseAccessConditions; } /** @@ -133,10 +133,10 @@ export interface ContainerDeleteMethodOptions extends CommonOptions { /** * Conditions to meet when deleting the container. * - * @type {ContainerAccessConditions} + * @type {BlobRequestConditions} * @memberof ContainerDeleteMethodOptions */ - containerAccessConditions?: ContainerAccessConditions; + conditions?: BlobRequestConditions; } /** @@ -175,10 +175,10 @@ export interface ContainerSetMetadataOptions extends CommonOptions { * If specified, contains the lease id that must be matched and lease with this id * must be active in order for the operation to succeed. * - * @type {ContainerAccessConditions} + * @type {BlobRequestConditions} * @memberof ContainerSetMetadataOptions */ - containerAccessConditions?: ContainerAccessConditions; + conditions?: BlobRequestConditions; } /** @@ -203,7 +203,7 @@ export interface ContainerGetAccessPolicyOptions extends CommonOptions { * @type {LeaseAccessConditions} * @memberof ContainerGetAccessPolicyOptions */ - leaseAccessConditions?: LeaseAccessConditions; + conditions?: LeaseAccessConditions; } /** @@ -277,10 +277,10 @@ export interface ContainerSetAccessPolicyOptions extends CommonOptions { /** * Conditions to meet when setting the access policy. * - * @type {ContainerAccessConditions} + * @type {BlobRequestConditions} * @memberof ContainerSetAccessPolicyOptions */ - containerAccessConditions?: ContainerAccessConditions; + conditions?: BlobRequestConditions; } /** @@ -304,7 +304,7 @@ export interface ContainerAcquireLeaseOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof ContainerAcquireLeaseOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } /** @@ -328,7 +328,7 @@ export interface ContainerReleaseLeaseOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof ContainerReleaseLeaseOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } /** @@ -352,7 +352,7 @@ export interface ContainerRenewLeaseOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof ContainerRenewLeaseOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } /** @@ -376,7 +376,7 @@ export interface ContainerBreakLeaseOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof ContainerBreakLeaseOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } /** @@ -400,7 +400,7 @@ export interface ContainerChangeLeaseOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof ContainerChangeLeaseOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } /** @@ -762,15 +762,15 @@ export class ContainerClient extends StorageClient { public async getProperties( options: ContainerGetPropertiesOptions = {} ): Promise { - if (!options.leaseAccessConditions) { - options.leaseAccessConditions = {}; + if (!options.conditions) { + options.conditions = {}; } const { span, spanOptions } = createSpan("ContainerClient-getProperties", options.spanOptions); try { return this.containerContext.getProperties({ abortSignal: options.abortSignal, - ...options.leaseAccessConditions, + ...options.conditions, spanOptions }); } catch (e) { @@ -796,23 +796,13 @@ export class ContainerClient extends StorageClient { public async delete( options: ContainerDeleteMethodOptions = {} ): Promise { - if (!options.containerAccessConditions) { - options.containerAccessConditions = {}; - } - - if (!options.containerAccessConditions.modifiedAccessConditions) { - options.containerAccessConditions.modifiedAccessConditions = {}; - } - - if (!options.containerAccessConditions.leaseAccessConditions) { - options.containerAccessConditions.leaseAccessConditions = {}; + if (!options.conditions) { + options.conditions = {}; } if ( - (options.containerAccessConditions.modifiedAccessConditions.ifMatch && - options.containerAccessConditions.modifiedAccessConditions.ifMatch !== ETagNone) || - (options.containerAccessConditions.modifiedAccessConditions.ifNoneMatch && - options.containerAccessConditions.modifiedAccessConditions.ifNoneMatch !== ETagNone) + (options.conditions.ifMatch && options.conditions.ifMatch !== ETagNone) || + (options.conditions.ifNoneMatch && options.conditions.ifNoneMatch !== ETagNone) ) { throw new RangeError( "the IfMatch and IfNoneMatch access conditions must have their default\ @@ -825,8 +815,8 @@ export class ContainerClient extends StorageClient { try { return this.containerContext.deleteMethod({ abortSignal: options.abortSignal, - leaseAccessConditions: options.containerAccessConditions.leaseAccessConditions, - modifiedAccessConditions: options.containerAccessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, spanOptions }); } catch (e) { @@ -858,24 +848,14 @@ export class ContainerClient extends StorageClient { metadata?: Metadata, options: ContainerSetMetadataOptions = {} ): Promise { - if (!options.containerAccessConditions) { - options.containerAccessConditions = {}; - } - - if (!options.containerAccessConditions.modifiedAccessConditions) { - options.containerAccessConditions.modifiedAccessConditions = {}; - } - - if (!options.containerAccessConditions.leaseAccessConditions) { - options.containerAccessConditions.leaseAccessConditions = {}; + if (!options.conditions) { + options.conditions = {}; } if ( - options.containerAccessConditions.modifiedAccessConditions.ifUnmodifiedSince || - (options.containerAccessConditions.modifiedAccessConditions.ifMatch && - options.containerAccessConditions.modifiedAccessConditions.ifMatch !== ETagNone) || - (options.containerAccessConditions.modifiedAccessConditions.ifNoneMatch && - options.containerAccessConditions.modifiedAccessConditions.ifNoneMatch !== ETagNone) + options.conditions.ifUnmodifiedSince || + (options.conditions.ifMatch && options.conditions.ifMatch !== ETagNone) || + (options.conditions.ifNoneMatch && options.conditions.ifNoneMatch !== ETagNone) ) { throw new RangeError( "the IfUnmodifiedSince, IfMatch, and IfNoneMatch must have their default values\ @@ -888,9 +868,9 @@ export class ContainerClient extends StorageClient { try { return this.containerContext.setMetadata({ abortSignal: options.abortSignal, - leaseAccessConditions: options.containerAccessConditions.leaseAccessConditions, + leaseAccessConditions: options.conditions, metadata, - modifiedAccessConditions: options.containerAccessConditions.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, spanOptions }); } catch (e) { @@ -920,8 +900,8 @@ export class ContainerClient extends StorageClient { public async getAccessPolicy( options: ContainerGetAccessPolicyOptions = {} ): Promise { - if (!options.leaseAccessConditions) { - options.leaseAccessConditions = {}; + if (!options.conditions) { + options.conditions = {}; } const { span, spanOptions } = createSpan( @@ -932,7 +912,7 @@ export class ContainerClient extends StorageClient { try { const response = await this.containerContext.getAccessPolicy({ abortSignal: options.abortSignal, - leaseAccessConditions: options.leaseAccessConditions, + leaseAccessConditions: options.conditions, spanOptions }); @@ -1000,7 +980,7 @@ export class ContainerClient extends StorageClient { containerAcl?: SignedIdentifier[], options: ContainerSetAccessPolicyOptions = {} ): Promise { - options.containerAccessConditions = options.containerAccessConditions || {}; + options.conditions = options.conditions || {}; const { span, spanOptions } = createSpan( "ContainerClient-setAccessPolicy", options.spanOptions @@ -1026,8 +1006,8 @@ export class ContainerClient extends StorageClient { abortSignal: options.abortSignal, access, containerAcl: acl, - leaseAccessConditions: options.containerAccessConditions.leaseAccessConditions, - modifiedAccessConditions: options.containerAccessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, spanOptions }); } catch (e) { diff --git a/sdk/storage/storage-blob/src/LeaseClient.ts b/sdk/storage/storage-blob/src/LeaseClient.ts index 66c4337e5cb1..5e5f7af2c0fb 100644 --- a/sdk/storage/storage-blob/src/LeaseClient.ts +++ b/sdk/storage/storage-blob/src/LeaseClient.ts @@ -92,7 +92,7 @@ export interface LeaseOperationOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof LeaseOperationOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } /** @@ -173,7 +173,7 @@ export class LeaseClient { return await this._containerOrBlobOperation.acquireLease({ abortSignal: options.abortSignal, duration, - modifiedAccessConditions: options.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, proposedLeaseId: this._leaseId, spanOptions }); @@ -210,7 +210,7 @@ export class LeaseClient { proposedLeaseId, { abortSignal: options.abortSignal, - modifiedAccessConditions: options.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, spanOptions } ); @@ -243,7 +243,7 @@ export class LeaseClient { try { return await this._containerOrBlobOperation.releaseLease(this._leaseId, { abortSignal: options.abortSignal, - modifiedAccessConditions: options.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, spanOptions }); } catch (e) { @@ -272,7 +272,7 @@ export class LeaseClient { try { return await this._containerOrBlobOperation.renewLease(this._leaseId, { abortSignal: options.abortSignal, - modifiedAccessConditions: options.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, spanOptions }); } catch (e) { @@ -309,7 +309,7 @@ export class LeaseClient { const operationOptions: ContainerBreakLeaseOptionalParams = { abortSignal: options.abortSignal, breakPeriod, - modifiedAccessConditions: options.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, spanOptions }; return await this._containerOrBlobOperation.breakLease(operationOptions); diff --git a/sdk/storage/storage-blob/src/PageBlobClient.ts b/sdk/storage/storage-blob/src/PageBlobClient.ts index f775fa3dd063..424591833e28 100644 --- a/sdk/storage/storage-blob/src/PageBlobClient.ts +++ b/sdk/storage/storage-blob/src/PageBlobClient.ts @@ -27,9 +27,9 @@ import { import { PageBlob } from "./generated/src/operations"; import { rangeToString } from "./Range"; import { - BlobAccessConditions, + BlobRequestConditions, Metadata, - PageBlobAccessConditions, + PageBlobRequestConditions, ensureCpkIfSpecified, PremiumPageBlobTier, toAccessTier @@ -68,10 +68,10 @@ export interface PageBlobCreateOptions extends CommonOptions { /** * Conditions to meet when creating a page blob. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof PageBlobCreateOptions */ - accessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * A user-controlled value that can be used to track requests. * The value must be between 0 and 2^63 - 1. The default value is 0. @@ -129,10 +129,10 @@ export interface PageBlobUploadPagesOptions extends CommonOptions { /** * Conditions to meet when uploading pages. * - * @type {PageBlobAccessConditions} + * @type {PageBlobRequestConditions} * @memberof PageBlobUploadPagesOptions */ - accessConditions?: PageBlobAccessConditions; + conditions?: PageBlobRequestConditions; /** * Callback to receive events on the progress of upload pages operation. * @@ -186,10 +186,10 @@ export interface PageBlobClearPagesOptions extends CommonOptions { /** * Conditions to meet when clearing pages. * - * @type {PageBlobAccessConditions} + * @type {PageBlobRequestConditions} * @memberof PageBlobClearPagesOptions */ - accessConditions?: PageBlobAccessConditions; + conditions?: PageBlobRequestConditions; /** * Customer Provided Key Info. * @@ -217,10 +217,10 @@ export interface PageBlobGetPageRangesOptions extends CommonOptions { /** * Conditions to meet when getting page ranges. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof PageBlobGetPageRangesOptions */ - accessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; } /** @@ -241,10 +241,10 @@ export interface PageBlobGetPageRangesDiffOptions extends CommonOptions { /** * Conditions to meet when getting page ranges diff. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof PageBlobGetPageRangesDiffOptions */ - accessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; /** * (unused) * @@ -272,10 +272,10 @@ export interface PageBlobResizeOptions extends CommonOptions { /** * Conditions to meet when resizing a page blob. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof PageBlobResizeOptions */ - accessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; } /** @@ -296,10 +296,10 @@ export interface PageBlobUpdateSequenceNumberOptions extends CommonOptions { /** * Conditions to meet when updating sequence number. * - * @type {BlobAccessConditions} + * @type {BlobRequestConditions} * @memberof PageBlobUpdateSequenceNumberOptions */ - accessConditions?: BlobAccessConditions; + conditions?: BlobRequestConditions; } /** @@ -323,7 +323,7 @@ export interface PageBlobStartCopyIncrementalOptions extends CommonOptions { * @type {ModifiedAccessConditions} * @memberof PageBlobStartCopyIncrementalOptions */ - modifiedAccessConditions?: ModifiedAccessConditions; + conditions?: ModifiedAccessConditions; } export interface PageBlobUploadPagesFromURLOptions extends CommonOptions { @@ -338,17 +338,17 @@ export interface PageBlobUploadPagesFromURLOptions extends CommonOptions { /** * Conditions to meet when updating sequence number. * - * @type {PageBlobAccessConditions} + * @type {PageBlobRequestConditions} * @memberof PageBlobUploadPagesFromURLOptions */ - accessConditions?: PageBlobAccessConditions; + conditions?: PageBlobRequestConditions; /** * Conditions to meet for the source Azure Blob/File when copying from a URL to the blob. * * @type {ModifiedAccessConditions} * @memberof PageBlobUploadPagesFromURLOptions */ - sourceModifiedAccessConditions?: ModifiedAccessConditions; + sourceConditions?: ModifiedAccessConditions; /** * An MD5 hash of the content from the URI. * This hash is used to verify the integrity of the content during transport of the data from the URI. @@ -571,7 +571,7 @@ export class PageBlobClient extends BlobClient { size: number, options: PageBlobCreateOptions = {} ): Promise { - options.accessConditions = options.accessConditions || {}; + options.conditions = options.conditions || {}; const { span, spanOptions } = createSpan("PageBlobClient-create", options.spanOptions); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); @@ -579,9 +579,9 @@ export class PageBlobClient extends BlobClient { abortSignal: options.abortSignal, blobHTTPHeaders: options.blobHTTPHeaders, blobSequenceNumber: options.blobSequenceNumber, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, + leaseAccessConditions: options.conditions, metadata: options.metadata, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, cpkInfo: options.customerProvidedKey, tier: toAccessTier(options.tier), spanOptions @@ -614,17 +614,17 @@ export class PageBlobClient extends BlobClient { count: number, options: PageBlobUploadPagesOptions = {} ): Promise { - options.accessConditions = options.accessConditions || {}; + options.conditions = options.conditions || {}; const { span, spanOptions } = createSpan("PageBlobClient-uploadPages", options.spanOptions); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return this.pageBlobContext.uploadPages(body, count, { abortSignal: options.abortSignal, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, onUploadProgress: options.onProgress, range: rangeToString({ offset, count }), - sequenceNumberAccessConditions: options.accessConditions.sequenceNumberAccessConditions, + sequenceNumberAccessConditions: options.conditions, transactionalContentMD5: options.transactionalContentMD5, transactionalContentCrc64: options.transactionalContentCrc64, cpkInfo: options.customerProvidedKey, @@ -661,8 +661,8 @@ export class PageBlobClient extends BlobClient { count: number, options: PageBlobUploadPagesFromURLOptions = {} ): Promise { - options.accessConditions = options.accessConditions || {}; - options.sourceModifiedAccessConditions = options.sourceModifiedAccessConditions || {}; + options.conditions = options.conditions || {}; + options.sourceConditions = options.sourceConditions || {}; const { span, spanOptions } = createSpan( "PageBlobClient-uploadPagesFromURL", options.spanOptions @@ -678,14 +678,14 @@ export class PageBlobClient extends BlobClient { abortSignal: options.abortSignal, sourceContentMD5: options.sourceContentMD5, sourceContentCrc64: options.sourceContentCrc64, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, - sequenceNumberAccessConditions: options.accessConditions.sequenceNumberAccessConditions, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + sequenceNumberAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, sourceModifiedAccessConditions: { - sourceIfMatch: options.sourceModifiedAccessConditions.ifMatch, - sourceIfModifiedSince: options.sourceModifiedAccessConditions.ifModifiedSince, - sourceIfNoneMatch: options.sourceModifiedAccessConditions.ifNoneMatch, - sourceIfUnmodifiedSince: options.sourceModifiedAccessConditions.ifUnmodifiedSince + sourceIfMatch: options.sourceConditions.ifMatch, + sourceIfModifiedSince: options.sourceConditions.ifModifiedSince, + sourceIfNoneMatch: options.sourceConditions.ifNoneMatch, + sourceIfUnmodifiedSince: options.sourceConditions.ifUnmodifiedSince }, cpkInfo: options.customerProvidedKey, spanOptions @@ -717,15 +717,15 @@ export class PageBlobClient extends BlobClient { count?: number, options: PageBlobClearPagesOptions = {} ): Promise { - options.accessConditions = options.accessConditions || {}; + options.conditions = options.conditions || {}; const { span, spanOptions } = createSpan("PageBlobClient-clearPages", options.spanOptions); try { return this.pageBlobContext.clearPages(0, { abortSignal: options.abortSignal, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, range: rangeToString({ offset, count }), - sequenceNumberAccessConditions: options.accessConditions.sequenceNumberAccessConditions, + sequenceNumberAccessConditions: options.conditions, cpkInfo: options.customerProvidedKey, spanOptions }); @@ -755,14 +755,14 @@ export class PageBlobClient extends BlobClient { count?: number, options: PageBlobGetPageRangesOptions = {} ): Promise { - options.accessConditions = options.accessConditions || {}; + options.conditions = options.conditions || {}; const { span, spanOptions } = createSpan("PageBlobClient-getPageRanges", options.spanOptions); try { return this.pageBlobContext .getPageRanges({ abortSignal: options.abortSignal, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, range: rangeToString({ offset, count }), spanOptions }) @@ -795,7 +795,7 @@ export class PageBlobClient extends BlobClient { prevSnapshot: string, options: PageBlobGetPageRangesDiffOptions = {} ): Promise { - options.accessConditions = options.accessConditions || {}; + options.conditions = options.conditions || {}; const { span, spanOptions } = createSpan( "PageBlobClient-getPageRangesDiff", options.spanOptions @@ -804,8 +804,8 @@ export class PageBlobClient extends BlobClient { return this.pageBlobContext .getPageRangesDiff({ abortSignal: options.abortSignal, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, prevsnapshot: prevSnapshot, range: rangeToString({ offset, count }), spanOptions @@ -835,13 +835,13 @@ export class PageBlobClient extends BlobClient { size: number, options: PageBlobResizeOptions = {} ): Promise { - options.accessConditions = options.accessConditions || {}; + options.conditions = options.conditions || {}; const { span, spanOptions } = createSpan("PageBlobClient-resize", options.spanOptions); try { return this.pageBlobContext.resize(size, { abortSignal: options.abortSignal, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, spanOptions }); } catch (e) { @@ -870,7 +870,7 @@ export class PageBlobClient extends BlobClient { sequenceNumber?: number, options: PageBlobUpdateSequenceNumberOptions = {} ): Promise { - options.accessConditions = options.accessConditions || {}; + options.conditions = options.conditions || {}; const { span, spanOptions } = createSpan( "PageBlobClient-updateSequenceNumber", options.spanOptions @@ -879,8 +879,8 @@ export class PageBlobClient extends BlobClient { return this.pageBlobContext.updateSequenceNumber(sequenceNumberAction, { abortSignal: options.abortSignal, blobSequenceNumber: sequenceNumber, - leaseAccessConditions: options.accessConditions.leaseAccessConditions, - modifiedAccessConditions: options.accessConditions.modifiedAccessConditions, + leaseAccessConditions: options.conditions, + modifiedAccessConditions: options.conditions, spanOptions }); } catch (e) { @@ -919,7 +919,7 @@ export class PageBlobClient extends BlobClient { try { return this.pageBlobContext.copyIncremental(copySource, { abortSignal: options.abortSignal, - modifiedAccessConditions: options.modifiedAccessConditions, + modifiedAccessConditions: options.conditions, spanOptions }); } catch (e) { diff --git a/sdk/storage/storage-blob/src/models.ts b/sdk/storage/storage-blob/src/models.ts index e310f64be250..7a10c6f7d3d2 100644 --- a/sdk/storage/storage-blob/src/models.ts +++ b/sdk/storage/storage-blob/src/models.ts @@ -15,23 +15,15 @@ export interface Metadata { [propertyName: string]: string; } -export interface ContainerAccessConditions { - modifiedAccessConditions?: ModifiedAccessConditions; - leaseAccessConditions?: LeaseAccessConditions; -} +export interface BlobRequestConditions extends ModifiedAccessConditions, LeaseAccessConditions {} -export interface BlobAccessConditions { - modifiedAccessConditions?: ModifiedAccessConditions; - leaseAccessConditions?: LeaseAccessConditions; -} +export interface PageBlobRequestConditions + extends BlobRequestConditions, + SequenceNumberAccessConditions {} -export interface PageBlobAccessConditions extends BlobAccessConditions { - sequenceNumberAccessConditions?: SequenceNumberAccessConditions; -} - -export interface AppendBlobAccessConditions extends BlobAccessConditions { - appendPositionAccessConditions?: AppendPositionAccessConditions; -} +export interface AppendBlobRequestConditions + extends BlobRequestConditions, + AppendPositionAccessConditions {} export enum BlockBlobTier { Hot = "Hot", diff --git a/sdk/storage/storage-blob/test/blobbatch.spec.ts b/sdk/storage/storage-blob/test/blobbatch.spec.ts index 1015885e2e4d..0ab0b673c1cd 100644 --- a/sdk/storage/storage-blob/test/blobbatch.spec.ts +++ b/sdk/storage/storage-blob/test/blobbatch.spec.ts @@ -1,6 +1,11 @@ import * as assert from "assert"; import * as dotenv from "dotenv"; -import { getGenericBSU, getGenericCredential, getTokenCredential, SimpleTokenCredential } from "./utils"; +import { + getGenericBSU, + getGenericCredential, + getTokenCredential, + SimpleTokenCredential +} from "./utils"; import { record } from "./utils/recorder"; import { BatchDeleteRequest, BatchSetTierRequest } from "../src/BatchRequest"; import { ContainerClient, BlockBlobClient, BlobServiceClient, newPipeline } from "../src"; @@ -197,17 +202,13 @@ describe("BlobBatch", () => { // Assemble batch delete request. let batchDeleteRequest = new BatchDeleteRequest(); await batchDeleteRequest.addSubRequest(blockBlobURLs[0], { - blobAccessConditions: { - modifiedAccessConditions: { - ifMatch: b0.eTag - } + conditions: { + ifMatch: b0.eTag } }); await batchDeleteRequest.addSubRequest(blockBlobURLs[1], { - blobAccessConditions: { - modifiedAccessConditions: { - ifNoneMatch: b1.eTag - } + conditions: { + ifNoneMatch: b1.eTag } }); @@ -276,7 +277,7 @@ describe("BlobBatch", () => { let batchSetTierRequest = new BatchSetTierRequest(); await batchSetTierRequest.addSubRequest(blockBlobURLs[0], "Cool"); await batchSetTierRequest.addSubRequest(blockBlobURLs[1], "Cool", { - leaseAccessConditions: { leaseId: leaseResp.leaseId! } + conditions: { leaseId: leaseResp.leaseId! } }); // Submit batch request and verify response. diff --git a/sdk/storage/storage-blob/test/node/highlevel.node.spec.ts b/sdk/storage/storage-blob/test/node/highlevel.node.spec.ts index 75804036be9f..9b01f941bc6e 100644 --- a/sdk/storage/storage-blob/test/node/highlevel.node.spec.ts +++ b/sdk/storage/storage-blob/test/node/highlevel.node.spec.ts @@ -335,10 +335,8 @@ describe("Highlevel", () => { let retirableReadableStreamOptions: RetriableReadableStreamOptions; const downloadResponse = await blockBlobClient.download(0, undefined, { - blobAccessConditions: { - modifiedAccessConditions: { - ifMatch: uploadResponse.eTag - } + conditions: { + ifMatch: uploadResponse.eTag }, maxRetryRequests: 1, onProgress: (ev) => { @@ -369,10 +367,8 @@ describe("Highlevel", () => { let retirableReadableStreamOptions: RetriableReadableStreamOptions; let injectedErrors = 0; const downloadResponse = await blockBlobClient.download(0, undefined, { - blobAccessConditions: { - modifiedAccessConditions: { - ifMatch: uploadResponse.eTag - } + conditions: { + ifMatch: uploadResponse.eTag }, maxRetryRequests: 3, onProgress: () => { @@ -405,10 +401,8 @@ describe("Highlevel", () => { let retirableReadableStreamOptions: RetriableReadableStreamOptions; let injectedErrors = 0; const downloadResponse = await blockBlobClient.download(0, partialSize, { - blobAccessConditions: { - modifiedAccessConditions: { - ifMatch: uploadResponse.eTag - } + conditions: { + ifMatch: uploadResponse.eTag }, maxRetryRequests: 3, onProgress: () => { @@ -444,10 +438,8 @@ describe("Highlevel", () => { try { const downloadResponse = await blockBlobClient.download(0, undefined, { - blobAccessConditions: { - modifiedAccessConditions: { - ifMatch: uploadResponse.eTag - } + conditions: { + ifMatch: uploadResponse.eTag }, maxRetryRequests: 0, onProgress: () => { @@ -482,10 +474,8 @@ describe("Highlevel", () => { const aborter = new AbortController(); const downloadResponse = await blockBlobClient.download(0, undefined, { abortSignal: aborter.signal, - blobAccessConditions: { - modifiedAccessConditions: { - ifMatch: uploadResponse.eTag - } + conditions: { + ifMatch: uploadResponse.eTag }, maxRetryRequests: 3, onProgress: () => {