From b704ea4d10dc2876561291cc8a1b31f3780fe6f3 Mon Sep 17 00:00:00 2001 From: Blallo Date: Tue, 1 Feb 2022 23:29:48 +0100 Subject: [PATCH] Clean unused code and improve logging --- config.yml | 9 +++++++-- src/phi/api/app.py | 17 ++--------------- src/phi/app.py | 18 +----------------- src/phi/async_ldap/client.py | 8 +------- 4 files changed, 11 insertions(+), 41 deletions(-) diff --git a/config.yml b/config.yml index 64793c5..1162b95 100644 --- a/config.yml +++ b/config.yml @@ -41,9 +41,14 @@ logging: phi: level: DEBUG handlers: [console, file] + asyncio: + level: DEBUG + handlers: [console, file] + propagate: yes aiohttp: level: DEBUG handlers: [console, file] - ldap3: - level: WARNING + propagate: yes + bonsai: + level: DEBUG handlers: [console, file] diff --git a/src/phi/api/app.py b/src/phi/api/app.py index 4b04b2a..4f0af82 100644 --- a/src/phi/api/app.py +++ b/src/phi/api/app.py @@ -1,6 +1,4 @@ # -*- encoding: utf-8 -*- -import logging - from aiohttp import web from phi.logging import get_logger @@ -8,16 +6,8 @@ from phi.async_ldap.client import AsyncClient from phi.async_ldap.model import Hackers, Robots, Congregations from phi.api.routes import api_routes + log = get_logger(__name__) -alog = logging.getLogger("asyncio") - - -def api_startup(app): - app["ldap_client"].open() - - -def api_shutdown(app): - app["ldap_client"].close() def api_app(config): @@ -30,10 +20,7 @@ def api_app(config): app["users"] = Hackers(ldap_client) app["services"] = Robots(ldap_client) app["groups"] = Congregations(ldap_client) - app["alog"] = alog - - app.on_startup.append(api_startup) - app.on_shutdown.append(api_shutdown) + app["log"] = log app.router.add_routes(api_routes) diff --git a/src/phi/app.py b/src/phi/app.py index f26ff27..2e95c08 100644 --- a/src/phi/app.py +++ b/src/phi/app.py @@ -1,7 +1,6 @@ # -*- encoding: utf-8 -*- import pkg_resources -from asyncio import get_event_loop from aiohttp import web import click from pprint import pformat as pp @@ -15,9 +14,7 @@ log = get_logger(__name__) def setup_app(config): - loop = get_event_loop() - - app = web.Application(loop=loop) + app = web.Application() app["config"] = config api = api_app(config) @@ -34,19 +31,6 @@ def run_app(app): ) -def _validate_port(ctx, param, value): - """ - Callback to validate provided port. - """ - if 0 < value or value > 65535: - raise click.BadParameter( - "Provided value is not in the range 0-65535: {} [type: {}]".format( - value, type(value) - ) - ) - return value - - @click.command(help="phid is the main application daemon.") @click.option( "--config", diff --git a/src/phi/async_ldap/client.py b/src/phi/async_ldap/client.py index f147849..219d42d 100644 --- a/src/phi/async_ldap/client.py +++ b/src/phi/async_ldap/client.py @@ -86,7 +86,7 @@ class AsyncClient(LDAPClient): host=None, port=None, encryption=None, - ciphers=None, + cyphers=None, validate=False, ca_cert=None, username=None, @@ -130,9 +130,3 @@ class AsyncClient(LDAPClient): self.set_auto_page_acquire(True) self.set_credentials(self.method, user=self.username, password=self.password) - - def open(self): - pass - - def close(self): - pass