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

added $lib.pkg.get() and fixups for toprim on feed (and other) APIs #1983

Merged
merged 2 commits into from
Dec 4, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions synapse/lib/stormtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class LibPkg(Lib):
def getObjLocals(self):
return {
'add': self._libPkgAdd,
'get': self._libPkgGet,
'del': self._libPkgDel,
'list': self._libPkgList,
}
Expand All @@ -226,6 +227,20 @@ async def _libPkgAdd(self, pkgdef):
self.runt.confirm(('pkg', 'add'), None)
await self.runt.snap.core.addStormPkg(pkgdef)

async def _libPkgGet(self, name):
'''
Get a Storm package from the Cortex.

Args:
name (str): A Storm Package name.

Returns:
dict: The Storm package definition.
'''
name = await tostr(name)
pkgdef = await self.runt.snap.core.getStormPkg(name)
return Dict(pkgdef)

async def _libPkgDel(self, name):
'''
Delete a Storm Package from the Cortex.
Expand Down Expand Up @@ -1421,6 +1436,9 @@ async def _libGenr(self, name, data):
Returns:
s_node.Node: An async generator that yields nodes.
'''
name = await tostr(name)
data = await toprim(data)

self.runt.layerConfirm(('feed:data', *name.split('.')))
with s_provenance.claim('feed:data', name=name):
return self.runt.snap.addFeedNodes(name, data)
Expand Down Expand Up @@ -1450,6 +1468,8 @@ async def _libIngest(self, name, data):
setting to produce warning messages, instead of causing the Storm Runtime
to be torn down.
'''
name = await tostr(name)
data = await toprim(data)

self.runt.layerConfirm(('feed:data', *name.split('.')))
with s_provenance.claim('feed:data', name=name):
Expand Down Expand Up @@ -1598,6 +1618,7 @@ async def _methQueueGets(self, offs=0, wait=True, cull=False, size=None):
yield item

async def _methQueuePuts(self, items):
items = await toprim(items)
todo = s_common.todo('coreQueuePuts', self.name, items)
gatekeys = self._getGateKeys('put')
return await self.runt.dyncall('cortex', todo, gatekeys=gatekeys)
Expand Down Expand Up @@ -1654,6 +1675,7 @@ async def _methTeleOpen(self, url):
Returns:
Proxy: A Storm Proxy representing a Telepath Proxy.
'''
url = await tostr(url)
scheme = url.split('://')[0]
self.runt.confirm(('lib', 'telepath', 'open', scheme))
return Proxy(await self.runt.getTeleProxy(url))
Expand Down
26 changes: 26 additions & 0 deletions synapse/tests/test_lib_storm.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,32 @@ async def test_lib_storm_basics(self):
resp = await core.callStorm(wget, opts=opts)
self.true(resp['ok'])

# check that the feed API uses toprim
email = await core.callStorm('''
$iden = $lib.guid()
$props = $lib.dict([email protected])
$lib.feed.ingest(syn.nodes, (
( (ps:contact, $iden), $lib.dict(props=$props)),
))
ps:contact=$iden
return(:email)
''')
self.eq(email, '[email protected]')

email = await core.callStorm('''
$iden = $lib.guid()
$props = $lib.dict([email protected])
yield $lib.feed.genr(syn.nodes, (
( (ps:contact, $iden), $lib.dict(props=$props)),
))
return(:email)
''')
self.eq(email, '[email protected]')

pkg0 = {'name': 'hehe', 'version': (1, 2, 3)}
await core.addStormPkg(pkg0)
self.eq((1, 2, 3), await core.callStorm('return($lib.pkg.get(hehe).version)'))

async def test_storm_undef(self):

async with self.getTestCore() as core:
Expand Down