Skip to content

Commit 1394e8d

Browse files
committed
feat: avoid miss initialize()
1 parent b2b960f commit 1394e8d

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

src/coreEnforcer.ts

+9-23
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,18 @@ import { getLogger, logPrint } from './log';
2727
export class CoreEnforcer {
2828
protected modelPath: string;
2929
protected model: Model;
30-
protected fm: FunctionMap;
31-
private eft: Effector;
32-
private matcherMap: Map<string, ((context: object) => Promise<any>) | ((context: object) => any)>;
30+
protected fm: FunctionMap = FunctionMap.loadFunctionMap();
31+
protected eft: Effector = new DefaultEffector();
32+
private matcherMap: Map<string, ((context: object) => Promise<any>) | ((context: object) => any)> = new Map();
3333

3434
protected adapter: FilteredAdapter | Adapter;
3535
protected watcher: Watcher | null = null;
36-
protected rm: RoleManager;
37-
38-
private enabled: boolean;
39-
protected autoSave: boolean;
40-
protected autoBuildRoleLinks: boolean;
41-
protected autoNotifyWatcher: boolean;
42-
43-
public initialize(): void {
44-
this.rm = new DefaultRoleManager(10);
45-
this.eft = new DefaultEffector();
46-
this.matcherMap = new Map();
47-
this.watcher = null;
48-
49-
this.enabled = true;
50-
this.autoSave = true;
51-
this.autoBuildRoleLinks = true;
52-
this.autoNotifyWatcher = true;
53-
}
36+
protected rm: RoleManager = new DefaultRoleManager(10);
37+
38+
protected enabled = true;
39+
protected autoSave = true;
40+
protected autoBuildRoleLinks = true;
41+
protected autoNotifyWatcher = true;
5442

5543
/**
5644
* loadModel reloads the model from the model CONF file.
@@ -61,7 +49,6 @@ export class CoreEnforcer {
6149
this.model = newModel();
6250
this.model.loadModel(this.modelPath);
6351
this.model.printModel();
64-
this.fm = FunctionMap.loadFunctionMap();
6552
}
6653

6754
/**
@@ -80,7 +67,6 @@ export class CoreEnforcer {
8067
*/
8168
public setModel(m: Model): void {
8269
this.model = m;
83-
this.fm = FunctionMap.loadFunctionMap();
8470
}
8571

8672
/**

src/enforcer.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import { ManagementEnforcer } from './managementEnforcer';
16-
import { FunctionMap, Model, newModel } from './model';
16+
import { Model, newModel } from './model';
1717
import { Adapter, FileAdapter, StringAdapter } from './persist';
1818
import { getLogger } from './log';
1919

@@ -65,12 +65,8 @@ export class Enforcer extends ManagementEnforcer {
6565

6666
this.model = m;
6767
this.model.printModel();
68-
this.fm = FunctionMap.loadFunctionMap();
69-
70-
this.initialize();
7168

7269
if (this.adapter) {
73-
// error intentionally ignored
7470
await this.loadPolicy();
7571
}
7672
}

test/model.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ test('TestBasicModelWithoutUsers', async () => {
9999

100100
test('TestBasicModelWithoutResources', async () => {
101101
const e = await newEnforcer('examples/basic_without_resources_model.conf', 'examples/basic_without_resources_policy.csv');
102-
e.initialize();
103102

104103
await testEnforceWithoutUsers(e, 'alice', 'read', true);
105104
await testEnforceWithoutUsers(e, 'alice', 'write', false);

0 commit comments

Comments
 (0)