def cli(ctx, debug, verbose, no_traverse_manifest): ctx.ensure_object(dict) if not is_running_latest(): print_msg(UPGRADE_WARNING_OUTPUT) if not is_running_supported_python3(): print_error("Please upgrade to python3.6 to run r2c-cli.") set_debug_flag(ctx, debug) set_verbose_flag(ctx, verbose) ctx.obj["NO_TRAVERSE_MANIFEST"] = no_traverse_manifest
def load_params(params: str) -> Dict: try: parameter_obj = json.loads(params) except ValueError as e: print_error( f'Failed to parse parameter string:"{params}" as json. Parse Error: {e}' ) parameter_obj = {} return parameter_obj
def check_valid_token_with_logging(org: str, token: str) -> Optional[str]: valid_token = validate_token(org, token) if valid_token: # save to ~/.r2c save_config_creds(org, token) if org == PLATFORM_ANALYZER_PREFIX: print_success(f"You are now logged in to the r2c platform 🎉") else: print_success(f"You are now logged in to: {org} 🎉") return token else: print_error( "Couldn't log you in with that token. Please check your input and try again" ) return None
def test(ctx, analyzer_directory, which, cache, env_args_string): """ Locally run tests for the current analyzer. You can add integration test files to the `examples/` directory. For more information, refer to the integration test section of the README. For unittests, you can define how to run your unit tests in `src/unittest.sh`. You may have to login if your analyzer depends on privately published analyzers. """ verbose = ctx.obj["VERBOSE"] env_args_dict = parse_remaining(env_args_string) print_msg( f"Running integration tests for analyzer {'with debug mode' if ctx.obj['DEBUG'] else ''}" ) manifest, analyzer_directory = find_and_open_analyzer_manifest( analyzer_directory, ctx ) check_docker_is_running() print_msg("🔨 Building docker container") abort_on_build_failure( build_docker( manifest.analyzer_name, manifest.version, os.path.relpath(analyzer_directory, os.getcwd()), env_args_dict=env_args_dict, ) ) if which == "unit" or which == "all": image_id = VersionedAnalyzer(manifest.analyzer_name, manifest.version).image_id status = run_docker_unittest( analyzer_directory=analyzer_directory, analyzer_name=manifest.analyzer_name, docker_image=image_id, verbose=verbose, env_args_dict=env_args_dict, ) if status == 0: print_success(f"Unit tests passed") else: print_error(f"Unit tests failed with status {status}") if which == "integration" or which == "all": try: passed_all = integration_test( manifest=manifest, analyzer_directory=analyzer_directory, workdir=None, verbose=verbose, env_args_dict=env_args_dict, registry_data=get_registry_data(), use_cache=cache, ) if passed_all: print_success(f"All integration tests passed") else: print_error_exit(f"Some integration tests failed", status_code=-1) except SymlinkNeedsElevationError as sym: print_error( f"Error setting up integration tests. {sym}. Try again as an admin" )