move api endpoints to status-api

This commit is contained in:
Evgenii Alekseev 2021-09-05 06:46:14 +03:00
parent 0f4c89145b
commit cfbc9d3267
9 changed files with 60 additions and 60 deletions

View File

@ -58,7 +58,7 @@ class WebClient(Client):
"""
:return: full url for web service for ahriman service itself
"""
return f"{self.address}/api/v1/ahriman"
return f"{self.address}/status-api/v1/ahriman"
@property
def _login_url(self) -> str:
@ -72,7 +72,7 @@ class WebClient(Client):
"""
:return: full url for web service for status
"""
return f"{self.address}/api/v1/status"
return f"{self.address}/status-api/v1/status"
@staticmethod
def parse_address(configuration: Configuration) -> str:
@ -115,7 +115,7 @@ class WebClient(Client):
:param base: package base to generate url
:return: full url of web service for specific package base
"""
return f"{self.address}/api/v1/packages/{base}"
return f"{self.address}/status-api/v1/packages/{base}"
def add(self, package: Package, status: BuildStatusEnum) -> None:
"""

View File

@ -73,7 +73,7 @@ def auth_handler(validator: Auth) -> MiddlewareType:
"""
@middleware
async def handle(request: Request, handler: HandlerType) -> StreamResponse:
if request.path.startswith("/api"):
if request.path.startswith("/status-api"):
permission = UserAccess.Status
elif request.method in ("GET", "HEAD", "OPTIONS"):
permission = UserAccess.Read

View File

@ -34,23 +34,23 @@ def setup_routes(application: Application) -> None:
Available routes are:
GET / get build status page
GET /index.html same as above
GET / get build status page
GET /index.html same as above
POST /login login to service
POST /logout logout from service
POST /login login to service
POST /logout logout from service
GET /api/v1/ahriman get current service status
POST /api/v1/ahriman update service status
GET /status-api/v1/ahriman get current service status
POST /status-api/v1/ahriman update service status
GET /api/v1/packages get all known packages
POST /api/v1/packages force update every package from repository
GET /status-api/v1/packages get all known packages
POST /status-api/v1/packages force update every package from repository
DELETE /api/v1/package/:base delete package base from status page
GET /api/v1/package/:base get package base status
POST /api/v1/package/:base update package base status
DELETE /status-api/v1/package/:base delete package base from status page
GET /status-api/v1/package/:base get package base status
POST /status-api/v1/package/:base update package base status
GET /api/v1/status get web service status itself
GET /status-api/v1/status get web service status itself
:param application: web application instance
"""
@ -60,14 +60,14 @@ def setup_routes(application: Application) -> None:
application.router.add_post("/login", LoginView)
application.router.add_post("/logout", LogoutView)
application.router.add_get("/api/v1/ahriman", AhrimanView, allow_head=True)
application.router.add_post("/api/v1/ahriman", AhrimanView)
application.router.add_get("/status-api/v1/ahriman", AhrimanView, allow_head=True)
application.router.add_post("/status-api/v1/ahriman", AhrimanView)
application.router.add_get("/api/v1/packages", PackagesView, allow_head=True)
application.router.add_post("/api/v1/packages", PackagesView)
application.router.add_get("/status-api/v1/packages", PackagesView, allow_head=True)
application.router.add_post("/status-api/v1/packages", PackagesView)
application.router.add_delete("/api/v1/packages/{package}", PackageView)
application.router.add_get("/api/v1/packages/{package}", PackageView, allow_head=True)
application.router.add_post("/api/v1/packages/{package}", PackageView)
application.router.add_delete("/status-api/v1/packages/{package}", PackageView)
application.router.add_get("/status-api/v1/packages/{package}", PackageView, allow_head=True)
application.router.add_post("/status-api/v1/packages/{package}", PackageView)
application.router.add_get("/api/v1/status", StatusView, allow_head=True)
application.router.add_get("/status-api/v1/status", StatusView, allow_head=True)

View File

