UNPKG

azurite

Version:

An open source Azure Storage API compatible server

121 lines 4.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AccountSASService = void 0; var AccountSASService; (function (AccountSASService) { AccountSASService["Blob"] = "b"; AccountSASService["File"] = "f"; AccountSASService["Queue"] = "q"; AccountSASService["Table"] = "t"; })(AccountSASService || (exports.AccountSASService = AccountSASService = {})); /** * ONLY AVAILABLE IN NODE.JS RUNTIME. * * This is a helper class to construct a string representing the services accessible by an AccountSAS. Setting a value * to true means that any SAS which uses these permissions will grant access to that service. Once all the * values are set, this should be serialized with toString and set as the services field on an * {@link AccountSASSignatureValues} object. It is possible to construct the services string without this class, but * the order of the services is particular and this class guarantees correctness. * * @export * @class AccountSASServices */ class AccountSASServices { constructor() { /** * Permission to access blob resources granted. * * @type {boolean} * @memberof AccountSASServices */ this.blob = false; /** * Permission to access file resources granted. * * @type {boolean} * @memberof AccountSASServices */ this.file = false; /** * Permission to access queue resources granted. * * @type {boolean} * @memberof AccountSASServices */ this.queue = false; /** * Permission to access table resources granted. * * @type {boolean} * @memberof AccountSASServices */ this.table = false; } /** * Creates an {@link AccountSASServices} from the specified services string. This method will throw an * Error if it encounters a character that does not correspond to a valid service. * * @static * @param {string} services * @returns {AccountSASServices} * @memberof AccountSASServices */ static parse(services) { const accountSASServices = new AccountSASServices(); for (const c of services) { switch (c) { case AccountSASService.Blob: if (accountSASServices.blob) { throw new RangeError(`Duplicated permission character: ${c}`); } accountSASServices.blob = true; break; case AccountSASService.File: if (accountSASServices.file) { throw new RangeError(`Duplicated permission character: ${c}`); } accountSASServices.file = true; break; case AccountSASService.Queue: if (accountSASServices.queue) { throw new RangeError(`Duplicated permission character: ${c}`); } accountSASServices.queue = true; break; case AccountSASService.Table: if (accountSASServices.table) { throw new RangeError(`Duplicated permission character: ${c}`); } accountSASServices.table = true; break; default: throw new RangeError(`Invalid service character: ${c}`); } } return accountSASServices; } /** * Converts the given services to a string. * * @returns {string} * @memberof AccountSASServices */ toString() { const services = []; if (this.blob) { services.push(AccountSASService.Blob); } if (this.table) { services.push(AccountSASService.Table); } if (this.queue) { services.push(AccountSASService.Queue); } if (this.file) { services.push(AccountSASService.File); } return services.join(""); } } exports.default = AccountSASServices; //# sourceMappingURL=AccountSASServices.js.map