Skip to content

Commit 70e4e12

Browse files
committed
feat: add sync mode
Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>
1 parent 523ce85 commit 70e4e12

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/syncedEnforcer.ts

+23
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import { Enforcer, newEnforcerWithClass } from './enforcer';
1616
import AwaitLock from 'await-lock';
1717
import { Watcher } from './persist';
18+
import { MatchingFunc } from './rbac';
1819

1920
// SyncedEnforcer wraps Enforcer and provides synchronized access
2021
export class SyncedEnforcer extends Enforcer {
@@ -477,6 +478,28 @@ export class SyncedEnforcer extends Enforcer {
477478
await this.lock.acquireAsync();
478479
return super.removeFilteredNamedGroupingPolicy(ptype, fieldIndex, ...fieldValues).finally(() => this.lock.release());
479480
}
481+
482+
/**
483+
* add matching function to RoleManager by ptype
484+
* @param ptype g
485+
* @param fn the function will be added
486+
*/
487+
public async addNamedMatchingFunc(ptype: string, fn: MatchingFunc): Promise<void> {
488+
await this.lock.acquireAsync();
489+
return super.addNamedMatchingFunc(ptype, fn).finally(() => this.lock.release());
490+
}
491+
492+
/**
493+
* add domain matching function to RoleManager by ptype
494+
* @param ptype g
495+
* @param fn the function will be added
496+
*/
497+
public async addNamedDomainMatchingFunc(ptype: string, fn: MatchingFunc): Promise<void> {
498+
await this.lock.acquireAsync();
499+
return super.addNamedDomainMatchingFunc(ptype, fn).finally(() => {
500+
this.lock.release();
501+
});
502+
}
480503
}
481504

482505
// newSyncedEnforcer creates a synchronized enforcer via file or DB.

0 commit comments

Comments
 (0)