diff --git a/synapse/lib/layer.py b/synapse/lib/layer.py index db47659742..ab324ac324 100644 --- a/synapse/lib/layer.py +++ b/synapse/lib/layer.py @@ -1406,11 +1406,17 @@ async def setLayerInfo(self, name, valu): ''' Set a mutable layer property. ''' - if name not in ('name',): + if name not in ('name', 'logedits'): mesg = f'{name} is not a valid layer info key' raise s_exc.BadOptValu(mesg=mesg) + + if name == 'logedits': + valu = bool(valu) + self.logedits = valu + # TODO when we can set more props, we may need to parse values. await self.layrinfo.set(name, valu) + return valu async def stat(self): diff --git a/synapse/lib/stormtypes.py b/synapse/lib/stormtypes.py index 6384e87ba4..17d152c2e7 100644 --- a/synapse/lib/stormtypes.py +++ b/synapse/lib/stormtypes.py @@ -117,15 +117,15 @@ def intify(x): mesg = f'Failed to make an integer from "{x}".' raise s_exc.BadCast(mesg=mesg) from e -def kwarg_format(text, **kwargs): +def kwarg_format(_text, **kwargs): ''' Replaces instances curly-braced argument names in text with their values ''' for name, valu in kwargs.items(): temp = '{%s}' % (name,) - text = text.replace(temp, str(valu)) + _text = _text.replace(temp, str(valu)) - return text + return _text class StormType: ''' @@ -3721,6 +3721,17 @@ async def _methLayerGet(self, name, defv=None): return self.valu.get(name, defv) async def _methLayerSet(self, name, valu): + + name = await tostr(name) + + if name == 'name': + valu = await tostr(valu) + elif name == 'logedits': + valu = await tobool(valu) + else: + mesg = f'Layer does not support setting: {name}' + raise s_exc.BadOptValu(mesg=mesg) + useriden = self.runt.user.iden layriden = self.valu.get('iden') gatekeys = ((useriden, ('layer', 'set', name), layriden),) diff --git a/synapse/tests/test_lib_layer.py b/synapse/tests/test_lib_layer.py index 8a23afcd68..b368296797 100644 --- a/synapse/tests/test_lib_layer.py +++ b/synapse/tests/test_lib_layer.py @@ -1366,3 +1366,25 @@ async def test_layer_iter_props(self): rows = await alist(layr.iterTagPropRows('foo', 'score', stortype=s_layer.STOR_TYPE_I64, startvalu=42)) self.eq(expect[1:], rows) + + async def test_layer_setinfo(self): + + async with self.getTestCore() as core: + + layer = core.getView().layers[0] + + self.eq('hehe', await core.callStorm('$layer = $lib.layer.get() $layer.set(name, hehe) return($layer.get(name))')) + + self.eq(False, await core.callStorm('$layer = $lib.layer.get() $layer.set(logedits, $lib.false) return($layer.get(logedits))')) + edits0 = [e async for e in layer.syncNodeEdits(0, wait=False)] + await core.callStorm('[inet:ipv4=1.2.3.4]') + edits1 = [e async for e in layer.syncNodeEdits(0, wait=False)] + self.eq(len(edits0), len(edits1)) + + self.eq(True, await core.callStorm('$layer = $lib.layer.get() $layer.set(logedits, $lib.true) return($layer.get(logedits))')) + await core.callStorm('[inet:ipv4=5.5.5.5]') + edits2 = [e async for e in layer.syncNodeEdits(0, wait=False)] + self.gt(len(edits2), len(edits1)) + + with self.raises(s_exc.BadOptValu): + await core.callStorm('$layer = $lib.layer.get() $layer.set(newp, hehe)')