Comparing version 3.0.5 to 3.0.6
@@ -166,2 +166,3 @@ "use strict"; | ||
} | ||
exports.Config = Config; | ||
Config.DEFAULT_SECTION = 'default'; | ||
@@ -171,2 +172,1 @@ Config.DEFAULT_COMMENT = '#'; | ||
Config.DEFAULT_MULTI_LINE_SEPARATOR = '\\'; | ||
exports.Config = Config; |
@@ -16,6 +16,7 @@ "use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -26,3 +27,2 @@ }); | ||
const expression_eval_1 = require("expression-eval"); | ||
const _ = require("lodash"); | ||
const effect_1 = require("./effect"); | ||
@@ -145,3 +145,3 @@ const model_1 = require("./model"); | ||
this.model.clearPolicy(); | ||
if (this.adapter.isFiltered) { | ||
if (this.adapter.isFiltered()) { | ||
yield this.adapter.loadFilteredPolicy(this.model, filter); | ||
@@ -177,3 +177,3 @@ } | ||
if (this.isFiltered()) { | ||
throw new Error('cannot save a filtered policy'); | ||
throw new Error('Cannot save a filtered policy'); | ||
} | ||
@@ -236,2 +236,3 @@ const flag = yield this.adapter.savePolicy(this.model); | ||
privateEnforce(asyncCompile = true, ...rvals) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -246,12 +247,16 @@ if (!this.enabled) { | ||
const astMap = this.model.model.get('g'); | ||
if (astMap) { | ||
astMap.forEach((value, key) => { | ||
const rm = value.rm; | ||
functions[key] = util_1.generateGFunction(rm); | ||
}); | ||
} | ||
const expString = this.model.model.get('m').get('m').value; | ||
// TODO Typescript 3.7 is not supported by prettier | ||
// eslint-disable-next-line prettier/prettier | ||
(_a = astMap) === null || _a === void 0 ? void 0 : _a.forEach((value, key) => { | ||
const rm = value.rm; | ||
functions[key] = util_1.generateGFunction(rm); | ||
}); | ||
const expString = (_c = (_b = this.model.model.get('m')) === null || _b === void 0 ? void 0 : _b.get('m')) === null || _c === void 0 ? void 0 : _c.value; | ||
if (!expString) { | ||
throw new Error('model is undefined'); | ||
throw new Error('Unable to find matchers in model'); | ||
} | ||
const effect = (_e = (_d = this.model.model.get('e')) === null || _d === void 0 ? void 0 : _d.get('e')) === null || _e === void 0 ? void 0 : _e.value; | ||
if (!effect) { | ||
throw new Error('Unable to find policy_effect in model'); | ||
} | ||
const matcherKey = `${asyncCompile ? 'ASYNC[' : 'SYNC['}${expString}]`; | ||
@@ -265,18 +270,22 @@ let expression = this.matcherMap.get(matcherKey); | ||
let matcherResults; | ||
const policyLen = this.model.model.get('p').get('p').policy.length; | ||
if (policyLen !== 0) { | ||
const p = (_f = this.model.model.get('p')) === null || _f === void 0 ? void 0 : _f.get('p'); | ||
const policyLen = (_h = (_g = p) === null || _g === void 0 ? void 0 : _g.policy) === null || _h === void 0 ? void 0 : _h.length; | ||
const rTokens = (_k = (_j = this.model.model.get('r')) === null || _j === void 0 ? void 0 : _j.get('r')) === null || _k === void 0 ? void 0 : _k.tokens; | ||
const rTokensLen = (_l = rTokens) === null || _l === void 0 ? void 0 : _l.length; | ||
if (policyLen && policyLen !== 0) { | ||
policyEffects = new Array(policyLen); | ||
matcherResults = new Array(policyLen); | ||
for (let i = 0; i < policyLen; i++) { | ||
const pvals = this.model.model.get('p').get('p').policy[i]; | ||
const parameters = {}; | ||
const { tokens: rTokens } = this.model.model.get('r').get('r'); | ||
if (((_m = rTokens) === null || _m === void 0 ? void 0 : _m.length) !== rvals.length) { | ||
throw new Error(`invalid request size: expected ${rTokensLen}, got ${rvals.length}, rvals: ${rvals}"`); | ||
} | ||
rTokens.forEach((token, j) => { | ||
parameters[token] = rvals[j]; | ||
}); | ||
const { tokens: gTokens } = this.model.model.get('p').get('p'); | ||
gTokens.forEach((token, j) => { | ||
parameters[token] = pvals[j]; | ||
(_o = p) === null || _o === void 0 ? void 0 : _o.tokens.forEach((token, j) => { | ||
var _a; | ||
parameters[token] = (_a = p) === null || _a === void 0 ? void 0 : _a.policy[i][j]; | ||
}); | ||
const context = Object.assign({}, parameters, functions); | ||
const context = Object.assign(Object.assign({}, parameters), functions); | ||
const result = asyncCompile ? yield expression(context) : expression(context); | ||
@@ -302,4 +311,4 @@ switch (typeof result) { | ||
} | ||
if (_.has(parameters, 'p_eft')) { | ||
const eft = _.get(parameters, 'p_eft'); | ||
const eft = parameters['p_eft']; | ||
if (eft) { | ||
if (eft === 'allow') { | ||
@@ -318,3 +327,3 @@ policyEffects[i] = effect_1.Effect.Allow; | ||
} | ||
if (this.model.model.get('e').get('e').value === 'priority(p_eft) || deny') { | ||
if (effect === 'priority(p_eft) || deny') { | ||
break; | ||
@@ -328,11 +337,9 @@ } | ||
const parameters = {}; | ||
const { tokens: rTokens } = this.model.model.get('r').get('r'); | ||
rTokens.forEach((token, j) => { | ||
(_p = rTokens) === null || _p === void 0 ? void 0 : _p.forEach((token, j) => { | ||
parameters[token] = rvals[j]; | ||
}); | ||
const { tokens: pTokens } = this.model.model.get('p').get('p'); | ||
pTokens.forEach(token => { | ||
(_r = (_q = p) === null || _q === void 0 ? void 0 : _q.tokens) === null || _r === void 0 ? void 0 : _r.forEach(token => { | ||
parameters[token] = ''; | ||
}); | ||
const context = Object.assign({}, parameters, functions); | ||
const context = Object.assign(Object.assign({}, parameters), functions); | ||
const result = asyncCompile ? yield expression(context) : expression(context); | ||
@@ -346,3 +353,3 @@ if (result) { | ||
} | ||
const res = this.eft.mergeEffects(this.model.model.get('e').get('e').value, policyEffects, matcherResults); | ||
const res = this.eft.mergeEffects(effect, policyEffects, matcherResults); | ||
// only generate the request --> result string if the message | ||
@@ -349,0 +356,0 @@ // is going to be logged. |
@@ -16,6 +16,7 @@ "use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -96,8 +97,7 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const rm = this.model.model.get('g').get('g').rm; | ||
if (domain == null) { | ||
return yield rm.getRoles(name); | ||
return yield this.rm.getRoles(name); | ||
} | ||
else { | ||
return yield rm.getRoles(name, domain); | ||
return yield this.rm.getRoles(name, domain); | ||
} | ||
@@ -115,8 +115,7 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const rm = this.model.model.get('g').get('g').rm; | ||
if (domain == null) { | ||
return yield rm.getUsers(name); | ||
return yield this.rm.getUsers(name); | ||
} | ||
else { | ||
return yield rm.getUsers(name, domain); | ||
return yield this.rm.getUsers(name, domain); | ||
} | ||
@@ -123,0 +122,0 @@ }); |
@@ -16,6 +16,7 @@ "use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -22,0 +23,0 @@ }); |
@@ -16,6 +16,7 @@ "use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -22,0 +23,0 @@ }); |
@@ -16,6 +16,7 @@ "use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -22,0 +23,0 @@ }); |
@@ -30,2 +30,4 @@ "use strict"; | ||
fm.addFunction('keyMatch2', util.keyMatch2Func); | ||
fm.addFunction('keyMatch3', util.keyMatch3Func); | ||
fm.addFunction('keyMatch4', util.keyMatch4Func); | ||
fm.addFunction('regexMatch', util.regexMatchFunc); | ||
@@ -32,0 +34,0 @@ fm.addFunction('ipMatch', util.ipMatchFunc); |
@@ -16,6 +16,7 @@ "use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -161,4 +162,7 @@ }); | ||
getPolicy(sec, key) { | ||
var _a; | ||
const policy = []; | ||
const ast = this.model.get(sec).get(key); | ||
// TODO Typescript 3.7 is not supported by prettier | ||
// eslint-disable-next-line prettier/prettier | ||
const ast = (_a = this.model.get(sec)) === null || _a === void 0 ? void 0 : _a.get(key); | ||
if (ast) { | ||
@@ -171,3 +175,4 @@ policy.push(...ast.policy); | ||
hasPolicy(sec, key, rule) { | ||
const ast = this.model.get(sec).get(key); | ||
var _a; | ||
const ast = (_a = this.model.get(sec)) === null || _a === void 0 ? void 0 : _a.get(key); | ||
if (!ast) { | ||
@@ -180,4 +185,5 @@ return false; | ||
addPolicy(sec, key, rule) { | ||
var _a; | ||
if (!this.hasPolicy(sec, key, rule)) { | ||
const ast = this.model.get(sec).get(key); | ||
const ast = (_a = this.model.get(sec)) === null || _a === void 0 ? void 0 : _a.get(key); | ||
if (!ast) { | ||
@@ -193,4 +199,5 @@ return false; | ||
removePolicy(sec, key, rule) { | ||
var _a; | ||
if (this.hasPolicy(sec, key, rule)) { | ||
const ast = this.model.get(sec).get(key); | ||
const ast = (_a = this.model.get(sec)) === null || _a === void 0 ? void 0 : _a.get(key); | ||
if (!ast) { | ||
@@ -206,4 +213,5 @@ return true; | ||
getFilteredPolicy(sec, key, fieldIndex, ...fieldValues) { | ||
var _a; | ||
const res = []; | ||
const ast = this.model.get(sec).get(key); | ||
const ast = (_a = this.model.get(sec)) === null || _a === void 0 ? void 0 : _a.get(key); | ||
if (!ast) { | ||
@@ -229,5 +237,6 @@ return res; | ||
removeFilteredPolicy(sec, key, fieldIndex, ...fieldValues) { | ||
var _a; | ||
const res = []; | ||
let bool = false; | ||
const ast = this.model.get(sec).get(key); | ||
const ast = (_a = this.model.get(sec)) === null || _a === void 0 ? void 0 : _a.get(key); | ||
if (!ast) { | ||
@@ -257,4 +266,5 @@ return bool; | ||
getValuesForFieldInPolicy(sec, key, fieldIndex) { | ||
var _a; | ||
const values = []; | ||
const ast = this.model.get(sec).get(key); | ||
const ast = (_a = this.model.get(sec)) === null || _a === void 0 ? void 0 : _a.get(key); | ||
if (!ast) { | ||
@@ -261,0 +271,0 @@ return values; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -8,0 +9,0 @@ }); |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -8,0 +9,0 @@ }); |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -8,0 +9,0 @@ }); |
@@ -16,6 +16,7 @@ "use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -26,2 +27,43 @@ }); | ||
const log_1 = require("../log"); | ||
/** | ||
* Role represents the data structure for a role in RBAC. | ||
*/ | ||
class Role { | ||
constructor(name) { | ||
this.name = name; | ||
this.roles = []; | ||
} | ||
addRole(role) { | ||
if (this.roles.some(n => n.name === role.name)) { | ||
return; | ||
} | ||
this.roles.push(role); | ||
} | ||
deleteRole(role) { | ||
this.roles = this.roles.filter(n => n.name !== role.name); | ||
} | ||
hasRole(name, hierarchyLevel) { | ||
if (this.name === name) { | ||
return true; | ||
} | ||
if (hierarchyLevel <= 0) { | ||
return false; | ||
} | ||
for (const role of this.roles) { | ||
if (role.hasRole(name, hierarchyLevel - 1)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
hasDirectRole(name) { | ||
return this.roles.some(n => n.name === name); | ||
} | ||
toString() { | ||
return this.name + this.roles.join(', '); | ||
} | ||
getRoles() { | ||
return this.roles.map(n => n.name); | ||
} | ||
} | ||
// RoleManager provides a default implementation for the RoleManager interface | ||
@@ -181,42 +223,1 @@ class DefaultRoleManager { | ||
exports.DefaultRoleManager = DefaultRoleManager; | ||
/** | ||
* Role represents the data structure for a role in RBAC. | ||
*/ | ||
class Role { | ||
constructor(name) { | ||
this.name = name; | ||
this.roles = []; | ||
} | ||
addRole(role) { | ||
if (this.roles.some(n => n.name === role.name)) { | ||
return; | ||
} | ||
this.roles.push(role); | ||
} | ||
deleteRole(role) { | ||
this.roles = this.roles.filter(n => n.name !== role.name); | ||
} | ||
hasRole(name, hierarchyLevel) { | ||
if (this.name === name) { | ||
return true; | ||
} | ||
if (hierarchyLevel <= 0) { | ||
return false; | ||
} | ||
for (const role of this.roles) { | ||
if (role.hasRole(name, hierarchyLevel - 1)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
hasDirectRole(name) { | ||
return this.roles.some(n => n.name === name); | ||
} | ||
toString() { | ||
return this.name + this.roles.join(', '); | ||
} | ||
getRoles() { | ||
return this.roles.map(n => n.name); | ||
} | ||
} |
@@ -5,5 +5,6 @@ import * as rbac from '../rbac'; | ||
declare function keyMatch3Func(...args: any[]): boolean; | ||
declare function keyMatch4Func(...args: any[]): boolean; | ||
declare function regexMatchFunc(...args: any[]): boolean; | ||
declare function ipMatchFunc(...args: any[]): boolean; | ||
declare function generateGFunction(rm: rbac.RoleManager): any; | ||
export { keyMatchFunc, keyMatch2Func, keyMatch3Func, regexMatchFunc, ipMatchFunc, generateGFunction }; | ||
export { keyMatchFunc, keyMatch2Func, keyMatch3Func, regexMatchFunc, ipMatchFunc, generateGFunction, keyMatch4Func }; |
@@ -16,6 +16,7 @@ "use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -27,2 +28,6 @@ }); | ||
const _ = require("lodash"); | ||
// regexMatch determines whether key1 matches the pattern of key2 in regular expression. | ||
function regexMatch(key1, key2) { | ||
return new RegExp(key2).test(key1); | ||
} | ||
// keyMatch determines whether key1 matches the pattern of key2 (similar to RESTful path), | ||
@@ -89,6 +94,66 @@ // key2 can contain a *. | ||
exports.keyMatch3Func = keyMatch3Func; | ||
// regexMatch determines whether key1 matches the pattern of key2 in regular expression. | ||
function regexMatch(key1, key2) { | ||
return new RegExp(key2).test(key1); | ||
// keyMatch4 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *. | ||
// Besides what keyMatch3 does, keyMatch4 can also match repeated patterns: | ||
// "/parent/123/child/123" matches "/parent/{id}/child/{id}" | ||
// "/parent/123/child/456" does not match "/parent/{id}/child/{id}" | ||
// But keyMatch3 will match both. | ||
function keyMatch4(key1, key2) { | ||
key2 = key2.replace(/\/\*/g, '/.*'); | ||
const tokens = []; | ||
let j = -1; | ||
for (let i = 0; i < key2.length; i++) { | ||
const c = key2.charAt(i); | ||
if (c === '{') { | ||
j = i; | ||
} | ||
else if (c === '}') { | ||
tokens.push(key2.substring(j, i + 1)); | ||
} | ||
} | ||
let regexp = new RegExp(/(.*){[^/]+}(.*)/g); | ||
for (;;) { | ||
if (!key2.includes('/{')) { | ||
break; | ||
} | ||
key2 = key2.replace(regexp, '$1([^/]+)$2'); | ||
} | ||
regexp = new RegExp('^' + key2 + '$'); | ||
let values = regexp.exec(key1); | ||
if (!values) { | ||
return false; | ||
} | ||
values = values.slice(1); | ||
if (tokens.length !== values.length) { | ||
throw new Error('KeyMatch4: number of tokens is not equal to number of values'); | ||
} | ||
const m = new Map(); | ||
tokens.forEach((n, index) => { | ||
const key = tokens[index]; | ||
let v = m.get(key); | ||
if (!v) { | ||
v = []; | ||
} | ||
if (values) { | ||
v.push(values[index]); | ||
} | ||
m.set(key, v); | ||
}); | ||
for (const value of m.values()) { | ||
if (value.length > 1) { | ||
for (let i = 1; i < values.length; i++) { | ||
if (values[i] !== values[0]) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
// keyMatch4Func is the wrapper for keyMatch4. | ||
function keyMatch4Func(...args) { | ||
const name1 = _.toString(args[0]); | ||
const name2 = _.toString(args[1]); | ||
return keyMatch4(name1, name2); | ||
} | ||
exports.keyMatch4Func = keyMatch4Func; | ||
// regexMatchFunc is the wrapper for regexMatch. | ||
@@ -95,0 +160,0 @@ function regexMatchFunc(...args) { |
{ | ||
"name": "casbin", | ||
"version": "3.0.5", | ||
"version": "3.0.6", | ||
"description": "An authorization library that supports access control models like ACL, RBAC, ABAC in Node.JS", | ||
@@ -10,6 +10,5 @@ "main": "lib/index.js", | ||
"postpack": "rimraf lib", | ||
"prettier": "prettier --write **/*.{ts,js}", | ||
"build": "rimraf lib && tsc -p tsconfig.release.json", | ||
"lint": "tslint -p . -c tslint.json", | ||
"test": "jest" | ||
"build": "rimraf lib && tsc", | ||
"test": "jest", | ||
"lint": "eslint . --ext .js,.ts" | ||
}, | ||
@@ -21,11 +20,17 @@ "devDependencies": { | ||
"@types/node": "^10.5.3", | ||
"@typescript-eslint/eslint-plugin": "^2.6.1", | ||
"@typescript-eslint/parser": "^2.6.1", | ||
"coveralls": "^3.0.2", | ||
"eslint": "^6.6.0", | ||
"eslint-config-prettier": "^6.5.0", | ||
"eslint-plugin-prettier": "^3.1.1", | ||
"husky": "^2.3.0", | ||
"jest": "^24.3.1", | ||
"lint-staged": "^8.1.7", | ||
"prettier": "^1.17.1", | ||
"prettier": "^1.18.2", | ||
"pretty-quick": "^2.0.1", | ||
"rimraf": "^2.6.2", | ||
"ts-jest": "^24.0.0", | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.4.5" | ||
"typescript": "^3.7.2" | ||
}, | ||
@@ -54,11 +59,5 @@ "dependencies": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
"pre-commit": "yarn lint && pretty-quick --staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{ts,js}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"publishConfig": { | ||
@@ -65,0 +64,0 @@ "registry": "https://registry.yarnpkg.com" |
179799
4075
19