diff --git a/changes/4a4d016df5220dbe11c742d168326ee0.yaml b/changes/4a4d016df5220dbe11c742d168326ee0.yaml new file mode 100644 index 00000000000..241e4323954 --- /dev/null +++ b/changes/4a4d016df5220dbe11c742d168326ee0.yaml @@ -0,0 +1,7 @@ +--- +desc: Added ``$lib.cell.iden`` to retrieve the iden of the Cortex which the Storm + query is executing on. Unlike ``$lib.cell.getCellInfo().cell.iden``, this value + is available to non-admin users. +prs: [] +type: feat +... diff --git a/synapse/lib/stormlib/cell.py b/synapse/lib/stormlib/cell.py index 5e450ab04c6..c428f5080aa 100644 --- a/synapse/lib/stormlib/cell.py +++ b/synapse/lib/stormlib/cell.py @@ -120,6 +120,9 @@ class CellLib(s_stormtypes.Lib): A Storm Library for interacting with the Cortex. ''' _storm_locals = ( + {'name': 'iden', 'desc': 'The Cortex service identifier.', + 'type': {'type': 'gtor', '_gtorfunc': '_getCellIden', + 'returns': {'type': 'str', 'desc': 'The Cortex service identifier.'}}}, {'name': 'getCellInfo', 'desc': 'Return metadata specific for the Cortex.', 'type': {'type': 'function', '_funcname': '_getCellInfo', 'args': (), 'returns': {'type': 'dict', 'desc': 'A dictionary containing metadata.', }}}, @@ -174,6 +177,10 @@ class CellLib(s_stormtypes.Lib): ) _storm_lib_path = ('cell',) + def __init__(self, runt, name=()): + s_stormtypes.Lib.__init__(self, runt, name=name) + self.gtors['iden'] = self._getCellIden + def getObjLocals(self): return { 'getCellInfo': self._getCellInfo, @@ -187,6 +194,10 @@ def getObjLocals(self): 'uptime': self._uptime, } + @s_stormtypes.stormfunc(readonly=True) + async def _getCellIden(self): + return self.runt.snap.core.getCellIden() + async def _hotFixesApply(self): if not self.runt.isAdmin(): mesg = '$lib.cell.stormFixesApply() requires admin privs.' diff --git a/synapse/tests/test_lib_stormlib_cell.py b/synapse/tests/test_lib_stormlib_cell.py index 95732aa4934..a76e56dfa3a 100644 --- a/synapse/tests/test_lib_stormlib_cell.py +++ b/synapse/tests/test_lib_stormlib_cell.py @@ -14,6 +14,9 @@ async def test_stormlib_cell(self): async with self.getTestCore() as core: + ret = await core.callStorm('return ( $lib.cell.iden )') + self.eq(ret, core.getCellIden()) + ret = await core.callStorm('return ( $lib.cell.getCellInfo() )') self.eq(ret, await core.getCellInfo())