diff --git a/app/routers/apps.py b/app/routers/apps.py index 6e52c7d..5fc3011 100644 --- a/app/routers/apps.py +++ b/app/routers/apps.py @@ -5,15 +5,17 @@ from app.sse_starlette import EventSourceResponse from fastapi import APIRouter, HTTPException, status from fastapi.params import Depends -router = APIRouter(prefix="/apps", tags=["Apps"]) +_PREFIX = "apps" + +router = APIRouter(prefix=f"/{_PREFIX}", tags=["Apps"]) @router.get( "/status", + name=f"{_PREFIX}/status", summary="Get the status of currently installed apps.", response_description=docs.get_app_status_response_docs, dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, ) def get_status(): try: @@ -25,11 +27,11 @@ def get_status(): @router.get( - "/status_sub", + "/status-sub", + name=f"{_PREFIX}/status-sub", summary="Subscribe to status changes of currently installed apps.", response_description=docs.get_app_status_sub_response_docs, dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, ) async def get_status(): try: diff --git a/app/routers/bitcoin.py b/app/routers/bitcoin.py index f6e5be2..3b68acf 100644 --- a/app/routers/bitcoin.py +++ b/app/routers/bitcoin.py @@ -12,11 +12,14 @@ from app.utils import bitcoin_rpc from fastapi import APIRouter, HTTPException, Request, status from fastapi.params import Depends -router = APIRouter(prefix="/bitcoin", tags=["Bitcoin Core"]) +_PREFIX = "bitcoin" + +router = APIRouter(prefix=f"/{_PREFIX}", tags=["Bitcoin Core"]) @router.get( - "/btc_status", + "/btc-status", + name=f"{_PREFIX}.btc-status", description="Get general information about bitcoin core. Combines most important information from `getblockchaininfo` and `getnetworkinfo`", dependencies=[Depends(JWTBearer())], response_model=BtcStatus, @@ -26,7 +29,8 @@ async def btc_status(): @router.get( - "/getblockcount", + "/get-block-count", + name=f"{_PREFIX}.get-block-count", summary="Get the current block count", description="See documentation on [bitcoincore.org](https://bitcoincore.org/en/doc/0.21.0/rpc/blockchain/getblockcount/)", response_description="""A JSON String with relevant information.\n @@ -38,7 +42,6 @@ async def btc_status(): } """, dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, ) def getblockcount(): r = bitcoin_rpc("getblockcount") @@ -50,12 +53,12 @@ def getblockcount(): @router.get( - "/getblockchaininfo", + "/get-blockchain-info", + name=f"{_PREFIX}.get-blockchain-info", summary="Get the current blockchain status", description="See documentation on [bitcoincore.org](https://bitcoincore.org/en/doc/0.21.0/rpc/blockchain/getblockchaininfo/)", response_description="A JSON String with relevant information.", dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, response_model=BlockchainInfo, ) async def getblockchaininfo(): @@ -64,7 +67,8 @@ async def getblockchaininfo(): @router.get( - "/getnetworkinfo", + "/get-network-info", + name=f"{_PREFIX}.get-network-info", summary="Get information about the network", description="See documentation on [bitcoincore.org](https://bitcoincore.org/en/doc/0.21.0/rpc/network/getnetworkinfo/)", response_description="A JSON String with relevant information.", @@ -78,12 +82,12 @@ async def getnetworkinfo(): @router.get( - "/block_sub", + "/block-sub", + name=f"{_PREFIX}.block-sub", summary="Subscribe to incoming blocks.", description=blocks_sub_doc, response_description="A JSON object with information about the new block.", dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, ) async def zmq_sub(request: Request, verbosity: int = 1): return EventSourceResponse(handle_block_sub(request, verbosity)) diff --git a/app/routers/lightning.py b/app/routers/lightning.py index 6f095f6..a833f55 100644 --- a/app/routers/lightning.py +++ b/app/routers/lightning.py @@ -1,3 +1,4 @@ +from app.routers.system import _PREFIX from app.auth.auth_bearer import JWTBearer from app.models.lightning import ( Invoice, @@ -19,11 +20,14 @@ from app.routers.lightning_docs import send_payment_desc from fastapi import APIRouter, HTTPException, Query, status from fastapi.params import Depends -router = APIRouter(prefix="/lightning", tags=["Lightning"]) +_PREFIX = "lightning" + +router = APIRouter(prefix=f"/{_PREFIX}", tags=["Lightning"]) @router.get( - "/get_ln_status", + "/get-ln-status", + name=f"{_PREFIX}.get-ln-status", summary="Get current lightning system status", dependencies=[Depends(JWTBearer())], status_code=status.HTTP_200_OK, @@ -39,11 +43,11 @@ async def get_ln_status_path(): @router.post( - "/addinvoice", + "/add-invoice", + name=f"{_PREFIX}.add-invoice", summary="Addinvoice adds a new Invoice to the database.", description="For additional information see [LND docs](https://api.lightning.community/#addinvoice)", dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, response_model=Invoice, ) async def addinvoice( @@ -58,11 +62,11 @@ async def addinvoice( @router.get( - "/getbalance", + "/get-balance", + name=f"{_PREFIX}.get-balance", summary="Get the current on chain and channel balances of the lighting wallet.", response_description="A JSON String with on chain wallet balances.", dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, response_model=WalletBalance, ) async def getwalletbalance(): @@ -75,12 +79,12 @@ async def getwalletbalance(): @router.post( - "/sendpayment", + "/send-payment", + name=f"{_PREFIX}.send-payment", summary="Attempt to pay a payment request.", description=send_payment_desc, response_description="Either an error or a Payment object on success", dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, response_model=Payment, ) async def sendpayment( @@ -95,11 +99,11 @@ async def sendpayment( @router.get( - "/getinfo", + "/get-info", + name=f"{_PREFIX}.get-info", summary="Request information about the currently running lightning node.", response_description="Either an error or a LnInfo object on success", dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, response_model=LnInfo, ) async def get_info(): @@ -113,7 +117,7 @@ async def get_info(): @router.get( "/decode-pay-req", - name="lightning.decode-pay-req", + name=f"{_PREFIX}.decode-pay-req", summary="DecodePayReq takes an encoded payment request string and attempts to decode it, returning a full description of the conditions encoded within the payment request.", response_model=PaymentRequest, response_description="A fully decoded payment request or a HTTP status 400 if the payment request cannot be decoded.", diff --git a/app/routers/system.py b/app/routers/system.py index 5733a87..9804c6a 100644 --- a/app/routers/system.py +++ b/app/routers/system.py @@ -19,11 +19,14 @@ from decouple import config from fastapi import APIRouter, HTTPException, Request, status from fastapi.params import Depends -router = APIRouter(prefix="/system", tags=["System"]) +_PREFIX = "system" + +router = APIRouter(prefix=f"/{_PREFIX}", tags=["System"]) @router.post( "/login", + name=f"{_PREFIX}.login", summary="Logs the user in with the current password", response_description="JWT token for the current session.", status_code=status.HTTP_200_OK, @@ -36,7 +39,8 @@ def login(i: LoginInput): @router.get( - "/get_system_info", + "/get-system-info", + name=f"{_PREFIX}.get-system-info", summary="Get system status information", dependencies=[Depends(JWTBearer())], response_model=SystemInfo, @@ -46,7 +50,8 @@ async def get_system_info_path(): @router.get( - "/hardware_info", + "/hardware-info", + name=f"{_PREFIX}.hardware-info", summary="Get hardware status information.", response_description="Returns a JSON string with hardware information:\n" + get_hw_info_json, @@ -58,8 +63,8 @@ def hw_info() -> map: @router.get( - "/get_debug_logs_raw", - name="system.get_debug_logs_raw", + "/get-debug-logs-raw", + name=f"{_PREFIX}.get-debug-logs-raw", summary=get_debug_logs_raw_summary, description=get_debug_logs_raw_desc, response_description=get_debug_logs_raw_resp_desc, @@ -71,12 +76,12 @@ async def get_debug_logs_raw_route() -> RawDebugLogData: @router.get( - "/hardware_info_sub", + "/hardware-info-sub", + name=f"{_PREFIX}.hardware-info-sub", summary="Subscribe to hardware status information.", response_description=f"Yields a JSON string with hardware information every {HW_INFO_YIELD_TIME} seconds:\n" + get_hw_info_json, dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, ) async def hw_info_sub(request: Request): return EventSourceResponse(subscribe_hardware_info(request)) @@ -84,9 +89,9 @@ async def hw_info_sub(request: Request): @router.post( "/reboot", + name=f"{_PREFIX}.reboot", summary="Reboots the system", dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, ) def reboot_system(): return HTTPException(status.HTTP_501_NOT_IMPLEMENTED) @@ -94,9 +99,9 @@ def reboot_system(): @router.post( "/shutdown", + name=f"{_PREFIX}.shutdown", summary="Shuts the system down", dependencies=[Depends(JWTBearer())], - status_code=status.HTTP_200_OK, ) def reboot_system(): return HTTPException(status.HTTP_501_NOT_IMPLEMENTED)