diff --git a/synapse/cortex.py b/synapse/cortex.py index 206c3de818..04639af4b9 100644 --- a/synapse/cortex.py +++ b/synapse/cortex.py @@ -109,8 +109,6 @@ reqver = '>=0.2.0,<3.0.0' -NEXSVERS_CRON_USER = (2, 193) - # Constants returned in results from syncLayersEvents and syncIndexEvents SYNC_NODEEDITS = 0 # A nodeedits: (, 0, , (), {}) SYNC_NODEEDIT = 1 # A nodeedit: (, 0, , ()) @@ -959,7 +957,6 @@ async def initServiceStorage(self): await self._bumpCellVers('cortex:storage', ( (1, self._storUpdateMacros), (4, self._storCortexHiveMigration), - (5, self._cronCreatorToUser), ), nexs=False) # Perform module loading @@ -1098,12 +1095,17 @@ async def _viewNomergeToProtected(self): await view.setViewInfo('protected', nomerge) await view.setViewInfo('nomerge', None) - async def _cronCreatorToUser(self): - apptdefs = self.cortexdata.getSubKeyVal('agenda:appt:') - for iden, info in apptdefs.items(): - if (user := info.pop('creator', None)) is not None: - info['user'] = user - apptdefs.set(iden, info) + async def _addCronUser(self): + for iden, cron in self.agenda.list(): + await self.editCronJob(iden, 'user', cron.creator) + + @s_nexus.Pusher.onPushAuto('cortex:add:trigger:creator') + async def _addTriggerCreator(self): + for view in self.views.values(): + for iden, trig in view.triggers.list(): + if trig.tdef.get('creator') is None: + trig.tdef['creator'] = trig.tdef['user'] + view.trigdict.set(iden, trig.tdef) async def _storUpdateMacros(self): for name, node in await self.hive.open(('cortex', 'storm', 'macros')): @@ -1536,6 +1538,8 @@ async def _execCellUpdates(self): await self._bumpCellVers('cortex:defaults', ( (1, self._addAllLayrRead), (2, self._viewNomergeToProtected), + (3, self._addCronUser), + (4, self._addTriggerCreator), )) async def _addAllLayrRead(self): @@ -6510,10 +6514,6 @@ async def addCronJob(self, cdef): The incunit if not None it must be larger in unit size than all the keys in all reqs elements. Non-recurring jobs may also have a req of 'now' which will cause the job to also execute immediately. ''' - if self.nexsvers < NEXSVERS_CRON_USER: - if (user := cdef.pop('user', None)) is not None: - cdef['creator'] = user - s_schemas.reqValidCronDef(cdef) iden = cdef.get('iden') @@ -6550,10 +6550,7 @@ async def addCronJob(self, cdef): cdef['created'] = s_common.now() - if (user := cdef.get('user')) is None: - user = cdef.get('creator') - - opts = {'user': user, 'view': cdef.get('view')} + opts = {'user': cdef['user'], 'view': cdef.get('view')} view = self._viewFromOpts(opts) cdef['view'] = view.iden @@ -6563,9 +6560,6 @@ async def addCronJob(self, cdef): @s_nexus.Pusher.onPush('cron:add') async def _onAddCronJob(self, cdef): - if (user := cdef.pop('creator', None)) is not None: - cdef['user'] = user - iden = cdef['iden'] appt = self.agenda.appts.get(iden) @@ -6688,25 +6682,23 @@ async def listCronJobs(self): if user is not None: info['username'] = user.name + creator = self.auth.user(cron.creator) + if creator is not None: + info['creatorname'] = creator.name + crons.append(info) return crons + @s_nexus.Pusher.onPushAuto('cron:edit') async def editCronJob(self, iden, name, valu): - if self.nexsvers < NEXSVERS_CRON_USER and name == 'user': - name = 'creator' - - return await self._push('cron:edit', iden, name, valu) - - @s_nexus.Pusher.onPush('cron:edit') - async def _editCronJob(self, iden, name, valu): ''' Modify a cron job definition. ''' appt = await self.agenda.get(iden) # TODO make this generic and check cdef - if name in ('creator', 'user'): + if name == 'user': await self.auth.reqUser(valu) appt.user = valu diff --git a/synapse/lib/agenda.py b/synapse/lib/agenda.py index f594a091d4..928cf383a7 100644 --- a/synapse/lib/agenda.py +++ b/synapse/lib/agenda.py @@ -269,7 +269,7 @@ class _Appt: 'lastfinishtime', } - def __init__(self, stor, iden, recur, indx, query, user, recs, nexttime=None, view=None, created=None, pool=False): + def __init__(self, stor, iden, recur, indx, query, creator, user, recs, nexttime=None, view=None, created=None, pool=False): self.doc = '' self.name = '' self.task = None @@ -280,6 +280,7 @@ def __init__(self, stor, iden, recur, indx, query, user, recs, nexttime=None, vi self.indx = indx # incremented for each appt added ever. Used for nexttime tiebreaking for stable ordering self.query = query # query to run self.user = user # user iden to run query as + self.creator = creator # user iden which created the appt self.recs = recs # List[ApptRec] list of the individual entries to calculate next time from self._recidxnexttime = None # index of rec who is up next self.view = view @@ -347,6 +348,7 @@ def pack(self): 'indx': self.indx, 'query': self.query, 'user': self.user, + 'creator': self.creator, 'created': self.created, 'recs': [d.pack() for d in self.recs], 'nexttime': self.nexttime, @@ -364,7 +366,11 @@ def unpack(cls, stor, val): if val['ver'] != 1: raise s_exc.BadStorageVersion(mesg=f"Found version {val['ver']}") # pragma: no cover recs = [ApptRec.unpack(tupl) for tupl in val['recs']] - appt = cls(stor, val['iden'], val['recur'], val['indx'], val['query'], val['user'], recs, nexttime=val['nexttime'], view=val.get('view')) + + creator = val['creator'] + user = val.get('user', creator) + + appt = cls(stor, val['iden'], val['recur'], val['indx'], val['query'], creator, user, recs, nexttime=val['nexttime'], view=val.get('view')) appt.doc = val.get('doc', '') appt.name = val.get('name', '') appt.pool = val.get('pool', False) @@ -525,6 +531,9 @@ async def add(self, cdef): Notes: The cron definition may contain the following keys: + creator (str) + Iden of the user which created the appointment. + user (str) Iden of the user used to run the Storm query. @@ -558,6 +567,7 @@ async def add(self, cdef): query = cdef.get('storm') user = cdef.get('user') view = cdef.get('view') + creator = cdef.get('creator', self.core.auth.rootuser.iden) created = cdef.get('created') pool = cdef.get('pool', False) @@ -603,7 +613,7 @@ async def add(self, cdef): incvals = (incvals, ) recs.extend(ApptRec(rd, incunit, v) for (rd, v) in itertools.product(reqdicts, incvals)) - appt = _Appt(self, iden, recur, indx, query, user, recs, nexttime=nexttime, view=view, created=created, pool=pool) + appt = _Appt(self, iden, recur, indx, query, creator, user, recs, nexttime=nexttime, view=view, created=created, pool=pool) self._addappt(iden, appt) appt.doc = cdef.get('doc', '') diff --git a/synapse/lib/cell.py b/synapse/lib/cell.py index 5242deddfa..adcd1dc5b7 100644 --- a/synapse/lib/cell.py +++ b/synapse/lib/cell.py @@ -62,7 +62,7 @@ logger = logging.getLogger(__name__) -NEXUS_VERSION = (2, 193) +NEXUS_VERSION = (2, 177) SLAB_MAP_SIZE = 128 * s_const.mebibyte SSLCTX_CACHE_SIZE = 64 diff --git a/synapse/lib/schemas.py b/synapse/lib/schemas.py index eb88f268db..94df873cb3 100644 --- a/synapse/lib/schemas.py +++ b/synapse/lib/schemas.py @@ -120,10 +120,7 @@ }, }, 'additionalProperties': False, - 'required': ['storm'], - 'if': {'required': ['user']}, - 'then': {'not': {'required': ['creator']}}, - 'else': {'required': ['creator']}, + 'required': ['creator', 'storm', 'user'], 'dependencies': { 'incvals': ['incunit'], 'incunit': ['incvals'], diff --git a/synapse/lib/storm.py b/synapse/lib/storm.py index a80263db09..17d7d89094 100644 --- a/synapse/lib/storm.py +++ b/synapse/lib/storm.py @@ -1187,51 +1187,77 @@ ('--all', {'help': 'List every trigger in every readable view, rather than just the current view.', 'action': 'store_true'}), ), 'storm': ''' - $triggers = $lib.trigger.list($cmdopts.all) + init { + $conf = ({ + "columns": [ + {"name": "creator", "width": 24}, + {"name": "user", "width": 24}, + {"name": "iden", "width": 32}, + {"name": "view", "width": 11}, + {"name": "en?", "width": 3}, + {"name": "async?", "width": 6}, + {"name": "cond", "width": 9}, + {"name": "object", "width": 32}, + {"name": "storm query", "newlines": "split"}, + ], + "separators": { + "row:outline": false, + "column:outline": false, + "header:row": "#", + "data:row": "", + "column": "", + }, + }) + $printer = $lib.tabular.printer($conf) + } + $triggers = $lib.trigger.list($cmdopts.all) if $triggers { + $lib.print($printer.header()) - $lib.print("user iden view en? async? cond object storm query") + for $trig in $triggers { - for $trigger in $triggers { - $user = $trigger.username.ljust(10) - $iden = $trigger.iden.ljust(12) - $view = $trigger.view.ljust(12) - ($ok, $async) = $lib.trycast(bool, $trigger.async) - if $ok { - $async = $lib.model.type(bool).repr($async).ljust(6) - } else { - $async = $lib.model.type(bool).repr($lib.false).ljust(6) - } - $enabled = $lib.model.type(bool).repr($trigger.enabled).ljust(6) - $cond = $trigger.cond.ljust(9) + if ($trig.enabled) { $enabled = 'Y' } + else { $enabled = 'N' } + + if ($trig.async) { $async = 'Y' } + else { $async = 'N' } $fo = "" - if $trigger.form { - $fo = $trigger.form - } + if $trig.form { $fo = $trig.form } - $pr = "" - if $trigger.prop { - $pr = $trigger.prop - } + if $trig.cond.startswith('tag:') { - if $cond.startswith('tag:') { - $obj = $fo.ljust(14) - $obj2 = $trigger.tag.ljust(10) + $obj = `{$fo}#{$trig.tag}` + + } elif $trig.cond.startswith('edge:') { + + $n2form = $trig.n2form + if (not $n2form) { $n2form = '*' } + if (not $fo) { $fo = '*' } + + $obj = `{$fo} -({$trig.verb})> {$n2form}` } else { + $pr = "" + if $trig.prop { + $pr = $trig.prop + } + if $pr { - $obj = $pr.ljust(14) + $obj = $pr } elif $fo { - $obj = $fo.ljust(14) + $obj = $fo } else { - $obj = ' ' + $obj = '' } - $obj2 = ' ' } - $lib.print(`{$user} {$iden} {$view} {$enabled} {$async} {$cond} {$obj} {$obj2} {$trigger.storm}`) + $row = ( + $trig.creatorname, $trig.username, $trig.iden, $trig.view, + $enabled, $async, $trig.cond, $obj, $trig.storm + ) + $lib.print($printer.row($row)) } } else { $lib.print("No triggers found") @@ -1392,6 +1418,7 @@ init { $conf = ({ "columns": [ + {"name": "creator", "width": 24}, {"name": "user", "width": 24}, {"name": "iden", "width": 10}, {"name": "view", "width": 10}, @@ -1420,7 +1447,7 @@ for $cron in $crons { $job = $cron.pprint() $row = ( - $job.user, $job.idenshort, $job.viewshort, $job.enabled, + $job.creator, $job.user, $job.idenshort, $job.viewshort, $job.enabled, $job.isrecur, $job.isrunning, $job.iserr, `{$job.startcount}`, $job.laststart, $job.lastend, $job.query ) @@ -1444,6 +1471,7 @@ $job = $cron.pprint() $lib.print('iden: {iden}', iden=$job.iden) + $lib.print('creator: {creator}', creator=$job.creator) $lib.print('user: {user}', user=$job.user) $lib.print('enabled: {enabled}', enabled=$job.enabled) $lib.print(`pool: {$job.pool}`) diff --git a/synapse/lib/stormtypes.py b/synapse/lib/stormtypes.py index 1494c7f21e..8e57916690 100644 --- a/synapse/lib/stormtypes.py +++ b/synapse/lib/stormtypes.py @@ -8514,6 +8514,7 @@ async def _methTriggerAdd(self, tdef): useriden = self.runt.user.iden tdef['user'] = useriden + tdef['creator'] = useriden viewiden = tdef.pop('view', None) if viewiden is None: @@ -8738,6 +8739,7 @@ async def move(self, viewiden): tdef = dict(self.valu) tdef['view'] = viewiden tdef['user'] = useriden + tdef['creator'] = useriden try: s_trigger.reqValidTdef(tdef) @@ -9094,8 +9096,6 @@ class LibCron(Lib): 'desc': 'Permits a user to modify/move a cron job.'}, {'perm': ('cron', 'set', 'user'), 'gate': 'cortex', 'desc': 'Permits a user to modify the user property of a cron job.'}, - {'perm': ('cron', 'set', 'creator'), 'gate': 'cortex', - 'desc': 'Deprecated - Permits a user to modify the creator property of a cron job.'}, ) def getObjLocals(self): @@ -9366,7 +9366,8 @@ async def _methCronAdd(self, **kwargs): 'pool': pool, 'incunit': incunit, 'incvals': incval, - 'user': self.runt.user.iden + 'user': self.runt.user.iden, + 'creator': self.runt.user.iden } iden = kwargs.get('iden') @@ -9445,7 +9446,8 @@ def _ts_to_reqdict(ts): 'reqs': reqdicts, 'incunit': None, 'incvals': None, - 'user': self.runt.user.iden + 'user': self.runt.user.iden, + 'creator': self.runt.user.iden } iden = kwargs.get('iden') @@ -9588,18 +9590,13 @@ async def _methCronJobSet(self, name, valu): if name == 'user': # this permission must be granted cortex wide # to prevent abuse... + # TODO: Should we migrate this perm? self.runt.confirm(('cron', 'set', 'user')) - elif name == 'creator': - s_common.deprecated('Setting cron job "creator" field', curv='2.193.0') - mesg = 'Setting the cron job "creator" field is deprecated. Set the "user" field instead.' - await self.runt.warnonce(mesg, iden=iden) - - # this permission must be granted cortex wide - # to prevent abuse... - self.runt.confirm(('cron', 'set', 'creator')) - name = 'user' - else: + elif name in ('doc', 'name', 'pool'): self.runt.confirm(('cron', 'set', name), gateiden=iden) + else: + mesg = f'CronJob does not support setting: {name}' + raise s_exc.BadArg(mesg=mesg) self.valu = await self.runt.snap.core.editCronJob(iden, name, valu) @@ -9616,6 +9613,8 @@ def _formatTimestamp(ts): @stormfunc(readonly=True) async def _methCronJobPprint(self): user = self.valu.get('username') + creator = self.valu.get('creatorname') + view = self.valu.get('view') if not view: view = self.runt.snap.core.view.iden @@ -9629,6 +9628,7 @@ async def _methCronJobPprint(self): 'iden': iden, 'idenshort': iden[:8] + '..', 'user': user or '', + 'creator': creator or '', 'view': view, 'viewshort': view[:8] + '..', 'query': self.valu.get('query') or '', diff --git a/synapse/lib/trigger.py b/synapse/lib/trigger.py index 7ef8e1ca5c..6b88c20ef6 100644 --- a/synapse/lib/trigger.py +++ b/synapse/lib/trigger.py @@ -36,6 +36,7 @@ 'properties': { 'iden': {'type': 'string', 'pattern': s_config.re_iden}, 'user': {'type': 'string', 'pattern': s_config.re_iden}, + 'creator': {'type': 'string', 'pattern': s_config.re_iden}, 'view': {'type': 'string', 'pattern': s_config.re_iden}, 'form': {'type': 'string', 'pattern': _formre}, 'n2form': {'type': 'string', 'pattern': _formre}, @@ -51,7 +52,7 @@ 'created': {'type': 'integer', 'minimum': 0}, }, 'additionalProperties': True, - 'required': ['iden', 'user', 'storm', 'enabled'], + 'required': ['iden', 'user', 'storm', 'enabled', 'creator'], 'allOf': [ { 'if': {'properties': {'cond': {'const': 'node:add'}}}, @@ -566,6 +567,13 @@ def pack(self): if triguser is not None: tdef['username'] = triguser.name + if (creator := tdef.get('creator')) is not None: + if (user := self.view.core.auth.user(creator)) is not None: + tdef['creatorname'] = user.name + else: + tdef['creator'] = triguser.iden + tdef['creatorname'] = triguser.name + return tdef def getStorNode(self, form): diff --git a/synapse/lib/view.py b/synapse/lib/view.py index e69c60bbd3..9f3eda88f6 100644 --- a/synapse/lib/view.py +++ b/synapse/lib/view.py @@ -1603,6 +1603,7 @@ async def addTrigger(self, tdef): tdef.setdefault('created', s_common.now()) tdef.setdefault('user', root.iden) + tdef.setdefault('creator', tdef['user']) tdef.setdefault('async', False) tdef.setdefault('enabled', True) @@ -1613,8 +1614,6 @@ async def addTrigger(self, tdef): @s_nexus.Pusher.onPush('trigger:add') async def _onPushAddTrigger(self, tdef): - s_trigger.reqValidTdef(tdef) - trig = self.trigdict.get(tdef['iden']) if trig is not None: return self.triggers.get(tdef['iden']).pack() diff --git a/synapse/tests/test_lib_agenda.py b/synapse/tests/test_lib_agenda.py index 9a3f9e0d71..134fae9d22 100644 --- a/synapse/tests/test_lib_agenda.py +++ b/synapse/tests/test_lib_agenda.py @@ -434,6 +434,7 @@ def looptime(): # Can't use an existing authgate iden viewiden = core.getView().iden cdef = {'user': core.auth.rootuser.iden, + 'creator': core.auth.rootuser.iden, 'storm': '[test:str=bar]', 'reqs': {'hour': 10}, 'incunit': 'dayofweek', @@ -444,15 +445,6 @@ def looptime(): self.nn(core.getAuthGate(viewiden)) - with self.raises(s_exc.SchemaViolation): - s_schemas.reqValidCronDef({'storm': 'inet:fqdn'}) - - with self.raises(s_exc.SchemaViolation): - s_schemas.reqValidCronDef({'storm': 'inet:fqdn', 'creator': s_common.guid(), 'user': s_common.guid()}) - - s_schemas.reqValidCronDef({'storm': 'inet:fqdn', 'creator': s_common.guid()}) - s_schemas.reqValidCronDef({'storm': 'inet:fqdn', 'user': s_common.guid()}) - async def test_agenda_persistence(self): ''' Test we can make/change/delete appointments and they are persisted to storage ''' @@ -461,6 +453,7 @@ async def test_agenda_persistence(self): async with self.getTestCore(dirn=dirn) as core: cdef = {'user': core.auth.rootuser.iden, + 'creator': core.auth.rootuser.iden, 'storm': '[test:str=bar]', 'reqs': {'hour': 10, 'minute': 15}, 'incunit': 'dayofweek', @@ -470,6 +463,7 @@ async def test_agenda_persistence(self): # every 6th of the month at 7am and 8am (the 6th is a Thursday) cdef = {'user': core.auth.rootuser.iden, + 'creator': core.auth.rootuser.iden, 'storm': '[test:str=baz]', 'reqs': {'hour': (7, 8), 'minute': 0, 'dayofmonth': 6}, 'incunit': 'month', @@ -483,6 +477,7 @@ async def test_agenda_persistence(self): # Add an appt with an invalid query cdef = {'user': core.auth.rootuser.iden, + 'creator': core.auth.rootuser.iden, 'storm': '[test:str=', 'reqs': {'hour': (7, 8)}, 'incunit': 'month', @@ -497,7 +492,8 @@ async def test_agenda_persistence(self): await core.delCronJob(guid1) # And one-shots for Christmas and last day of Hanukkah of 2018 - cdef = {'user': core.auth.rootuser.iden, + cdef = {'creator': core.auth.rootuser.iden, + 'user': core.auth.rootuser.iden, 'storm': '#happyholidays', 'reqs': (xmas, lasthanu)} @@ -726,11 +722,7 @@ async def test_agenda_edit(self): q = '$cron = $lib.cron.get($iden) return ( $cron.set(creator, $lowuser) )' msgs = await core.stormlist(q, opts=opts) - self.stormIsInErr('must have permission cron.set.creator', msgs) - self.stormIsInWarn('Setting the cron job "creator" field is deprecated', msgs) - - cdef = await core.callStorm('for $cron in $lib.cron.list() { return($cron.set(creator, $lib.user.iden)) }') - self.eq(cdef['user'], core.auth.rootuser.iden) + self.stormIsInErr('CronJob does not support setting: creator', msgs) async def test_agenda_fatal_run(self): @@ -1015,7 +1007,8 @@ async def task(): q = '$q=$lib.queue.gen(test) for $i in $lib.range(60) { $lib.time.sleep(0.1) $q.put($i) }' guid = s_common.guid() cdef = { - 'user': core.auth.rootuser.iden, 'iden': guid, + 'creator': core.auth.rootuser.iden, 'iden': guid, + 'user': core.auth.rootuser.iden, 'storm': q, 'reqs': {'now': True} } @@ -1087,7 +1080,8 @@ async def task(): q = '$q=$lib.queue.gen(test) for $i in $lib.range(60) { $lib.time.sleep(0.1) $q.put($i) }' guid = s_common.guid() cdef = { - 'user': core00.auth.rootuser.iden, 'iden': guid, + 'creator': core00.auth.rootuser.iden, 'iden': guid, + 'user': core00.auth.rootuser.iden, 'storm': q, 'reqs': {'NOW': True}, 'pool': True, @@ -1120,70 +1114,27 @@ async def test_cron_creator_migration(self): async with self.getRegrCore('cron-creator-to-user') as core: cdef = await core.callStorm('for $cron in $lib.cron.list() { return($cron) }') self.eq(cdef['user'], core.auth.rootuser.iden) - self.none(cdef.get('creator')) - - async def test_cron_creator_nexus_compat(self): - with mock.patch('synapse.lib.cell.NEXUS_VERSION', (2, 177)): - async with self.getRegrCore('cron-creator-to-user') as core0: - with mock.patch('synapse.lib.cell.NEXUS_VERSION', (2, 193)): - - conf = {'mirror': core0.getLocalUrl()} - async with self.getRegrCore('cron-creator-to-user', conf=conf) as core1: - - lowuser = await core1.addUser('lowuser') - lowuser = lowuser.get('iden') - - indx = core0.nexsroot.nexslog.index() - await core1.sync() + self.eq(cdef['creator'], core.auth.rootuser.iden) - opts = {'vars': {'lowuser': lowuser}} - q = 'for $cron in $lib.cron.list() { return($cron.set(user, $lowuser)) }' - cdef = await core1.callStorm(q, opts=opts) - self.eq(cdef['user'], lowuser) - self.none(cdef.get('creator')) + async def test_cron_creator_mirror(self): + conf = {'mirror': 'cell:///newp'} + async with self.getRegrCore('cron-creator-to-user', conf=conf) as core: - await core1.sync() + apptdefs = core.cortexdata.getSubKeyVal('agenda:appt:') + for iden, info in apptdefs.items(): + self.none(info.get('user')) - evts = await s_t_utils.alist(core0.nexsroot.nexslog.iter(indx + 1)) - edit = [e[1] for e in evts if e[1][1] == 'cron:edit'] - self.len(1, edit) - self.eq(edit[0][2][1], 'creator') - - await core1.callStorm('cron.add --minute +2 { $lib.print(foo) }') - - evts = await s_t_utils.alist(core0.nexsroot.nexslog.iter(indx + 1)) - edit = [e[1] for e in evts if e[1][1] == 'cron:add'] - self.len(1, edit) - self.nn(edit[0][2][0].get('creator')) - self.none(edit[0][2][0].get('user')) - - async with self.getRegrCore('cron-creator-to-user') as core0: - conf = {'mirror': core0.getLocalUrl()} - async with self.getRegrCore('cron-creator-to-user', conf=conf) as core1: - - lowuser = await core1.addUser('lowuser') - lowuser = lowuser.get('iden') - - indx = core0.nexsroot.nexslog.index() - await core1.sync() - - opts = {'vars': {'lowuser': lowuser}} - q = 'for $cron in $lib.cron.list() { return($cron.set(user, $lowuser)) }' - cdef = await core1.callStorm(q, opts=opts) - self.eq(cdef['user'], lowuser) - self.none(cdef.get('creator')) - - await core1.sync() - - evts = await s_t_utils.alist(core0.nexsroot.nexslog.iter(indx + 1)) - edit = [e[1] for e in evts if e[1][1] == 'cron:edit'] - self.len(1, edit) - self.eq(edit[0][2][1], 'user') + q = 'for $cron in $lib.cron.list() { return($cron) }' + cdef = await core.callStorm(q) + self.eq(cdef['user'], core.auth.rootuser.iden) + self.eq(cdef['creator'], core.auth.rootuser.iden) + await core.promote(graceful=False) - await core1.callStorm('cron.add --minute +2 { $lib.print(foo) }') + apptdefs = core.cortexdata.getSubKeyVal('agenda:appt:') + for iden, info in apptdefs.items(): + self.nn(info.get('user')) - evts = await s_t_utils.alist(core0.nexsroot.nexslog.iter(indx + 1)) - edit = [e[1] for e in evts if e[1][1] == 'cron:add'] - self.len(1, edit) - self.nn(edit[0][2][0].get('user')) - self.none(edit[0][2][0].get('creator')) + q = 'for $cron in $lib.cron.list() { return($cron) }' + cdef = await core.callStorm(q) + self.eq(cdef['user'], core.auth.rootuser.iden) + self.eq(cdef['creator'], core.auth.rootuser.iden) diff --git a/synapse/tests/test_lib_cell.py b/synapse/tests/test_lib_cell.py index bf13641997..7fb3c4b3c6 100644 --- a/synapse/tests/test_lib_cell.py +++ b/synapse/tests/test_lib_cell.py @@ -3080,7 +3080,7 @@ async def test_cell_hive_migration(self): self.stormIsInPrint('0973342044469bc40b577969028c5079: (foodmon ): running', msgs) msgs = await core.stormlist('trigger.list') - self.stormIsInPrint('visi 27f5dc524e7c3ee8685816ddf6ca1326', msgs) + self.stormIsInPrint('visi 27f5dc524e7c3ee8685816ddf6ca1326', msgs) self.stormIsInPrint('[ +#count test:str=$tag ]', msgs) msgs = await core.stormlist('testcmd0 foo') diff --git a/synapse/tests/test_lib_stormtypes.py b/synapse/tests/test_lib_stormtypes.py index f74642ddac..c4742bff1e 100644 --- a/synapse/tests/test_lib_stormtypes.py +++ b/synapse/tests/test_lib_stormtypes.py @@ -4325,12 +4325,14 @@ async def test_storm_lib_trigger_async_regression(self): tdef = await core.callStorm('return ( $lib.trigger.get(bc1cbf350d151bba5936e6654dd13ff5) )') self.notin('async', tdef) + view = view[:8] + msgs = await core.stormlist('trigger.list') self.stormHasNoWarnErr(msgs) - trgs = ('iden view en? async? cond object', - f'8af9a5b134d08fded3edb667f8d8bbc2 {view} true true tag:add inet:ipv4', - f'99b637036016dadd6db513552a1174b8 {view} true false tag:add ', - f'bc1cbf350d151bba5936e6654dd13ff5 {view} true false node:add inet:ipv4', + trgs = ('iden view en? async? cond object', + f'8af9a5b134d08fded3edb667f8d8bbc2 {view}... Y Y tag:add inet:ipv4#aka', + f'99b637036016dadd6db513552a1174b8 {view}... Y N tag:add #aka ', + f'bc1cbf350d151bba5936e6654dd13ff5 {view}... Y N node:add inet:ipv4', ) for m in trgs: self.stormIsInPrint(m, msgs) @@ -4532,8 +4534,8 @@ async def test_storm_lib_trigger(self): await core.nodes('trigger.add tag:add --view $view --tag neato.* --query {[ +#awesome ]}', opts={'vars': forkopts}) mesgs = await core.stormlist('trigger.list', opts=forkopts) nodes = await core.nodes('syn:trigger', opts=forkopts) - self.stormNotInPrint(mainview, mesgs) - self.stormIsInPrint(forkview, mesgs) + self.stormNotInPrint(mainview[:8], mesgs) + self.stormIsInPrint(forkview[:8], mesgs) self.len(1, nodes) othr = nodes[0].ndef[1] self.nn(nodes[0].props.get('.created')) diff --git a/synapse/tests/test_lib_trigger.py b/synapse/tests/test_lib_trigger.py index c51ea9cf96..76643baf3b 100644 --- a/synapse/tests/test_lib_trigger.py +++ b/synapse/tests/test_lib_trigger.py @@ -20,7 +20,7 @@ async def test_trigger_async(self): self.none(nodes[0].tags.get('foo')) msgs = await core.stormlist('trigger.list') - self.stormIsInPrint('true true node:add inet:ipv4', msgs) + self.stormIsInPrint('Y Y node:add inet:ipv4', msgs) self.nn(await core.callStorm('return($lib.queue.gen(foo).pop(wait=$lib.true))')) nodes = await core.nodes('inet:ipv4=1.2.3.4') @@ -784,6 +784,12 @@ async def test_trigger_edges(self): self.isin('cupcake', node[0].tags) # the other two edge:del triggers cannot run because we can't get to n2 anymore + msgs = await core.stormlist('trigger.list --all') + self.stormIsInPrint('edge:del * -(refs)> *', msgs) + self.stormIsInPrint('edge:del test:int -(refs)> *', msgs) + self.stormIsInPrint('edge:del * -(refs)> test:int', msgs) + self.stormIsInPrint('edge:del test:int -(refs)> test:int', msgs) + await core.nodes('for $trig in $lib.trigger.list() { $lib.trigger.del($trig.iden) }', opts=opts) self.len(0, await core.nodes('syn:trigger', opts=opts)) diff --git a/synapse/tests/test_model_syn.py b/synapse/tests/test_model_syn.py index 28565e1425..92182aee1d 100644 --- a/synapse/tests/test_model_syn.py +++ b/synapse/tests/test_model_syn.py @@ -726,7 +726,7 @@ async def test_syn_cron_runts(self): visi = await core.addUser('visi') - cdef = {'storm': 'inet:ipv4', 'reqs': {'hour': 2}, 'creator': visi.get('iden')} + cdef = {'storm': 'inet:ipv4', 'reqs': {'hour': 2}, 'creator': visi.get('iden'), 'user': visi.get('iden')} adef = await core.addCronJob(cdef) iden = adef.get('iden')