async def runCmdOpts(self, opts): s_common.deprecated('cmdr> trigger') line = opts.get('line') if line is None: self.printf(self.__doc__) return core = self.getCmdItem() argv = s_parser.Parser(line).cmdrargs() try: opts = self._make_argparser().parse_args(argv) except s_exc.ParserExit: return handlers = { 'add': self._handle_add, 'del': self._handle_del, 'disable': self._handle_disable, 'enable': self._handle_enable, 'list': self._handle_list, 'mod': self._handle_mod, } await handlers[opts.cmd](core, opts)
async def getAuthInfo(self, name): s_common.deprecated('getAuthInfo') user = await self.cell.auth.getUserByName(name) if user is not None: info = user.pack() info['roles'] = [ self.cell.auth.role(r).name for r in info['roles'] ] return info role = await self.cell.auth.getRoleByName(name) if role is not None: return role.pack() raise s_exc.NoSuchName(name=name)
async def __call__(self, text, ptype=None, refang=True, unique=True): text = await s_stormtypes.tostr(text) form = await s_stormtypes.tostr(ptype, noneok=True) refang = await s_stormtypes.tobool(refang) unique = await s_stormtypes.tobool(unique) # Remove this in 3.0.0 since it is deprecated. s_common.deprecated('$lib.scrape()') await self.runt.warnonce( '$lib.scrape() is deprecated. Use $lib.scrape.ndefs().') async with await s_spooled.Set.anit() as items: # type: s_spooled.Set for item in s_scrape.scrape(text, ptype=form, refang=refang, first=False): if unique: if item in items: continue await items.add(item) yield item await asyncio.sleep(0)
async def runCmdOpts(self, opts): s_common.deprecated('cmdr> at') line = opts.get('line') if line is None: self.printf(self.__doc__) return core = self.getCmdItem() argv = s_parser.Parser(line).cmdrargs() # Currently, using an argparser is overkill for this command. Using for future extensibility (and help). try: opts = self._make_argparser().parse_args(argv) except s_exc.ParserExit: return query = None consumed_next = False tslist = [] # TODO: retrieve time from cortex in case of wrong cmdr time now = time.time() for pos, arg in enumerate(opts.args): try: if consumed_next: consumed_next = False continue if arg.startswith('{'): if query is not None: self.printf('Error: only a single query is allowed') return query = arg[1:-1] continue if arg.startswith('+'): if arg[-1].isdigit(): if pos == len(opts.args) - 1: self.printf('Time delta missing unit') return arg = f'{arg} {opts.args[pos + 1]}' consumed_next = True ts = now + s_time.delta(arg) / 1000.0 tslist.append(ts) continue ts = s_time.parse(arg) / 1000.0 tslist.append(ts) except (ValueError, s_exc.BadTypeValu): self.printf(f'Error: Trouble parsing "{arg}"') return if query is None: self.printf('Error: Missing query argument') return def _ts_to_reqdict(ts): dt = datetime.datetime.fromtimestamp(ts, datetime.timezone.utc) return { 'minute': dt.minute, 'hour': dt.hour, 'dayofmonth': dt.day, 'month': dt.month, 'year': dt.year } if not tslist: self.printf('Error: at least one requirement must be provided') return reqdicts = [_ts_to_reqdict(ts) for ts in tslist] cdef = {'storm': query, 'reqs': reqdicts, 'incunit': None, 'incvals': None, } newcdef = await core.addCronJob(cdef) self.printf(f'Created cron job {newcdef["iden"]}')
async def setAuthAdmin(self, name, isadmin): s_common.deprecated('setAuthAdmin') item = await self.cell.auth.getUserByName(name) if item is None: item = await self.cell.auth.getRoleByName(name) await item.setAdmin(isadmin)
async def delAuthRule(self, name, rule, gateiden=None): s_common.deprecated('delAuthRule') item = await self.cell.auth.getUserByName(name) if item is None: item = await self.cell.auth.getRoleByName(name) await item.delRule(rule, gateiden=gateiden)