Skip to content

Commit

Permalink
[Storage][Blob] Flatten and simplify access conditions
Browse files Browse the repository at this point in the history
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
}
```
  • Loading branch information
jeremymeng committed Oct 20, 2019
1 parent 7da8d54 commit 862f930
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 293 deletions.
50 changes: 25 additions & 25 deletions sdk/storage/storage-blob/src/AppendBlobClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,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";
Expand Down Expand Up @@ -50,10 +50,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.
*
Expand Down Expand Up @@ -95,10 +95,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.
*
Expand Down Expand Up @@ -146,17 +146,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 {Models.ModifiedAccessConditions}
* @memberof AppendBlobAppendBlockFromURLOptions
*/
sourceModifiedAccessConditions?: Models.ModifiedAccessConditions;
sourceConditions?: Models.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.
Expand Down Expand Up @@ -386,16 +386,16 @@ export class AppendBlobClient extends BlobClient {
options: AppendBlobCreateOptions = {}
): Promise<Models.AppendBlobCreateResponse> {
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
});
Expand Down Expand Up @@ -426,15 +426,15 @@ export class AppendBlobClient extends BlobClient {
options: AppendBlobAppendBlockOptions = {}
): Promise<Models.AppendBlobAppendBlockResponse> {
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,
Expand Down Expand Up @@ -478,8 +478,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);

Expand All @@ -488,14 +488,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
Expand Down
Loading

0 comments on commit 862f930

Please sign in to comment.