Is your feature request related to a problem? Please describe.
Our current solution stores an instance of BlobSasPermissions to CosmosDB in the form of JSON. See an example below:
{
"read": true,
"add": false,
"create": false,
"write": true,
"delete": false
}
The reason this happens is because we store it as part of an object hierarchy that looks like this:
MainRequestObject:
- BlobSasPermissionsObject
We run into an issue when calling generateBlobSASQueryParameters with a re-hydrated version of BlobSasPermissions from this JSON format as it loses it's toString() implementation in the process (and there is no way to instantiate BlobSasPermission from anything other than the simple permission string format eg. 'rwx'). So passing our re-hydrated BlobSasPermissions causes generateBlobSASQueryParameters to throw an Invalid Permissions exception.
Describe the solution you'd like
It would be ideal for us to be able to call generateBlobSASQueryParameters with the following:
const permission = JSON.parse("{
"read": true,
"add": false,
"create": false,
"write": true,
"delete": false
}") as BlobSasPermission;
Or even:
BlobSasPermission.parse(jsonString);
Describe alternatives you've considered
Since we want to retain our database structure (for backwards compatibility), it is not desirable to change how we serialize BlobSasPermission. Right now we just recreate the BlobSasPermission.toString method in our codebase to work with an external object (remember that obj below does not have toString() since it was re-hydrated from JSON):
private getSasPermissionsString (obj: BlobSASPermissions): string {
const permissions: string[] = [];
if (obj.read) {
permissions.push('r');
}
if (obj.add) {
permissions.push('a');
}
if (obj.create) {
permissions.push('c');
}
if (obj.write) {
permissions.push('w');
}
if (obj.delete) {
permissions.push('d');
}
return permissions.join('');
}
Additional context
None.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.
Thanks for feedback. Mark this as feature request and will be triaged in following release schedule.
Probably we should have made the toString() function static.
https://github.com/Azure/azure-sdk-for-js/blob/a5ba0748cc248d1ab724ad76cea5bd65bbd5474d/sdk/storage/storage-blob/src/sas/BlobSASPermissions.ts#L145
Then you would be able to call BlobSASPermissions.toString(permissionLikeObject) to get the permission string, and then call BlobSASPermissions.parse(permissionString) to get an instance of BlobSASPermissions.
from(PermissionLikeObject): BlobSASPermissions
Most helpful comment
Thanks for feedback. Mark this as feature request and will be triaged in following release schedule.