Skip to content

Module config.ext.aiohttp

View Source
from aiohttp import web

from glom import glom

from config.spring import ConfigClient

class AioHttpConfig:

    def __init__(

        self, app: web.Application, key: str = "config", client=ConfigClient()

    ) -> None:

        self._validate_app(app)

        self._validate_client(client)

        client.get_config()

        app[str(key)] = _Config(client.config)

    def _validate_app(self, app: web.Application) -> None:

        if not isinstance(app, web.Application):

            raise TypeError("instance must be <aiohttp.web.Application>")

    def _validate_client(self, client) -> None:

        if client.__class__.__name__ not in ("ConfigClient", "CF"):

            raise TypeError("instance must be <ConfigClient> or <CF>")

class _Config(dict):

    def get(self, key, default=None):

        return glom(self, key, default=default)

Classes

AioHttpConfig

class AioHttpConfig(
    app: aiohttp.web_app.Application,
    key: str = 'config',
    client=ConfigClient(address='http://localhost:8888', branch='master', app_name='', profile='development', url='http://localhost:8888/master/-development.json', fail_fast=True, oauth2=None)
)
View Source
class AioHttpConfig:

    def __init__(

        self, app: web.Application, key: str = "config", client=ConfigClient()

    ) -> None:

        self._validate_app(app)

        self._validate_client(client)

        client.get_config()

        app[str(key)] = _Config(client.config)

    def _validate_app(self, app: web.Application) -> None:

        if not isinstance(app, web.Application):

            raise TypeError("instance must be <aiohttp.web.Application>")

    def _validate_client(self, client) -> None:

        if client.__class__.__name__ not in ("ConfigClient", "CF"):

            raise TypeError("instance must be <ConfigClient> or <CF>")