Verified Commit 43b7fdb6 authored by Kevin Morris's avatar Kevin Morris
Browse files

fix(rpc): display rpc doc when no query string is provided

Closes #255

Signed-off-by: Kevin Morris's avatarKevin Morris <>
parent 60ae6760
......@@ -12,7 +12,7 @@ from fastapi.responses import JSONResponse
from aurweb import defaults
from aurweb.ratelimit import check_ratelimit
from aurweb.rpc import RPC
from aurweb.rpc import RPC, documentation
router = APIRouter()
......@@ -74,6 +74,9 @@ async def rpc(request: Request,
args: Optional[List[str]] = Query(default=[], alias="arg[]"),
callback: Optional[str] = Query(default=None)):
if not request.url.query:
return documentation()
# Create a handle to our RPC class.
rpc = RPC(version=v, type=type)
import os
from collections import defaultdict
from typing import Any, Callable, Dict, List, NewType, Union
from fastapi.responses import HTMLResponse
from sqlalchemy import and_, literal
import aurweb.config as config
......@@ -23,6 +26,18 @@ DataGenerator = NewType("DataGenerator",
Callable[[models.Package], Dict[str, Any]])
def documentation():
aurwebdir = config.get("options", "aurwebdir")
rpc_doc = os.path.join(aurwebdir, "doc", "rpc.html")
if not os.path.exists(rpc_doc):
raise OSError("doc/rpc.html could not be read")
with open(rpc_doc) as f:
data =
return HTMLResponse(data)
class RPC:
""" RPC API handler class.
......@@ -14,7 +14,7 @@ from redis.client import Pipeline
import aurweb.models.dependency_type as dt
import aurweb.models.relation_type as rt
from aurweb import asgi, config, db, scripts
from aurweb import asgi, config, db, rpc, scripts
from aurweb.models.account_type import USER_ID
from aurweb.models.license import License
from aurweb.models.package import Package
......@@ -215,6 +215,29 @@ def pipeline():
yield pipeline
def test_rpc_documentation(client: TestClient):
with client as request:
resp = request.get("/rpc")
assert resp.status_code == int(HTTPStatus.OK)
assert "aurweb RPC Interface" in resp.text
def test_rpc_documentation_missing():
config_get = config.get
def mock_get(section: str, key: str) -> str:
if section == "options" and key == "aurwebdir":
return "/missing"
return config_get(section, key)
with mock.patch("aurweb.config.get", side_effect=mock_get):
expr = r"^doc/rpc\.html could not be read$"
with pytest.raises(OSError, match=expr):
def test_rpc_singular_info(client: TestClient,
user: User,
packages: List[Package],
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment