add debugtoolbar support

This commit is contained in:
Evgenii Alekseev 2021-09-26 12:27:46 +03:00
parent 5a6d0e0000
commit d60c553ea2
8 changed files with 50 additions and 1 deletions

View File

@ -125,6 +125,9 @@ Group name must refer to architecture, e.g. it should be `s3:x86_64` for x86_64
Web server settings. If any of `host`/`port` is not set, web integration will be disabled. Group name must refer to architecture, e.g. it should be `web:x86_64` for x86_64 architecture. Web server settings. If any of `host`/`port` is not set, web integration will be disabled. Group name must refer to architecture, e.g. it should be `web:x86_64` for x86_64 architecture.
* `address` - optional address in form `proto://host:port` (`port` can be omitted in case of default `proto` ports), will be used instead of `http://{host}:{port}` in case if set, string, optional. This option is required in case if `OAuth` provider is used. * `address` - optional address in form `proto://host:port` (`port` can be omitted in case of default `proto` ports), will be used instead of `http://{host}:{port}` in case if set, string, optional. This option is required in case if `OAuth` provider is used.
* `debug` - enable debug toolbar, boolean, optional, default `no`.
* `debug_check_host` - check hosts to access debug toolbar, boolean, optional, default `no`.
* `debug_allowed_hosts` - allowed hosts to get access to debug toolbar, space separated list of string, optional.
* `host` - host to bind, string, optional. * `host` - host to bind, string, optional.
* `password` - password to authorize in web service in order to update service status, string, required in case if authorization enabled. * `password` - password to authorize in web service in order to update service status, string, required in case if authorization enabled.
* `port` - port to bind, int, optional. * `port` - port to bind, int, optional.

View File

@ -15,6 +15,7 @@ optdepends=('breezy: -bzr packages support'
'mercurial: -hg packages support' 'mercurial: -hg packages support'
'python-aioauth-client: web server with OAuth2 authorization' 'python-aioauth-client: web server with OAuth2 authorization'
'python-aiohttp: web server' 'python-aiohttp: web server'
'python-aiohttp-debugtoolbar: web server with enabled debug panel'
'python-aiohttp-jinja2: web server' 'python-aiohttp-jinja2: web server'
'python-aiohttp-security: web server with authorization' 'python-aiohttp-security: web server with authorization'
'python-aiohttp-session: web server with authorization' 'python-aiohttp-session: web server with authorization'

View File

@ -51,6 +51,9 @@ command = rsync --archive --compress --partial --delete
chunk_size = 8388608 chunk_size = 8388608
[web] [web]
debug = no
debug_check_host = no
debug_allowed_hosts =
host = 127.0.0.1 host = 127.0.0.1
static_path = /usr/share/ahriman/static static_path = /usr/share/ahriman/static
templates = /usr/share/ahriman templates = /usr/share/ahriman

View File

@ -110,6 +110,7 @@ setup(
"aiohttp", "aiohttp",
"aiohttp_jinja2", "aiohttp_jinja2",
"aioauth-client", "aioauth-client",
"aiohttp_debugtoolbar",
"aiohttp_session", "aiohttp_session",
"aiohttp_security", "aiohttp_security",
"cryptography", "cryptography",

View File

@ -99,6 +99,14 @@ def setup_service(architecture: str, configuration: Configuration, spawner: Spaw
application.logger.info("setup process spawner") application.logger.info("setup process spawner")
application["spawn"] = spawner application["spawn"] = spawner
application.logger.info("setup debug panel")
debug_enabled = configuration.getboolean("web", "debug", fallback=False)
if debug_enabled:
import aiohttp_debugtoolbar # type: ignore
aiohttp_debugtoolbar.setup(application,
hosts=configuration.getlist("web", "debug_allowed_hosts", fallback=[]),
check_host=configuration.getboolean("web", "debug_check_host", fallback=False))
application.logger.info("setup authorization") application.logger.info("setup authorization")
validator = application["validator"] = Auth.load(configuration) validator = application["validator"] = Auth.load(configuration)
if validator.enabled: if validator.enabled:

View File

@ -64,3 +64,20 @@ def application_with_auth(configuration: Configuration, user: User, spawner: Spa
application["validator"]._users[generated.username] = generated application["validator"]._users[generated.username] = generated
return application return application
@pytest.fixture
def application_with_debug(configuration: Configuration, user: User, spawner: Spawn,
mocker: MockerFixture) -> web.Application:
"""
application fixture with debug enabled
:param configuration: configuration fixture
:param user: user descriptor fixture
:param spawner: spawner fixture
:param mocker: mocker object
:return: application test instance
"""
configuration.set_option("web", "debug", "yes")
mocker.patch.object(ahriman.core.auth.helpers, "_has_aiohttp_security", False)
mocker.patch("pathlib.Path.mkdir")
return setup_service("x86_64", configuration, spawner)

View File

@ -45,7 +45,7 @@ def test_run(application: web.Application, mocker: MockerFixture) -> None:
def test_run_with_auth(application_with_auth: web.Application, mocker: MockerFixture) -> None: def test_run_with_auth(application_with_auth: web.Application, mocker: MockerFixture) -> None:
""" """
must run application must run application with enabled authorization
""" """
port = 8080 port = 8080
application_with_auth["configuration"].set_option("web", "port", str(port)) application_with_auth["configuration"].set_option("web", "port", str(port))
@ -54,3 +54,16 @@ def test_run_with_auth(application_with_auth: web.Application, mocker: MockerFix
run_server(application_with_auth) run_server(application_with_auth)
run_application_mock.assert_called_with(application_with_auth, host="127.0.0.1", port=port, run_application_mock.assert_called_with(application_with_auth, host="127.0.0.1", port=port,
handle_signals=False, access_log=pytest.helpers.anyvar(int)) handle_signals=False, access_log=pytest.helpers.anyvar(int))
def test_run_with_debug(application_with_debug: web.Application, mocker: MockerFixture) -> None:
"""
must run application with enabled debug panel
"""
port = 8080
application_with_debug["configuration"].set_option("web", "port", str(port))
run_application_mock = mocker.patch("aiohttp.web.run_app")
run_server(application_with_debug)
run_application_mock.assert_called_with(application_with_debug, host="127.0.0.1", port=port,
handle_signals=False, access_log=pytest.helpers.anyvar(int))

View File

@ -62,6 +62,9 @@ region = eu-central-1
secret_key = secret_key =
[web] [web]
debug = no
debug_check_host = no
debug_allowed_hosts =
host = 127.0.0.1 host = 127.0.0.1
static_path = ../web/templates/static static_path = ../web/templates/static
templates = ../web/templates templates = ../web/templates