Skip to content

Commit

Permalink
Merge branch 'main' into gha_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ianco authored Apr 12, 2021
2 parents 5ab4235 + 87165c2 commit 925016b
Show file tree
Hide file tree
Showing 30 changed files with 1,368 additions and 247 deletions.
54 changes: 50 additions & 4 deletions aries_cloudagent/admin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

import asyncio
import logging
from typing import Callable, Coroutine, Sequence, Set
import re
import uuid

from typing import Callable, Coroutine, Sequence, Set

import aiohttp_cors
import jwt

from aiohttp import web
from aiohttp_apispec import (
docs,
response_schema,
setup_aiohttp_apispec,
validation_middleware,
)
import aiohttp_cors
import jwt

from marshmallow import fields

Expand Down Expand Up @@ -364,12 +367,20 @@ async def setup_context(request: web.Request, handler):

middlewares.append(setup_context)

app = web.Application(middlewares=middlewares)
app = web.Application(
middlewares=middlewares,
client_max_size=(
self.context.settings.get("admin.admin_client_max_request_size", 1)
* 1024
* 1024
),
)

server_routes = [
web.get("/", self.redirect_handler, allow_head=False),
web.get("/plugins", self.plugins_handler, allow_head=False),
web.get("/status", self.status_handler, allow_head=False),
web.get("/status/config", self.config_handler, allow_head=False),
web.post("/status/reset", self.status_reset_handler),
web.get("/status/live", self.liveliness_handler, allow_head=False),
web.get("/status/ready", self.readiness_handler, allow_head=False),
Expand Down Expand Up @@ -523,6 +534,41 @@ async def plugins_handler(self, request: web.BaseRequest):
plugins = registry and sorted(registry.plugin_names) or []
return web.json_response({"result": plugins})

@docs(tags=["server"], summary="Fetch the server configuration")
@response_schema(AdminStatusSchema(), 200, description="")
async def config_handler(self, request: web.BaseRequest):
"""
Request handler for the server configuration.
Args:
request: aiohttp request object
Returns:
The web response
"""
config = {
k: self.context.settings[k]
for k in self.context.settings
if k
not in [
"admin.admin_api_key",
"multitenant.jwt_secret",
"wallet.key",
"wallet.rekey",
"wallet.seed",
"wallet.storage.creds",
]
}
for index in range(len(config.get("admin.webhook_urls", []))):
config["admin.webhook_urls"][index] = re.sub(
r"#.*",
"",
config["admin.webhook_urls"][index],
)

return web.json_response(config)

@docs(tags=["server"], summary="Fetch the server status")
@response_schema(AdminStatusSchema(), 200, description="")
async def status_handler(self, request: web.BaseRequest):
Expand Down
40 changes: 40 additions & 0 deletions aries_cloudagent/admin/tests/test_admin_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from aiohttp import ClientSession, DummyCookieJar, TCPConnector, web
from aiohttp.test_utils import unused_port

Expand Down Expand Up @@ -190,10 +192,12 @@ async def test_start_stop(self):

settings = {
"admin.admin_insecure_mode": False,
"admin.admin_client_max_request_size": 4,
"admin.admin_api_key": "test-api-key",
}
server = self.get_admin_server(settings)
await server.start()
assert server.app._client_max_size == 4 * 1024 * 1024
with async_mock.patch.object(
server, "websocket_queues", async_mock.MagicMock()
) as mock_wsq:
Expand Down Expand Up @@ -372,6 +376,42 @@ async def test_visit_secure_mode(self):

await server.stop()

async def test_query_config(self):
settings = {
"admin.admin_insecure_mode": False,
"admin.admin_api_key": "test-api-key",
"admin.webhook_urls": ["localhost:8123/abc#secret", "localhost:8123/def"],
"multitenant.jwt_secret": "abc123",
"wallet.key": "abc123",
"wallet.rekey": "def456",
"wallet.seed": "00000000000000000000000000000000",
"wallet.storage.creds": "secret",
}
server = self.get_admin_server(settings)
await server.start()

async with self.client_session.get(
f"http://127.0.0.1:{self.port}/status/config",
headers={"x-api-key": "test-api-key"},
) as response:
result = json.loads(await response.text())
assert "admin.admin_insecure_mode" in result
assert all(
k not in result
for k in [
"admin.admin_api_key",
"multitenant.jwt_secret",
"wallet.key",
"wallet.rekey",
"wallet.seed",
"wallet.storage.creds",
]
)
assert result["admin.webhook_urls"] == [
"localhost:8123/abc",
"localhost:8123/def",
]

async def test_visit_shutting_down(self):
settings = {
"admin.admin_insecure_mode": True,
Expand Down
Loading

0 comments on commit 925016b

Please sign in to comment.