async def addTrigger(self, tdef): ''' Adds a trigger to the view. ''' tdef['iden'] = s_common.guid() root = await self.core.auth.getUserByName('root') tdef.setdefault('user', root.iden) tdef.setdefault('enabled', True) s_trigger.reqValidTdef(tdef) return await self._push('trigger:add', tdef)
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() user = self.core.auth.user(tdef['user']) self.core.getStormQuery(tdef['storm']) trig = self.triggers.load(tdef) await self.trigdict.set(trig.iden, tdef) await self.core.auth.addAuthGate(trig.iden, 'trigger') await user.setAdmin(True, gateiden=tdef.get('iden'), logged=False) return trig.pack()
async def addTrigger(self, tdef): ''' Adds a trigger to the view. ''' iden = tdef.get('iden') if iden is None: tdef['iden'] = s_common.guid() elif self.triggers.get(iden) is not None: raise s_exc.DupIden(mesg='A trigger with this iden already exists') root = await self.core.auth.getUserByName('root') tdef.setdefault('user', root.iden) tdef.setdefault('enabled', True) s_trigger.reqValidTdef(tdef) return await self._push('trigger:add', tdef)
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() gate = self.core.auth.getAuthGate(tdef['iden']) if gate is not None: raise s_exc.DupIden(mesg='An AuthGate with this iden already exists') user = self.core.auth.user(tdef['user']) await self.core.getStormQuery(tdef['storm']) trig = await self.triggers.load(tdef) await self.trigdict.set(trig.iden, tdef) await self.core.auth.addAuthGate(trig.iden, 'trigger') await user.setAdmin(True, gateiden=tdef.get('iden'), logged=False) return trig.pack()