|
| 1 | +""" |
| 2 | +Copyright (C) 2021 Clariteia SL |
| 3 | +
|
| 4 | +This file is part of minos framework. |
| 5 | +
|
| 6 | +Minos framework can not be copied and/or distributed without the express permission of Clariteia SL. |
| 7 | +""" |
| 8 | +from pathlib import ( |
| 9 | + Path, |
| 10 | +) |
| 11 | +from typing import ( |
| 12 | + Optional, |
| 13 | +) |
| 14 | + |
| 15 | +import typer |
| 16 | + |
| 17 | +from minos.api_gateway.common import ( |
| 18 | + MinosConfig, |
| 19 | +) |
| 20 | +from minos.api_gateway.rest.launchers import ( |
| 21 | + EntrypointLauncher, |
| 22 | +) |
| 23 | +from minos.api_gateway.rest.service import ( |
| 24 | + ApiGatewayRestService, |
| 25 | +) |
| 26 | + |
| 27 | +app = typer.Typer() |
| 28 | + |
| 29 | + |
| 30 | +@app.command("start") |
| 31 | +def start( |
| 32 | + file_path: Optional[Path] = typer.Argument( |
| 33 | + "config.yml", help="API Gateway configuration file.", envvar="MINOS_API_GATEWAY_CONFIG_FILE_PATH" |
| 34 | + ) |
| 35 | +): # pragma: no cover |
| 36 | + """Start Api Gateway services.""" |
| 37 | + |
| 38 | + try: |
| 39 | + config = MinosConfig(file_path) |
| 40 | + except Exception as exc: |
| 41 | + typer.echo(f"Error loading config: {exc!r}") |
| 42 | + raise typer.Exit(code=1) |
| 43 | + |
| 44 | + services = (ApiGatewayRestService(config=config),) |
| 45 | + try: |
| 46 | + EntrypointLauncher(config=config, services=services).launch() |
| 47 | + except Exception as exc: |
| 48 | + typer.echo(f"Error launching Api Gateway: {exc!r}") |
| 49 | + raise typer.Exit(code=1) |
| 50 | + |
| 51 | + typer.echo("Api Gateway is up and running!\n") |
| 52 | + |
| 53 | + |
| 54 | +@app.command("status") |
| 55 | +def status(): |
| 56 | + """Get the Api Gateway status.""" |
| 57 | + raise NotImplementedError |
| 58 | + |
| 59 | + |
| 60 | +@app.command("stop") |
| 61 | +def stop(): |
| 62 | + """Stop the Api Gateway.""" |
| 63 | + raise NotImplementedError |
| 64 | + |
| 65 | + |
| 66 | +def main(): # pragma: no cover |
| 67 | + """CLI's main function.""" |
| 68 | + app() |
0 commit comments