Esempio n. 1
0
 async def task(self, abilities, obfuscator, facts=(), deadman=False):
     bps = BasePlanningService()
     potential_links = [Link.load(dict(command=i.test, paw=self.paw, ability=i, deadman=deadman)) for i in await self.capabilities(abilities)]
     links = []
     for valid in await bps.remove_links_missing_facts(
             await bps.add_test_variants(links=potential_links, agent=self, facts=facts)):
         links.append(valid)
     links = await bps.obfuscate_commands(self, obfuscator, links)
     self.links.extend(links)
     return links
Esempio n. 2
0
 async def task(self, abilities, facts=(), operation='task'):
     bps = BasePlanningService()
     potential_links = [
         Link(operation=operation, command=i.test, paw=self.paw, ability=i)
         for i in await self.capabilities(abilities)
     ]
     links = []
     for valid in await bps.remove_links_missing_facts(
             await bps.add_test_variants(links=potential_links,
                                         agent=self,
                                         facts=facts)):
         links.append(valid)
     self.links.extend(links)
     return links
Esempio n. 3
0
    async def task(self, abilities, obfuscator, facts=(), deadman=False):
        if not self.executors:
            return []

        bps = BasePlanningService()
        preferred_executor_name = self._get_preferred_executor_name()

        links = []
        for ability in await self.capabilities(abilities):
            executors = ability.find_executors(self.executors, self.platform)
            executors = sorted(
                executors,
                key=lambda ex: ex.name == preferred_executor_name,
                reverse=True)

            for executor in executors:
                ex_links = [
                    Link.load(
                        dict(command=self.encode_string(executor.test),
                             paw=self.paw,
                             ability=ability,
                             executor=executor,
                             deadman=deadman))
                ]
                valid_links = await bps.add_test_variants(
                    links=ex_links,
                    agent=self,
                    facts=facts,
                    trim_unset_variables=True)
                if valid_links:
                    links.extend(valid_links)
                    break

        links = await bps.obfuscate_commands(self, obfuscator, links)
        knowledge_svc_handle = BaseService.get_service('knowledge_svc')
        for fact in facts:
            fact.source = self.paw
            fact.origin_type = OriginType.SEEDED
            await knowledge_svc_handle.add_fact(fact)
        self.links.extend(links)
        return links