verae-nats-accounts/src/policy.js

14 lines
482 B
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const FILE = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'policy.json');
export function loadPolicy() {
return JSON.parse(fs.readFileSync(FILE, 'utf8'));
}
export function leafAllowed(subject) {
const allow = loadPolicy().leafAllow || [];
return allow.some((p) => (p.endsWith('.') ? subject.startsWith(p) : subject === p || subject.startsWith(`${p}.`)));
}