Esempio n. 1
0
 def execute_remove(self, settings: CLISettings) -> None:
     if not self.module:
         raise CommandError("Which module you are remove is required", 2)
     config = settings.get_persistent_config()
     if self.module not in config.extensions:
         raise CommandError(f"You haven't added {self.module}", 2)
     config.extensions.remove(self.module)
     settings.set_persistent_config(config)
Esempio n. 2
0
 def execute_list(self, settings: CLISettings) -> None:
     if self.module:
         manifest = self.get_manifest(self.module)
         self.print_extension(manifest)
         return
     for module_name in sorted(settings.get_persistent_config().extensions):
         print(module_name)
         manifest = self.get_manifest(module_name)
         self.print_extension(manifest, indent=2)
Esempio n. 3
0
    def execute_add(self, settings: CLISettings) -> None:
        if not self.module:
            raise CommandError("module is required", 2)
        if self.module in settings.get_persistent_config().extensions:
            self.execute_list(settings)
            return

        manifest = self.get_manifest(self.module)

        # Validate our new setups by pretending to create a new mapping with the new classes
        content_and_settings = tx_meta.SignalTypeMapping(
            list(
                itertools.chain(settings.get_all_content_types(),
                                manifest.content_types)),
            list(
                itertools.chain(settings.get_all_signal_types(),
                                manifest.signal_types)),
        )

        # For APIs, we also need to make sure they can be instanciated without args for the CLI
        apis = []
        for new_api in manifest.apis:
            try:
                instance = new_api()
            except Exception as e:
                logging.exception(
                    f"Failed to instanciante API {new_api.get_name()}")
                raise CommandError(
                    f"Not able to instanciate API {new_api.get_name()} - throws {e}"
                )
            apis.append(instance)
        apis.extend(settings.apis.get_all())
        tx_meta.FetcherMapping(apis)

        self.execute_list(settings)

        config = settings.get_persistent_config()
        config.extensions.add(self.module)
        settings.set_persistent_config(config)
Esempio n. 4
0
 def execute(self, settings: CLISettings) -> None:
     if self.credentials is not None:
         config = settings.get_persistent_config()
         config.ncmec_credentials = self.credentials
         settings.set_persistent_config(config)
Esempio n. 5
0
 def execute_config(self, settings: CLISettings) -> None:
     if self.api_token is not None:
         config = settings.get_persistent_config()
         config.fb_threatexchange_api_token = self.api_token
         settings.set_persistent_config(config)