def _cmprCtorRange(self, oper): prop, valu = oper[1].get('args') core = self.getStormCore() isrel = prop.startswith(':') def initMinMax(key): xmin, _ = core.getPropNorm(key, valu[0]) xmax, _ = core.getPropNorm(key, valu[1]) return int(xmin), int(xmax) norms = s_cache.KeyCache(initMinMax) def cmpr(tufo): full = prop if isrel: form = tufo[1].get('tufo:form') full = form + prop valu = tufo[1].get(full) if valu is None: return False minval, maxval = norms.get(full) return valu >= minval and valu <= maxval return cmpr
def _cmprCtorRange(self, oper): prop = self._reqOperArg(oper, 'prop') valu = self._reqOperArg(oper, 'valu') #TODO unified syntax plumbing with in-band help core = self.getStormCore() isrel = prop.startswith(':') def initMinMax(key): xmin, _ = core.getPropNorm(key, valu[0]) xmax, _ = core.getPropNorm(key, valu[1]) return int(xmin), int(xmax) norms = s_cache.KeyCache(initMinMax) def cmpr(tufo): full = prop if isrel: form = tufo[1].get('tufo:form') full = form + prop valu = tufo[1].get(full) if valu is None: return False minval, maxval = norms.get(full) return valu >= minval and valu <= maxval return cmpr
def test_keycache_lookup(self): foo = {10: 'asdf'} def getfoo(x): return foo.get(x) cache = s_cache.KeyCache(getfoo) self.assertEqual(cache[10], 'asdf')
def test_keycache_lookup(self): foo = {10: 'asdf'} def getfoo(x): return foo.get(x) cache = s_cache.KeyCache(getfoo) self.eq(cache[10], 'asdf') # Ensure put/pop methods work. cache.put(20, 'wasd') self.eq(cache[20], 'wasd') self.eq(cache.pop(20), 'wasd')
def test_keycache_lookup(self): foo = {10: 'asdf'} def getfoo(x): return foo.get(x) cache = s_cache.KeyCache(getfoo) self.eq(cache[10], 'asdf') self.eq(cache.get(10), 'asdf') self.eq(cache.get(20), None) foo = {10: 'asdf', 20: 'abcd'} self.eq(cache.get(20), 'abcd') foo = {10: 'asdf'} self.eq(cache.get(20), 'abcd')
def __init__(self, core): EventBus.__init__(self) self.core = core self.core.addTufoForm('syn:auth:user') self.core.addTufoProp('syn:auth:user', 'apikey', defval='') self.core.addTufoProp('syn:auth:user', 'shadow:sha256', defval='') self.core.addTufoForm('syn:auth:role') self.core.addTufoForm('syn:auth:userrole') self.core.addTufoProp('syn:auth:userrole', 'user') self.core.addTufoProp('syn:auth:userrole', 'role') self.users = s_cache.TufoPropCache(core, 'syn:auth:user') self.roles = s_cache.TufoPropCache(core, 'syn:auth:role') self.rules = s_cache.KeyCache(self._getUserRulesCache)
def _cmprCtorTag(self, oper): tag = self._reqOperArg(oper, 'valu') reg_props = {} # Glob helpers glob_smark = '*' glob_mmark = '**' glob_sre = '[^\.]+?' glob_mre = '.+' def _cmpGlobParts(s, sep='.'): parts = s.split(sep) parts = [p.replace(glob_mmark, glob_mre) for p in parts] parts = [p.replace(glob_smark, glob_sre) for p in parts] regex = '\{}'.format(sep).join(parts) return regex + '$' if glob_smark in tag: tag_regex = _cmpGlobParts(tag) reobj = self._rt_regexcache.get(tag_regex) def getIsHit(prop): #_tag = prop.split('|', 2)[2] #_tag = prop.split('|', 2)[2] # prop will be like "#foo.bar" return reobj.search(prop[1:]) glob_props = s_cache.KeyCache(getIsHit) def glob_cmpr(tufo): return any((glob_props.get(p) for p in tufo[1] if p[0] == '#')) return glob_cmpr # We're out of glob town, so a tag must be normalized tag, _ = self.getTypeNorm('syn:tag', tag) def reg_cmpr(tufo): return tufo[1].get('#' + tag) is not None return reg_cmpr