Skip to content

Commit

Permalink
feat: avoid miss initialize()
Browse files Browse the repository at this point in the history
  • Loading branch information
nodece committed Apr 30, 2020
1 parent b2b960f commit 1394e8d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
32 changes: 9 additions & 23 deletions src/coreEnforcer.ts
Expand Up @@ -27,30 +27,18 @@ import { getLogger, logPrint } from './log';
export class CoreEnforcer {
protected modelPath: string;
protected model: Model;
protected fm: FunctionMap;
private eft: Effector;
private matcherMap: Map<string, ((context: object) => Promise<any>) | ((context: object) => any)>;
protected fm: FunctionMap = FunctionMap.loadFunctionMap();
protected eft: Effector = new DefaultEffector();
private matcherMap: Map<string, ((context: object) => Promise<any>) | ((context: object) => any)> = new Map();

protected adapter: FilteredAdapter | Adapter;
protected watcher: Watcher | null = null;
protected rm: RoleManager;

private enabled: boolean;
protected autoSave: boolean;
protected autoBuildRoleLinks: boolean;
protected autoNotifyWatcher: boolean;

public initialize(): void {
this.rm = new DefaultRoleManager(10);
this.eft = new DefaultEffector();
this.matcherMap = new Map();
this.watcher = null;

this.enabled = true;
this.autoSave = true;
this.autoBuildRoleLinks = true;
this.autoNotifyWatcher = true;
}
protected rm: RoleManager = new DefaultRoleManager(10);

protected enabled = true;
protected autoSave = true;
protected autoBuildRoleLinks = true;
protected autoNotifyWatcher = true;

/**
* loadModel reloads the model from the model CONF file.
Expand All @@ -61,7 +49,6 @@ export class CoreEnforcer {
this.model = newModel();
this.model.loadModel(this.modelPath);
this.model.printModel();
this.fm = FunctionMap.loadFunctionMap();
}

/**
Expand All @@ -80,7 +67,6 @@ export class CoreEnforcer {
*/
public setModel(m: Model): void {
this.model = m;
this.fm = FunctionMap.loadFunctionMap();
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/enforcer.ts
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { ManagementEnforcer } from './managementEnforcer';
import { FunctionMap, Model, newModel } from './model';
import { Model, newModel } from './model';
import { Adapter, FileAdapter, StringAdapter } from './persist';
import { getLogger } from './log';

Expand Down Expand Up @@ -65,12 +65,8 @@ export class Enforcer extends ManagementEnforcer {

this.model = m;
this.model.printModel();
this.fm = FunctionMap.loadFunctionMap();

this.initialize();

if (this.adapter) {
// error intentionally ignored
await this.loadPolicy();
}
}
Expand Down
1 change: 0 additions & 1 deletion test/model.test.ts
Expand Up @@ -99,7 +99,6 @@ test('TestBasicModelWithoutUsers', async () => {

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

await testEnforceWithoutUsers(e, 'alice', 'read', true);
await testEnforceWithoutUsers(e, 'alice', 'write', false);
Expand Down

0 comments on commit 1394e8d

Please sign in to comment.