@ -18,7 +18,7 @@ def test_ahriman_url(web_client: WebClient) -> None:
must generate service status url correctly
"""
assert web_client._ahriman_url.startswith(web_client.address)
assert web_client._ahriman_url.endswith("/api/v1/ahriman")
assert web_client._ahriman_url.endswith("/status-api/v1/ahriman")
def test_status_url(web_client: WebClient) -> None:
@ -26,7 +26,7 @@ def test_status_url(web_client: WebClient) -> None:
must generate service status url correctly
"""
assert web_client._status_url.startswith(web_client.address)
assert web_client._status_url.endswith("/api/v1/status")
assert web_client._status_url.endswith("/status-api/v1/status")
def test_parse_address(configuration: Configuration) -> None:
@ -88,7 +88,7 @@ def test_package_url(web_client: WebClient, package_ahriman: Package) -> None:
must generate package status correctly
"""
assert web_client._package_url(package_ahriman.base).startswith(web_client.address)
assert web_client._package_url(package_ahriman.base).endswith(f"/api/v1/packages/{package_ahriman.base}")
assert web_client._package_url(package_ahriman.base).endswith(f"/status-api/v1/packages/{package_ahriman.base}")
def test_add(web_client: WebClient, package_ahriman: Package, mocker: MockerFixture) -> None:

View File

@ -33,7 +33,7 @@ async def test_auth_handler_api(aiohttp_request: Any, auth: Auth, mocker: Mocker
"""
must ask for status permission for api calls
"""
aiohttp_request = aiohttp_request._replace(path="/api")
aiohttp_request = aiohttp_request._replace(path="/status-api")
request_handler = AsyncMock()
mocker.patch("ahriman.core.auth.auth.Auth.is_safe_request", return_value=False)
check_permission_mock = mocker.patch("aiohttp_security.check_permission")
@ -47,7 +47,7 @@ async def test_auth_handler_api_post(aiohttp_request: Any, auth: Auth, mocker: M
"""
must ask for status permission for api calls with POST
"""
aiohttp_request = aiohttp_request._replace(path="/api", method="POST")
aiohttp_request = aiohttp_request._replace(path="/status-api", method="POST")
request_handler = AsyncMock()
mocker.patch("ahriman.core.auth.auth.Auth.is_safe_request", return_value=False)
check_permission_mock = mocker.patch("aiohttp_security.check_permission")

View File

@ -8,7 +8,7 @@ async def test_get(client: TestClient) -> None:
"""
must return valid service status
"""
response = await client.get("/api/v1/ahriman")
response = await client.get("/status-api/v1/ahriman")
status = BuildStatus.from_json(await response.json())
assert response.status == 200
@ -20,10 +20,10 @@ async def test_post(client: TestClient) -> None:
must update service status correctly
"""
payload = {"status": BuildStatusEnum.Success.value}
post_response = await client.post("/api/v1/ahriman", json=payload)
post_response = await client.post("/status-api/v1/ahriman", json=payload)
assert post_response.status == 204
response = await client.get("/api/v1/ahriman")
response = await client.get("/status-api/v1/ahriman")
status = BuildStatus.from_json(await response.json())
assert response.status == 200
@ -34,7 +34,7 @@ async def test_post_exception(client: TestClient) -> None:
"""
must raise exception on invalid payload
"""
post_response = await client.post("/api/v1/ahriman", json={})
post_response = await client.post("/status-api/v1/ahriman", json={})
assert post_response.status == 400
@ -45,5 +45,5 @@ async def test_post_exception_inside(client: TestClient, mocker: MockerFixture)
payload = {"status": BuildStatusEnum.Success.value}
mocker.patch("ahriman.core.status.watcher.Watcher.update_self", side_effect=Exception())
post_response = await client.post("/api/v1/ahriman", json=payload)
post_response = await client.post("/status-api/v1/ahriman", json=payload)
assert post_response.status == 500

View File

