Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage/sas improvement #12850

Merged
merged 6 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/storage/storage-blob/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 12.4.0-beta.2 (Unreleased)

- Added a new `from(permissionLike)` function to `AccountSASPermissions`, `BlobSASPermissions` and `ContainerSASPermissions` for creating such a permission from a raw permission-like object. Addressed issue [9714](https://github.com/Azure/azure-sdk-for-js/issues/9714).

## 12.4.0-beta.1 (2020-12-09)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions sdk/storage/storage-blob/review/storage-blob.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class AccountSASPermissions {
delete: boolean;
deleteVersion: boolean;
filter: boolean;
static from(permissionLike: AccountSASPermissionsLike): AccountSASPermissions;
list: boolean;
static parse(permissions: string): AccountSASPermissions;
process: boolean;
Expand All @@ -60,6 +61,21 @@ export class AccountSASPermissions {
write: boolean;
}

// @public
export interface AccountSASPermissionsLike {
add?: boolean;
create?: boolean;
delete?: boolean;
deleteVersion?: boolean;
filter?: boolean;
list?: boolean;
process?: boolean;
read?: boolean;
tag?: boolean;
update?: boolean;
write?: boolean;
}

// @public
export class AccountSASResourceTypes {
container: boolean;
Expand Down Expand Up @@ -1006,6 +1022,7 @@ export class BlobSASPermissions {
delete: boolean;
deleteVersion: boolean;
execute: boolean;
static from(permissionLike: BlobSASPermissionsLike): BlobSASPermissions;
move: boolean;
static parse(permissions: string): BlobSASPermissions;
read: boolean;
Expand All @@ -1014,6 +1031,19 @@ export class BlobSASPermissions {
write: boolean;
}

// @public
export interface BlobSASPermissionsLike {
add?: boolean;
create?: boolean;
delete?: boolean;
deleteVersion?: boolean;
execute?: boolean;
move?: boolean;
read?: boolean;
tag?: boolean;
write?: boolean;
}

// @public
export interface BlobSASSignatureValues {
blobName?: string;
Expand Down Expand Up @@ -1916,6 +1946,7 @@ export class ContainerSASPermissions {
delete: boolean;
deleteVersion: boolean;
execute: boolean;
static from(permissionLike: ContainerSASPermissionsLike): ContainerSASPermissions;
list: boolean;
move: boolean;
static parse(permissions: string): ContainerSASPermissions;
Expand All @@ -1925,6 +1956,20 @@ export class ContainerSASPermissions {
write: boolean;
}

// @public
export interface ContainerSASPermissionsLike {
add?: boolean;
create?: boolean;
delete?: boolean;
deleteVersion?: boolean;
execute?: boolean;
list?: boolean;
move?: boolean;
read?: boolean;
tag?: boolean;
write?: boolean;
}

// @public
export interface ContainerSetAccessPolicyHeaders {
clientRequestId?: string;
Expand Down
141 changes: 141 additions & 0 deletions sdk/storage/storage-blob/src/sas/AccountSASPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,53 @@ export class AccountSASPermissions {
return accountSASPermissions;
}

/**
* Creates a {@link AccountSASPermissions} from a raw object which contains same keys as it
* and boolean values for them.
*
* @static
* @param {AccountSASPermissionsLike} permissionLike
* @returns {AccountSASPermissions}
* @memberof AccountSASPermissions
*/
public static from(permissionLike: AccountSASPermissionsLike): AccountSASPermissions {
const accountSASPermissions = new AccountSASPermissions();
if (permissionLike.read) {
accountSASPermissions.read = true;
}
if (permissionLike.write) {
accountSASPermissions.write = true;
}
if (permissionLike.delete) {
accountSASPermissions.delete = true;
}
if (permissionLike.deleteVersion) {
accountSASPermissions.deleteVersion = true;
}
if (permissionLike.filter) {
accountSASPermissions.filter = true;
}
if (permissionLike.tag) {
accountSASPermissions.tag = true;
}
if (permissionLike.list) {
accountSASPermissions.list = true;
}
if (permissionLike.add) {
accountSASPermissions.add = true;
}
if (permissionLike.create) {
accountSASPermissions.create = true;
}
if (permissionLike.update) {
accountSASPermissions.update = true;
}
if (permissionLike.process) {
accountSASPermissions.process = true;
}
return accountSASPermissions;
}

/**
* Permission to read resources and list queues and tables granted.
*
Expand Down Expand Up @@ -209,3 +256,97 @@ export class AccountSASPermissions {
return permissions.join("");
}
}

/**
* A type that looks like an account SAS permission.
* Used in {@link AccountSASPermissions} to parse SAS permissions from raw objects.
*/
export interface AccountSASPermissionsLike {
/**
* Permission to read resources and list queues and tables granted.
*
* @type {boolean}
* @memberof AccountSASPermissionsLike
*/
read?: boolean;

/**
* Permission to write resources granted.
*
* @type {boolean}
* @memberof AccountSASPermissionsLike
*/
write?: boolean;

/**
* Permission to create blobs and files granted.
*
* @type {boolean}
* @memberof AccountSASPermissionsLike
*/
delete?: boolean;

/**
* Permission to delete versions granted.
*
* @type {boolean}
* @memberof AccountSASPermissionsLike
*/
deleteVersion?: boolean;

/**
* Permission to list blob containers, blobs, shares, directories, and files granted.
*
* @type {boolean}
* @memberof AccountSASPermissionsLike
*/
list?: boolean;

/**
* Permission to add messages, table entities, and append to blobs granted.
*
* @type {boolean}
* @memberof AccountSASPermissionsLike
*/
add?: boolean;

/**
* Permission to create blobs and files granted.
*
* @type {boolean}
* @memberof AccountSASPermissionsLike
*/
create?: boolean;

/**
* Permissions to update messages and table entities granted.
*
* @type {boolean}
* @memberof AccountSASPermissionsLike
*/
update?: boolean;

/**
* Permission to get and delete messages granted.
*
* @type {boolean}
* @memberof AccountSASPermissionsLike
*/
process?: boolean;

/**
* Specfies Tag access granted.
*
* @type {boolean}
* @memberof AccountSASPermissionsLike
*/
tag?: boolean;

/**
* Permission to filter blobs.
*
* @type {boolean}
* @memberof AccountSASPermissionsLike
*/
filter?: boolean;
}
119 changes: 119 additions & 0 deletions sdk/storage/storage-blob/src/sas/BlobSASPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,47 @@ export class BlobSASPermissions {
return blobSASPermissions;
}

/**
* Creates a {@link BlobSASPermissions} from a raw object which contains same keys as it
* and boolean values for them.
*
* @static
* @param {BlobSASPermissionsLike} permissionLike
* @returns {BlobSASPermissions}
* @memberof BlobSASPermissions
*/
public static from(permissionLike: BlobSASPermissionsLike): BlobSASPermissions {
const blobSASPermissions = new BlobSASPermissions();
if (permissionLike.read) {
blobSASPermissions.read = true;
}
if (permissionLike.add) {
blobSASPermissions.add = true;
}
if (permissionLike.create) {
blobSASPermissions.create = true;
}
if (permissionLike.write) {
blobSASPermissions.write = true;
}
if (permissionLike.delete) {
blobSASPermissions.delete = true;
}
if (permissionLike.deleteVersion) {
blobSASPermissions.deleteVersion = true;
}
if (permissionLike.tag) {
blobSASPermissions.tag = true;
}
if (permissionLike.move) {
blobSASPermissions.move = true;
}
if (permissionLike.execute) {
blobSASPermissions.execute = true;
}
return blobSASPermissions;
}

/**
* Specifies Read access granted.
*
Expand Down Expand Up @@ -174,3 +215,81 @@ export class BlobSASPermissions {
return permissions.join("");
}
}

/**
* A type that looks like a Blob SAS permission.
* Used in {@link BlobSASPermissions} to parse SAS permissions from raw objects.
*/
export interface BlobSASPermissionsLike {
/**
* Specifies Read access granted.
*
* @type {boolean}
* @memberof BlobSASPermissionsLike
*/
read?: boolean;

/**
* Specifies Add access granted.
*
* @type {boolean}
* @memberof BlobSASPermissionsLike
*/
add?: boolean;

/**
* Specifies Create access granted.
*
* @type {boolean}
* @memberof BlobSASPermissionsLike
*/
create?: boolean;

/**
* Specifies Write access granted.
*
* @type {boolean}
* @memberof BlobSASPermissionsLike
*/
write?: boolean;

/**
* Specifies Delete access granted.
*
* @type {boolean}
* @memberof BlobSASPermissionsLike
*/
delete?: boolean;

/**
* Specifies Delete version access granted.
*
* @type {boolean}
* @memberof BlobSASPermissionsLike
*/
deleteVersion?: boolean;

/**
* Specfies Tag access granted.
*
* @type {boolean}
* @memberof BlobSASPermissionsLike
*/
tag?: boolean;

/**
* Specifies Move access granted.
*
* @type {boolean}
* @memberof BlobSASPermissionsLike
*/
move?: boolean;

/**
* Specifies Execute access granted.
*
* @type {boolean}
* @memberof BlobSASPermissionsLike
*/
execute?: boolean;
}
Loading