def test_operating_env_init_no_args(): env = ace.env.ACEOperatingEnvironment("") assert env.get_uri() is None assert env.get_api_key() is None # the test environment uses a temporary directory for the base dir # so this assertion doesn't work # assert env.get_base_dir() == ace.env.get_default_base_dir() assert env.get_package_dir() == os.path.join(env.get_base_dir(), "packages") assert isinstance(env.get_package_manager(), ACEPackageManager)
def test_operating_env_init_env_args(monkeypatch): monkeypatch.setenv("ACE_URI", "http://test") monkeypatch.setenv("ACE_API_KEY", "test") monkeypatch.setenv("ACE_BASE_DIR", "/opt/ace") monkeypatch.setenv("ACE_PACKAGE_DIR", "/opt/ace/test/packages") env = ace.env.ACEOperatingEnvironment("") assert env.get_uri() == "http://test" assert env.get_api_key() == "test" assert env.get_base_dir() == "/opt/ace" assert env.get_package_dir() == "/opt/ace/test/packages"
def test_shortcut_functions(monkeypatch): monkeypatch.setenv("ACE_URI", "http://test") monkeypatch.setenv("ACE_API_KEY", "test") monkeypatch.setenv("ACE_BASE_DIR", "/opt/ace") monkeypatch.setenv("ACE_PACKAGE_DIR", "/opt/ace/test/packages") register_global_env(ace.env.ACEOperatingEnvironment("")) assert ace.env.get_uri() == get_uri() assert ace.env.get_api_key() == get_api_key() assert ace.env.get_base_dir() == get_base_dir() assert ace.env.get_package_dir() == get_package_dir() assert ace.env.get_package_manager() == get_package_manager()
async def run(self): from ace.env import get_uri, get_api_key # XXX uri = get_uri() api_key = get_api_key() if not uri: raise RuntimeError("missing remote uri") if not api_key: raise RuntimeError("missing api key") manager = AnalysisModuleManager(RemoteACESystem(uri, api_key)) manager.load_modules() task = asyncio.create_task(manager.run()) await self.shutdown_event.wait() manager.stop() await task
async def analyze(args): if len(args.targets) % 2 != 0: get_logger().error( "odd number of arguments (you need pairs of type and value)") return False targets = args.targets # did we specify targets from stdin? if args.from_stdin: for o_value in sys.stdin: # the type of observables coming in on stdin is also specified on the command line targets.append(args.stdin_type) targets.append(o_value.strip()) is_local = True uri = get_uri() api_key = get_api_key() if uri and api_key: is_local = False system = RemoteACESystem(uri, api_key) else: system = CommandLineSystem() system.storage_root = tempfile.mkdtemp() await system.initialize() # TODO move this to the system if is_local: await system.create_database() manager = AnalysisModuleManager(system, type(system), (system.db_url, ), concurrency_mode=CONCURRENCY_MODE_PROCESS) manager.load_modules() if not manager.analysis_modules: get_logger().error("no modules loaded") return False if is_local: for module in manager.analysis_modules: await system.register_analysis_module_type(module.type) root = system.new_root() if args.analysis_mode: root.analysis_mode = args.analysis_mode index = 0 while index < len(args.targets): o_type = args.targets[index] o_value = args.targets[index + 1] # TODO if you add a file then add_observable should call add_file if o_type == "file": await root.add_file(o_value) else: root.add_observable(o_type, o_value) index += 2 await root.submit() await manager.run_once() root = await system.get_root_analysis(root) display_analysis(root) return True