async def get_base_repo(self) -> dict:
        executors = [
            f"{executor}" for executor in os.listdir(executor_folder())
            if re.match("(.*_manifest.json|__pycache__)", executor) is None
        ]

        executors_names = list(
            map(
                lambda x: re.search(r"(^[a-zA-Z0-9_-]+)(?:\..*)*$", x).group(
                    1), executors))

        async def control_base_repo(chosen_option: str) -> Optional[dict]:
            metadata = executor_metadata(chosen_option)
            try:
                if not check_metadata(metadata):
                    click.secho(f"Invalid manifest for: {chosen_option}",
                                fg="yellow")
                else:
                    if not await check_commands(metadata):
                        print(f"{Bcolors.WARNING}Invalid bash dependency for"
                              f" {Bcolors.BOLD}{chosen_option}{Bcolors.ENDC}"
                              f"")
                    else:
                        return metadata
            except FileNotFoundError:
                click.secho(f"Not existent manifest for: {chosen_option}",
                            fg="yellow")
            return None

        return await choice_paged_option(executors_names, self.PAGE_SIZE,
                                         control_base_repo)
Example #2
0
    async def get_base_repo(self) -> dict:
        executors = [
            f"{executor}"
            for executor in os.listdir(executor_folder())
            if re.match("(.*_manifest.json|__pycache__)", executor) is None
        ]

        async def control_base_repo(chosen_option: str) -> Optional[dict]:
            metadata = executor_metadata(chosen_option)
            try:
                if not check_metadata(metadata):
                    print(f"{Bcolors.WARNING}Invalid manifest for " f"{Bcolors.BOLD}{chosen_option}{Bcolors.ENDC}")
                else:
                    if not await check_commands(metadata):
                        print(
                            f"{Bcolors.WARNING}Invalid bash dependency for"
                            f" {Bcolors.BOLD}{chosen_option}{Bcolors.ENDC}"
                            f""
                        )
                    else:
                        metadata["name"] = chosen_option
                        return metadata
            except FileNotFoundError:
                print(f"{Bcolors.WARNING}Not existent manifest for " f"{Bcolors.BOLD}{chosen_option}{Bcolors.ENDC}")
            return None

        return await choice_paged_option(executors, self.PAGE_SIZE, control_base_repo)
def test_imports():
    folder = executor_folder()
    modules = [
        f"{Path(module).stem}" for module in os.listdir(folder)
        if re.match(r".*\.py", module) is not None
    ]
    error_message = ""
    for module in modules:
        try:
            importlib.import_module(
                f"faraday_agent_dispatcher.static.executors.official.{module}")
        except ImportError:
            error_message = f"{error_message}Can't import {module}\n"

    assert len(error_message) == 0, error_message
    def __init__(self, name: str, config):
        name = name.strip()
        self.control_config(name, config)
        self.name = name
        self.repo_executor = config.get("repo_executor")
        if self.repo_executor:
            self.repo_name = re.search(r"(^[a-zA-Z0-9_-]+)(?:\..*)*$",
                                       self.repo_executor).group(1)
            metadata = executor_metadata(self.repo_name)
            repo_path = executor_folder() / self.repo_executor
            self.cmd = metadata["cmd"].format(EXECUTOR_FILE_PATH=repo_path)
        else:
            self.cmd = config.get("cmd")

        self.max_size = int(config.get("max_size", 64 * 1024))
        self.params = dict(config[Sections.EXECUTOR_PARAMS]
                           ) if Sections.EXECUTOR_PARAMS in config else {}
        self.varenvs = dict(config[Sections.EXECUTOR_VARENVS]
                            ) if Sections.EXECUTOR_VARENVS in config else {}
    def __init__(self, name: str, config):
        name = name.strip()
        self.control_config(name, config)
        self.name = name
        executor_section = Sections.EXECUTOR_DATA.format(name)
        params_section = Sections.EXECUTOR_PARAMS.format(name)
        varenvs_section = Sections.EXECUTOR_VARENVS.format(name)
        self.repo_name = config[executor_section].get("repo_executor", None)
        if self.repo_name:
            metadata = executor_metadata(self.repo_name)
            repo_path = executor_folder() / self.repo_name
            self.cmd = metadata["cmd"].format(EXECUTOR_FILE_PATH=repo_path)
        else:
            self.cmd = config[executor_section].get("cmd")

        self.max_size = int(config[executor_section].get("max_size", 64 * 1024))
        self.params = dict(config[params_section]) if params_section in config else {}
        self.params = {key: value.lower() in ["t", "true"] for key, value in self.params.items()}
        self.varenvs = dict(config[varenvs_section]) if varenvs_section in config else {}
def test_no_path_varenv_in_manifests():
    folder = executor_folder()
    modules = [
        f"{Path(module).stem}" for module in os.listdir(folder)
        if re.match(r".*\.py", module) is not None
    ]

    error_message = ""
    for module in modules:
        try:
            metadata = executor_metadata(module)
            if not full_check_metadata(metadata):
                error_message = f"{error_message}Not all manifest keys in " f"manifest for {module}\n"
            if "environment_variables" in metadata:
                if "PATH" in metadata["environment_variables"]:
                    error_message = f"{error_message}Overriding PATH " f"environment variable in {module}\n"

        except FileNotFoundError:
            error_message = f"{error_message}Can't found manifest file for " f"{module}\n"

    assert len(error_message) == 0, error_message