@azure/data-tables
Version:
An isomorphic client library for the Azure Tables service.
41 lines • 1.85 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateTableSas = generateTableSas;
const core_auth_1 = require("@azure/core-auth");
const tableSasSignatureValues_js_1 = require("./tableSasSignatureValues.js");
const tableSasPermisions_js_1 = require("./tableSasPermisions.js");
/**
* Generates a Table Service Shared Access Signature (SAS) URI based on the client properties
* and parameters passed in. The SAS is signed by the shared key credential of the client.
*
* @see https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas
*
* @param options - Optional parameters.
* @returns The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.
*/
function generateTableSas(tableName, credential, options = {}) {
let { expiresOn, permissions } = options;
if (!(0, core_auth_1.isNamedKeyCredential)(credential)) {
throw RangeError("Can only generate the account SAS when the client is initialized with a shared key credential");
}
// expiresOn and permissions are optional if an identifier is provided
// set defaults when no identifier and no values were provided
if (!options.identifier) {
if (!permissions) {
permissions = (0, tableSasPermisions_js_1.tableSasPermissionsFromString)("r");
}
if (expiresOn === undefined) {
const now = new Date();
expiresOn = new Date(now.getTime() + 3600 * 1000);
}
}
const sas = (0, tableSasSignatureValues_js_1.generateTableSasQueryParameters)(tableName, credential, {
...options,
expiresOn,
permissions,
}).toString();
return sas;
}
//# sourceMappingURL=generateTableSas.js.map