Skip to content

Commit

Permalink
make lib.layer.get() return top layer from view (#2156)
Browse files Browse the repository at this point in the history
make lib.layer.get() return top layer from view
  • Loading branch information
invisig0th committed Apr 15, 2021
1 parent 4196f8e commit c432832
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions synapse/lib/stormtypes.py
Expand Up @@ -4129,7 +4129,7 @@ class LibLayer(Lib):
'args': (
{'name': 'iden', 'type': 'str', 'default': None,
'desc': 'The iden of the layer to get. '
'If not set, this defaults to the default layer of the Cortex.', },
'If not set, this defaults to the top layer of the current View.', },
),
'returns': {'type': 'storm:layer', 'desc': 'The storm layer object.', }}},
{'name': 'list', 'desc': 'List the layers in a Cortex',
Expand Down Expand Up @@ -4177,8 +4177,12 @@ async def _libLayerDel(self, iden):
return await self.runt.dyncall('cortex', todo, gatekeys=gatekeys)

async def _libLayerGet(self, iden=None):
todo = s_common.todo('getLayerDef', iden)
ldef = await self.runt.dyncall('cortex', todo)

iden = await tostr(iden, noneok=True)
if iden is None:
iden = self.runt.snap.view.layers[0].iden

ldef = await self.runt.snap.core.getLayerDef(iden=iden)
if ldef is None:
mesg = f'No layer with iden: {iden}'
raise s_exc.NoSuchIden(mesg=mesg)
Expand Down
4 changes: 4 additions & 0 deletions synapse/tests/test_lib_stormtypes.py
Expand Up @@ -1899,6 +1899,10 @@ async def test_storm_lib_layer(self):

mainlayr = core.view.layers[0].iden

forkview = await core.callStorm('return($lib.view.get().fork().iden)')
forklayr = await core.callStorm('return($lib.layer.get().iden)', opts={'view': forkview})
self.eq(forklayr, core.views.get(forkview).layers[0].iden)

q = '$lib.print($lib.layer.get().iden)'
mesgs = await core.stormlist(q)
self.stormIsInPrint(mainlayr, mesgs)
Expand Down

0 comments on commit c432832

Please sign in to comment.