@backstage/backend-defaults
Version:
Backend defaults used by Backstage backend apps
34 lines (30 loc) • 1.14 kB
JavaScript
;
var helpers = require('./helpers.cjs.js');
const MIN_TOKEN_LENGTH = 8;
class StaticTokenHandler {
#entries = /* @__PURE__ */ new Map();
add(config) {
const token = config.getString("options.token");
const subject = config.getString("options.subject");
const allAccessRestrictions = helpers.readAccessRestrictionsFromConfig(config);
if (!token.match(/^\S+$/)) {
throw new Error("Illegal token, must be a set of non-space characters");
} else if (token.length < MIN_TOKEN_LENGTH) {
throw new Error(
`Illegal token, must be at least ${MIN_TOKEN_LENGTH} characters length`
);
} else if (!subject.match(/^\S+$/)) {
throw new Error("Illegal subject, must be a set of non-space characters");
} else if (this.#entries.has(token)) {
throw new Error(
"Static externalAccess token was declared more than once"
);
}
this.#entries.set(token, { subject, allAccessRestrictions });
}
async verifyToken(token) {
return this.#entries.get(token);
}
}
exports.StaticTokenHandler = StaticTokenHandler;
//# sourceMappingURL=static.cjs.js.map