Initial import of verae-nats-accounts from zapier monorepo
This commit is contained in:
commit
2923ba70e6
7 changed files with 103 additions and 0 deletions
14
src/policy.js
Normal file
14
src/policy.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
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}.`)));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue