Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor BatchFileAdapter #236

Merged
merged 3 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions src/persist/batchFileAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { FileAdapter } from './fileAdapter';
import { BatchAdapter } from './batchAdapter';

/**
* FileAdapter is the file adapter for Casbin.
* It can load policy from file or save policy to file.
* BatchFileAdapter is the file adapter for Casbin.
* It can add policies and remove policies.
* @deprecated The class should not be used, you should use FileAdapter.
*/
export class BatchFileAdapter extends FileAdapter implements BatchAdapter {
/**
Expand All @@ -13,16 +14,4 @@ export class BatchFileAdapter extends FileAdapter implements BatchAdapter {
constructor(filePath: string) {
super(filePath);
}

// addPolicies adds policy rules to the storage.
// This is part of the Auto-Save feature.
public async addPolicies(sec: string, ptype: string, rules: string[][]): Promise<void> {
throw new Error('not implemented');
}

// removePolicies removes policy rules from the storage.
// This is part of the Auto-Save feature.
public async removePolicies(sec: string, ptype: string, rules: string[][]): Promise<void> {
throw new Error('not implemented');
}
}
18 changes: 18 additions & 0 deletions src/persist/fileAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,31 @@ export class FileAdapter implements Adapter {
throw new Error('not implemented');
}

// addPolicies adds policy rules to the storage.
Zxilly marked this conversation as resolved.
Show resolved Hide resolved
// This is part of the Auto-Save feature.
public async addPolicies(sec: string, ptype: string, rules: string[][]): Promise<void> {
throw new Error('not implemented');
}

// UpdatePolicy updates a policy rule from storage.
Zxilly marked this conversation as resolved.
Show resolved Hide resolved
// This is part of the Auto-Save feature.
updatePolicy(sec: string, ptype: string, oldRule: string[], newRule: string[]): Promise<void> {
throw new Error('not implemented');
}

/**
* removePolicy removes a policy rule from the storage.
*/
public async removePolicy(sec: string, ptype: string, rule: string[]): Promise<void> {
throw new Error('not implemented');
}

// removePolicies removes policy rules from the storage.
Zxilly marked this conversation as resolved.
Show resolved Hide resolved
// This is part of the Auto-Save feature.
public async removePolicies(sec: string, ptype: string, rules: string[][]): Promise<void> {
throw new Error('not implemented');
}

/**
* removeFilteredPolicy removes policy rules that match the filter from the storage.
*/
Expand Down
1 change: 0 additions & 1 deletion src/persist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ export * from './watcher';
export * from './filteredAdapter';
export * from './defaultFilteredAdapter';
export * from './batchAdapter';
export * from './batchFileAdapter';
18 changes: 9 additions & 9 deletions test/managementAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { newEnforcer, Enforcer, Util } from '../src';
import { BatchFileAdapter } from '../src/persist';
import { FileAdapter } from '../src';

let e = {} as Enforcer;

Expand Down Expand Up @@ -147,7 +147,7 @@ test('addPolicy', async () => {
});

test('addPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const rules = [
['jack', 'data4', 'read'],
Expand All @@ -170,7 +170,7 @@ test('addNamedPolicy', async () => {
});

test('addNamedPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const rules = [
['jack', 'data4', 'read'],
Expand All @@ -193,7 +193,7 @@ test('removePolicy', async () => {
});

test('removePolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const rules = [
['jack', 'data4', 'read'],
Expand Down Expand Up @@ -225,7 +225,7 @@ test('removeNamedPolicy', async () => {
});

test('removeNamedPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const rules = [
['jack', 'data4', 'read'],
Expand Down Expand Up @@ -265,7 +265,7 @@ test('addGroupingPolicy', async () => {
});

test('addGroupingPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const groupingRules = [
['ham', 'data4_admin'],
Expand All @@ -281,7 +281,7 @@ test('addNamedGroupingPolicy', async () => {
});

test('addNamedGroupingPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const groupingRules = [
['ham', 'data4_admin'],
Expand All @@ -297,7 +297,7 @@ test('removeGroupingPolicy', async () => {
});

test('removeGroupingPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const groupingRules = [
['ham', 'data4_admin'],
Expand All @@ -320,7 +320,7 @@ test('removeFilteredNamedGroupingPolicy', async () => {
});

test('removeNamedGroupingPolicies', async () => {
const a = new BatchFileAdapter('examples/rbac_policy.csv');
const a = new FileAdapter('examples/rbac_policy.csv');
e.setAdapter(a);
const groupingRules = [
['ham', 'data4_admin'],
Expand Down