in connectors/service_cli.py [0:0]
def run(action, config_file, log_level, filebeat, service_type, uvloop):
"""Loads the config file, sets the logger and executes an action.
Actions:
- list: prints out a list of all connectors and exits
- poll: starts the event loop and run forever (default)
"""
logger.info(f"Running connector service version {__version__}")
# load config
config = {}
try:
config = load_config(config_file)
ContentExtraction.set_extraction_config(
config.get("extraction_service", None)
) # Not perfect, let's revisit
except Exception as e:
# If something goes wrong while parsing config file, we still want
# to set up the logger so that Cloud deployments report errors to
# logs properly
set_logger(logging.INFO, filebeat=filebeat)
msg = f"Could not parse {config_file}. Check logs for more information"
logger.exception(f"{msg}.\n{e}")
raise ClickException(msg) from e
# Precedence: CLI args >> Config Setting >> INFO
set_logger(
log_level or config["service"]["log_level"] or logging.INFO,
filebeat=filebeat,
)
# just display the list of connectors
if action == ("list",):
print("Registered connectors:") # noqa: T201
for source in get_source_klasses(config):
print(f"- {source.name}") # noqa: T201
print("Bye") # noqa: T201
return 0
if action == ("config",):
print( # noqa: T201
f"Getting default configuration for service type {service_type}"
)
source_list = config["sources"]
if service_type not in source_list:
msg = f"Could not find a connector for service type {service_type}"
raise UsageError(msg)
source_klass = get_source_klass(source_list[service_type])
print( # noqa: T201
json.dumps(source_klass.get_simple_configuration(), indent=2)
)
print("Bye") # noqa: T201
return 0
if "list" in action:
msg = "Cannot use the `list` action with other actions"
raise UsageError(msg)
if "config" in action:
msg = "Cannot use the `config` action with other actions"
raise UsageError(msg)
loop = get_event_loop(uvloop)
coro = _start_service(action, config, loop)
try:
return loop.run_until_complete(coro)
except asyncio.CancelledError:
return 0
finally:
logger.info("Bye")