def config_fixture(fallback_authn_enabled=False, edl_username='******', edl_password='******', use_localstack=False, staging_bucket='UNKNOWN', staging_path='UNKNOWN', oauth_client_id=None): c = util.config(validate=False) return util.Config( # Override fallback_authn_enabled=fallback_authn_enabled, edl_username=edl_username, edl_password=edl_password, use_localstack=use_localstack, staging_path=staging_path, staging_bucket=staging_bucket, oauth_client_id=oauth_client_id, # Default env=c.env, app_name=c.app_name, oauth_host=c.oauth_host, oauth_uid=c.oauth_uid, oauth_password=c.oauth_password, oauth_redirect_uri=c.oauth_redirect_uri, backend_host=c.backend_host, localstack_host=c.localstack_host, aws_default_region=c.aws_default_region, text_logger=c.text_logger, health_check_path=c.health_check_path, shared_secret_key=c.shared_secret_key, )
def run_cli(parser, args, AdapterClass, cfg=None): """ Runs the Harmony CLI invocation captured by the given args Parameters ---------- parser : argparse.ArgumentParser The parser being used to parse CLI arguments, used to provide CLI argument errors args : Namespace Argument values parsed from the command line, presumably via ArgumentParser.parse_args AdapterClass : class The BaseHarmonyAdapter subclass to use to handle service invocations cfg : harmony.util.Config A configuration instance for this service """ if cfg is None: cfg = config() if args.harmony_wrap_stdout: setup_stdout_log_formatting(cfg) if args.harmony_action == 'invoke': start_time = datetime.datetime.now() if not bool(args.harmony_input): parser.error( '--harmony-input must be provided for --harmony-action=invoke') elif not bool(args.harmony_sources): successful = _invoke_deprecated(AdapterClass, args.harmony_input, cfg) if not successful: raise Exception('Service operation failed') else: try: adapter = _build_adapter(AdapterClass, args.harmony_input, args.harmony_sources, args.harmony_data_location, cfg) adapter.logger.info(f'timing.{cfg.app_name}.start') _invoke(adapter, args.harmony_metadata_dir) finally: time_diff = datetime.datetime.now() - start_time duration_ms = int(round(time_diff.total_seconds() * 1000)) duration_logger = build_logger(cfg) extra_fields = { 'user': adapter.message.user, 'requestId': adapter.message.requestId, 'durationMs': duration_ms } duration_logger.info(f'timing.{cfg.app_name}.end', extra=extra_fields) if args.harmony_action == 'start': if not bool(args.harmony_queue_url): parser.error( '--harmony-queue-url must be provided for --harmony-action=start' ) else: return _start(AdapterClass, args.harmony_queue_url, args.harmony_visibility_timeout, cfg)
def setUp(self): self.config = util.config(validate=False)