azure-sdk-for-js
azure-sdk-for-js copied to clipboard
Blob Storage reference docs - request SAS 1:1 with .NET
Is it possible with the existing Blob Storage SDK v12 for JS to have an equivalent of this .NET code? I can't see it in the ref docs or the samples in this SDK repo.
.NET SDK code
sasBuilder.ExpiresOn = DateTimeOffset.UtcNow.AddHours(1);
sasBuilder.SetPermissions(DataLakeSasPermissions.Read | DataLakeSasPermissions.Write |DataLakeSasPermissions.List);
This is the code I have with permissions as a string in JS but I would like to use something from the SDK without a string.
JS SDK code
async function createAccountSas() {
const sasOptions = {
services: AccountSASServices.parse("btqf").toString(), // REMOVE this string to enum or something else
resourceTypes: AccountSASResourceTypes.parse("sco").toString(), // REMOVE this string to enum or something else
permissions: AccountSASPermissions.parse("rwdlacupi"), // REMOVE this string to enum or something else
protocol: SASProtocol.Https,
startsOn: new Date(),
expiresOn: new Date(new Date().valueOf() + (10 * 60 * 1000)), // 10 minutes
};
const sasToken = generateAccountSASQueryParameters(
sasOptions,
sharedKeyCredential
).toString();
console.log(`sasToken = '${sasToken}'\n`);
// prepend sasToken with `?`
return (sasToken[0] === '?') ? sasToken : `?${sasToken}`;
}
I'm not a storage expert, but it looks like the generateAccountSasUrl
method on BlobServiceClient
could make this a little simpler?
Also you should be able to do something like AccountSASPermissions.from({read: true, list: true})
to make the permissions a bit more legible.
@xirzec Can you tag an engineer that might be closer to SAS token generation on JS?
I think @EmmaZhu is the best point of contact for this.
Hi @diberry ,
The permission in JS is defined as a class instead of an enum type, parsing from a string to create a permission object is recommended.
Thanks Emma
@EmmaZhu Are you saying my sample code at the top of this issus is the recommended? If not, can you please provide an example of "a string".
@diberry Yes, we'd recommend to input the permission with code like: permissions: AccountSASPermissions.parse("rwdlacupi")
@diberry , anymore questions, please feel free to active the issue.