From 232878d23f5bf7b59863ce3ad07f49e2a8bd97c6 Mon Sep 17 00:00:00 2001 From: Jesus Lara Date: Mon, 11 Nov 2024 00:35:27 +0100 Subject: [PATCH] contrib for adding navconfig into an aiohttp application --- navconfig/contrib/__init__.py | 3 +++ navconfig/contrib/web.py | 12 ++++++++++++ navconfig/version.py | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 navconfig/contrib/__init__.py create mode 100644 navconfig/contrib/web.py diff --git a/navconfig/contrib/__init__.py b/navconfig/contrib/__init__.py new file mode 100644 index 0000000..df7f072 --- /dev/null +++ b/navconfig/contrib/__init__.py @@ -0,0 +1,3 @@ +from __future__ import annotations + +from .web import AiohttpConfig diff --git a/navconfig/contrib/web.py b/navconfig/contrib/web.py new file mode 100644 index 0000000..629fe8a --- /dev/null +++ b/navconfig/contrib/web.py @@ -0,0 +1,12 @@ +from aiohttp import web +from navconfig import config, Kardex + +class AiohttpConfig: + def __init__(self, app: web.Application, key_name: str = 'config'): + self.app = app + config_key = web.AppKey(key_name, Kardex) + if hasattr(self.app, key_name): + # already configured + return + self.app[config_key] = config + setattr(self.app, key_name, config) diff --git a/navconfig/version.py b/navconfig/version.py index 9588a14..0bb2236 100644 --- a/navconfig/version.py +++ b/navconfig/version.py @@ -5,7 +5,7 @@ "Configuration tool for all Navigator Services " "Tool for accessing Config info from different sources." ) -__version__ = "1.7.10" +__version__ = "1.7.11" __author__ = "Jesus Lara" __author_email__ = "jesuslarag@gmail.com" __license__ = "MIT"