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

make $lib.layer.get() return top layer from view by default #2156

Merged
merged 2 commits into from Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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