diff --git a/api.md b/api.md index d4179510b..2c45fdbc2 100644 --- a/api.md +++ b/api.md @@ -534,6 +534,28 @@ Stop service on-chain +--- +#### `GET /api/services/{service}/deployment` + +
+ Response + +```json +{ + "status": 1, + "nodes": { + "agent": [ + "traderomengnosis_abci_0" + ], + "tendermint": [ + "traderomengnosis_tm_0" + ] + } +} +``` + +
+ --- #### `POST /api/services/{service}/deployment/build` diff --git a/operate/cli.py b/operate/cli.py index 1885302fd..a6daeadcd 100644 --- a/operate/cli.py +++ b/operate/cli.py @@ -135,7 +135,7 @@ def create_app( # pylint: disable=too-many-locals, unused-argument, too-many-st def with_retries(f: t.Callable) -> t.Callable: """Retries decorator.""" - async def _call(request: Request) -> t.Dict: + async def _call(request: Request) -> JSONResponse: """Call the endpoint.""" logger.info(f"Calling `{f.__name__}` with retries enabled") retries = 0 @@ -155,7 +155,7 @@ async def _call(request: Request) -> t.Dict: @app.get("/api") @with_retries - async def _get_api(request: Request) -> t.Dict: + async def _get_api(request: Request) -> JSONResponse: """Get API info.""" return JSONResponse(content=operate.json) @@ -299,13 +299,13 @@ async def _create_safe(request: Request) -> t.List[t.Dict]: @app.get("/api/services") @with_retries - async def _get_services(request: Request) -> t.List[t.Dict]: + async def _get_services(request: Request) -> JSONResponse: """Get available services.""" return JSONResponse(content=operate.service_manager().json) @app.post("/api/services") @with_retries - async def _create_services(request: Request) -> t.Dict: + async def _create_services(request: Request) -> JSONResponse: """Create a service.""" if operate.password is None: return USER_NOT_LOGGED_IN_ERROR @@ -328,7 +328,7 @@ async def _create_services(request: Request) -> t.Dict: @app.put("/api/services") @with_retries - async def _update_services(request: Request) -> t.Dict: + async def _update_services(request: Request) -> JSONResponse: """Create a service.""" if operate.password is None: return USER_NOT_LOGGED_IN_ERROR @@ -346,7 +346,7 @@ async def _update_services(request: Request) -> t.Dict: @app.get("/api/services/{service}") @with_retries - async def _get_service(request: Request) -> t.Dict: + async def _get_service(request: Request) -> JSONResponse: """Create a service.""" return JSONResponse( content=( @@ -360,7 +360,7 @@ async def _get_service(request: Request) -> t.Dict: @app.post("/api/services/{service}/onchain/deploy") @with_retries - async def _deploy_service_onchain(request: Request) -> t.Dict: + async def _deploy_service_onchain(request: Request) -> JSONResponse: """Create a service.""" if operate.password is None: return USER_NOT_LOGGED_IN_ERROR @@ -380,7 +380,7 @@ async def _deploy_service_onchain(request: Request) -> t.Dict: @app.post("/api/services/{service}/onchain/stop") @with_retries - async def _stop_service_onchain(request: Request) -> t.Dict: + async def _stop_service_onchain(request: Request) -> JSONResponse: """Create a service.""" if operate.password is None: return USER_NOT_LOGGED_IN_ERROR @@ -401,9 +401,19 @@ async def _stop_service_onchain(request: Request) -> t.Dict: ) ) + @app.get("/api/services/{service}/deployment") + @with_retries + async def _get_service_deployment(request: Request) -> JSONResponse: + """Create a service.""" + return JSONResponse( + content=operate.service_manager.create_or_load( + request.path_params["service"], + ).deployment.json + ) + @app.post("/api/services/{service}/deployment/build") @with_retries - async def _build_service_locally(request: Request) -> t.Dict: + async def _build_service_locally(request: Request) -> JSONResponse: """Create a service.""" deployment = ( operate.service_manager() @@ -417,7 +427,7 @@ async def _build_service_locally(request: Request) -> t.Dict: @app.post("/api/services/{service}/deployment/start") @with_retries - async def _start_service_locally(request: Request) -> t.Dict: + async def _start_service_locally(request: Request) -> JSONResponse: """Create a service.""" deployment = ( operate.service_manager() @@ -432,7 +442,7 @@ async def _start_service_locally(request: Request) -> t.Dict: @app.post("/api/services/{service}/deployment/stop") @with_retries - async def _stop_service_locally(request: Request) -> t.Dict: + async def _stop_service_locally(request: Request) -> JSONResponse: """Create a service.""" deployment = ( operate.service_manager() @@ -446,7 +456,7 @@ async def _stop_service_locally(request: Request) -> t.Dict: @app.post("/api/services/{service}/deployment/delete") @with_retries - async def _delete_service_locally(request: Request) -> t.Dict: + async def _delete_service_locally(request: Request) -> JSONResponse: """Create a service.""" deployment = ( operate.service_manager()