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 3 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

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

22 changes: 22 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: SASPermissionsLike): AccountSASPermissions;
list: boolean;
static parse(permissions: string): AccountSASPermissions;
process: boolean;
Expand Down Expand Up @@ -1006,6 +1007,7 @@ export class BlobSASPermissions {
delete: boolean;
deleteVersion: boolean;
execute: boolean;
static from(permissionLike: SASPermissionsLike): BlobSASPermissions;
move: boolean;
static parse(permissions: string): BlobSASPermissions;
read: boolean;
Expand Down Expand Up @@ -1916,6 +1918,7 @@ export class ContainerSASPermissions {
delete: boolean;
deleteVersion: boolean;
execute: boolean;
static from(permissionLike: SASPermissionsLike): ContainerSASPermissions;
list: boolean;
move: boolean;
static parse(permissions: string): ContainerSASPermissions;
Expand Down Expand Up @@ -2694,6 +2697,25 @@ export interface SasIPRange {
start: string;
}

// @public
export interface SASPermissionsLike {
add?: boolean;
create?: boolean;
delete?: boolean;
deleteVersion?: boolean;
execute?: boolean;
filter?: boolean;
list?: boolean;
manageAccessControl?: boolean;
manageOwnership?: boolean;
move?: boolean;
process?: boolean;
read?: boolean;
tag?: boolean;
update?: boolean;
write?: boolean;
}

// @public
export enum SASProtocol {
Https = "https",
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage/storage-blob/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export {
ContainerRequestConditions,
ModificationConditions,
MatchConditions,
ModifiedAccessConditions
ModifiedAccessConditions,
SASPermissionsLike
} from "./models";
export { RestError };
export {
Expand Down
129 changes: 129 additions & 0 deletions sdk/storage/storage-blob/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,132 @@ export interface BlobQueryArrowField {
*/
scale?: number;
}

/**
* A type that looks like a SAS permission.
* Used in {@link BlobSASPermissions} {@link ContainerSASPermissions} and {@link AccountSASPermissions} to parse SAS permissions from raw objects.
ljian3377 marked this conversation as resolved.
Show resolved Hide resolved
*/
export interface SASPermissionsLike {
/**
* Specifies Read access granted.
*
* @type {boolean}
* @memberof SASPermissionsLike
*/
read?: boolean;

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

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

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

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

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

/**
* Specifies List access granted.
*
* @type {boolean}
* @memberof SASPermissionsLike
*/
list?: boolean;

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

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

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

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

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

/**
* Permission to filter blobs.
*
* @type {boolean}
* @memberof SASPermissionsLike
*/
filter?: boolean;

/**
* Specifies Ownership access granted, which allows the caller to set owner, owning group,
* or act as the owner when renaming or deleting a blob (file or directory) within a folder
* that has the sticky bit set.
*
* @type {boolean}
* @memberof SASPermissionsLike
*/
manageOwnership?: boolean;

/**
* Specifies Permission access granted, which allows the caller to set permissions and
* POSIX ACLs on blobs (files and directories).
*
* @type {boolean}
* @memberof SASPermissionsLike
*/
manageAccessControl?: boolean;
}
49 changes: 49 additions & 0 deletions sdk/storage/storage-blob/src/sas/AccountSASPermissions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { SASPermissionsLike } from "../models";

/**
* ONLY AVAILABLE IN NODE.JS RUNTIME.
*
Expand Down Expand Up @@ -68,6 +70,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 {SASPermissionsLike} permissionLike
* @returns {AccountSASPermissions}
* @memberof AccountSASPermissions
*/
public static from(permissionLike: SASPermissionsLike): AccountSASPermissions {
ljian3377 marked this conversation as resolved.
Show resolved Hide resolved
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
42 changes: 42 additions & 0 deletions sdk/storage/storage-blob/src/sas/BlobSASPermissions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { SASPermissionsLike } from "../models";
/**
* ONLY AVAILABLE IN NODE.JS RUNTIME.
*
Expand Down Expand Up @@ -63,6 +64,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 {SASPermissionsLike} permissionLike
* @returns {BlobSASPermissions}
* @memberof BlobSASPermissions
*/
public static from(permissionLike: SASPermissionsLike): 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
6 changes: 2 additions & 4 deletions sdk/storage/storage-blob/src/sas/BlobSASSignatureValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ function generateBlobSASQueryParameters20150405(

if (
!blobSASSignatureValues.identifier &&
!blobSASSignatureValues.permissions &&
!blobSASSignatureValues.expiresOn
!(blobSASSignatureValues.permissions && blobSASSignatureValues.expiresOn)
) {
throw new RangeError(
"Must provide 'permissions' and 'expiresOn' for Blob SAS generation when 'identifier' is not provided."
Expand Down Expand Up @@ -483,8 +482,7 @@ function generateBlobSASQueryParameters20181109(

if (
!blobSASSignatureValues.identifier &&
!blobSASSignatureValues.permissions &&
!blobSASSignatureValues.expiresOn
!(blobSASSignatureValues.permissions && blobSASSignatureValues.expiresOn)
) {
throw new RangeError(
"Must provide 'permissions' and 'expiresOn' for Blob SAS generation when 'identifier' is not provided."
Expand Down
46 changes: 46 additions & 0 deletions sdk/storage/storage-blob/src/sas/ContainerSASPermissions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { SASPermissionsLike } from "../models";

/**
* This is a helper class to construct a string representing the permissions granted by a ServiceSAS to a container.
* Setting a value to true means that any SAS which uses these permissions will grant permissions for that operation.
Expand Down Expand Up @@ -64,6 +66,50 @@ export class ContainerSASPermissions {
return containerSASPermissions;
}

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

/**
* Specifies Read access granted.
*
Expand Down
Loading