@ -8,12 +8,12 @@ async def test_get(client: TestClient, package_ahriman: Package, package_python_
"""
must return status for specific package
"""
await client.post(f"/api/v1/packages/{package_ahriman.base}",
await client.post(f"/status-api/v1/packages/{package_ahriman.base}",
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
await client.post(f"/api/v1/packages/{package_python_schedule.base}",
await client.post(f"/status-api/v1/packages/{package_python_schedule.base}",
json={"status": BuildStatusEnum.Success.value, "package": package_python_schedule.view()})
response = await client.get(f"/api/v1/packages/{package_ahriman.base}")
response = await client.get(f"/status-api/v1/packages/{package_ahriman.base}")
assert response.status == 200
packages = [Package.from_json(item["package"]) for item in await response.json()]
@ -25,7 +25,7 @@ async def test_get_not_found(client: TestClient, package_ahriman: Package) -> No
"""
must return Not Found for unknown package
"""
response = await client.get(f"/api/v1/packages/{package_ahriman.base}")
response = await client.get(f"/status-api/v1/packages/{package_ahriman.base}")
assert response.status == 404
@ -33,18 +33,18 @@ async def test_delete(client: TestClient, package_ahriman: Package, package_pyth
"""
must delete single base
"""
await client.post(f"/api/v1/packages/{package_ahriman.base}",
await client.post(f"/status-api/v1/packages/{package_ahriman.base}",
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
await client.post(f"/api/v1/packages/{package_python_schedule.base}",
await client.post(f"/status-api/v1/packages/{package_python_schedule.base}",
json={"status": BuildStatusEnum.Success.value, "package": package_python_schedule.view()})
response = await client.delete(f"/api/v1/packages/{package_ahriman.base}")
response = await client.delete(f"/status-api/v1/packages/{package_ahriman.base}")
assert response.status == 204
response = await client.get(f"/api/v1/packages/{package_ahriman.base}")
response = await client.get(f"/status-api/v1/packages/{package_ahriman.base}")
assert response.status == 404
response = await client.get(f"/api/v1/packages/{package_python_schedule.base}")
response = await client.get(f"/status-api/v1/packages/{package_python_schedule.base}")
assert response.status == 200
@ -52,16 +52,16 @@ async def test_delete_unknown(client: TestClient, package_ahriman: Package, pack
"""
must suppress errors on unknown package deletion
"""
await client.post(f"/api/v1/packages/{package_python_schedule.base}",
await client.post(f"/status-api/v1/packages/{package_python_schedule.base}",
json={"status": BuildStatusEnum.Success.value, "package": package_python_schedule.view()})
response = await client.delete(f"/api/v1/packages/{package_ahriman.base}")
response = await client.delete(f"/status-api/v1/packages/{package_ahriman.base}")
assert response.status == 204
response = await client.get(f"/api/v1/packages/{package_ahriman.base}")
response = await client.get(f"/status-api/v1/packages/{package_ahriman.base}")
assert response.status == 404
response = await client.get(f"/api/v1/packages/{package_python_schedule.base}")
response = await client.get(f"/status-api/v1/packages/{package_python_schedule.base}")
assert response.status == 200
@ -70,11 +70,11 @@ async def test_post(client: TestClient, package_ahriman: Package) -> None:
must update package status
"""
post_response = await client.post(
f"/api/v1/packages/{package_ahriman.base}",
f"/status-api/v1/packages/{package_ahriman.base}",
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
assert post_response.status == 204
response = await client.get(f"/api/v1/packages/{package_ahriman.base}")
response = await client.get(f"/status-api/v1/packages/{package_ahriman.base}")
assert response.status == 200
@ -82,7 +82,7 @@ async def test_post_exception(client: TestClient, package_ahriman: Package) -> N
"""
must raise exception on invalid payload
"""
post_response = await client.post(f"/api/v1/packages/{package_ahriman.base}", json={})
post_response = await client.post(f"/status-api/v1/packages/{package_ahriman.base}", json={})
assert post_response.status == 400
@ -91,15 +91,15 @@ async def test_post_light(client: TestClient, package_ahriman: Package) -> None:
must update package status only
"""
post_response = await client.post(
f"/api/v1/packages/{package_ahriman.base}",
f"/status-api/v1/packages/{package_ahriman.base}",
json={"status": BuildStatusEnum.Unknown.value, "package": package_ahriman.view()})
assert post_response.status == 204
post_response = await client.post(
f"/api/v1/packages/{package_ahriman.base}", json={"status": BuildStatusEnum.Success.value})
f"/status-api/v1/packages/{package_ahriman.base}", json={"status": BuildStatusEnum.Success.value})
assert post_response.status == 204
response = await client.get(f"/api/v1/packages/{package_ahriman.base}")
response = await client.get(f"/status-api/v1/packages/{package_ahriman.base}")
assert response.status == 200
statuses = {
Package.from_json(item["package"]).base: BuildStatus.from_json(item["status"])
@ -113,5 +113,5 @@ async def test_post_not_found(client: TestClient, package_ahriman: Package) -> N
must raise exception on status update for unknown package
"""
post_response = await client.post(
f"/api/v1/packages/{package_ahriman.base}", json={"status": BuildStatusEnum.Success.value})
f"/status-api/v1/packages/{package_ahriman.base}", json={"status": BuildStatusEnum.Success.value})
assert post_response.status == 400

View File

@ -9,12 +9,12 @@ async def test_get(client: TestClient, package_ahriman: Package, package_python_
"""
must return status for all packages
"""
await client.post(f"/api/v1/packages/{package_ahriman.base}",
await client.post(f"/status-api/v1/packages/{package_ahriman.base}",
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
await client.post(f"/api/v1/packages/{package_python_schedule.base}",
await client.post(f"/status-api/v1/packages/{package_python_schedule.base}",
json={"status": BuildStatusEnum.Success.value, "package": package_python_schedule.view()})
response = await client.get("/api/v1/packages")
response = await client.get("/status-api/v1/packages")
assert response.status == 200
packages = [Package.from_json(item["package"]) for item in await response.json()]
@ -27,6 +27,6 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
must be able to reload packages
"""
load_mock = mocker.patch("ahriman.core.status.watcher.Watcher.load")
response = await client.post("/api/v1/packages")
response = await client.post("/status-api/v1/packages")
assert response.status == 204
load_mock.assert_called_once()

View File

@ -10,10 +10,10 @@ async def test_get(client: TestClient, package_ahriman: Package) -> None:
"""
must generate web service status correctly
"""
await client.post(f"/api/v1/packages/{package_ahriman.base}",
await client.post(f"/status-api/v1/packages/{package_ahriman.base}",
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
response = await client.get("/api/v1/status")
response = await client.get("/status-api/v1/status")
assert response.status == 200
json = await response.json()