Module config.ext
None
None
View Source
try:
from config.ext.aiohttp import AioHttpConfig
except ImportError:
aiohttp = None
try:
from config.ext.flask import FlaskConfig
except ImportError:
flask = None
try:
from config.ext.fastapi import fastapi_cloud_foundry, fastapi_config_client
except ImportError:
fastapi = None
__all__ = [
"AioHttpConfig",
"FlaskConfig",
"fastapi_config_client,",
"fastapi_cloud_foundry",
]
Sub-modules
Functions
fastapi_cloud_foundry
def fastapi_cloud_foundry(
request: starlette.requests.Request
)
View Source
async def fastapi_cloud_foundry(request: Request):
try:
logger.debug("ConfigClient already initialized")
except AttributeError:
logger.debug("Initializing ConfigClient")
cc = CF()
cc.get_config()
request.app.config_client = cc
logger.debug("ConfigClient successfully initialized")
Classes
AioHttpConfig
class AioHttpConfig(
app: aiohttp.web_app.Application,
key: str = 'config',
client: Optional[config.spring.ConfigClient] = None,
**kwargs
)
View Source
class AioHttpConfig:
def __init__(
self,
app: web.Application,
key: str = "config",
client: Optional[ConfigClient] = None,
**kwargs,
) -> None:
self._validate_app(app)
if not client:
client = ConfigClient()
self._validate_client(client)
logger.debug(f"AioHttpConfig get_config params: [kwargs='{kwargs}']")
client.get_config(**kwargs)
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>")
FlaskConfig
class FlaskConfig(
app: flask.app.Flask,
client: Optional[config.spring.ConfigClient] = None,
**kwargs
)
View Source
class FlaskConfig:
def __init__(
self, app: Flask, client: Optional[ConfigClient] = None, **kwargs
) -> None:
if not isinstance(app, Flask):
raise TypeError("app must be Flask instance")
if not client:
client = ConfigClient()
_validate(client)
self.app = app
logger.debug(f"FlaskConfig get_config params: [kwargs='{kwargs}']")
client.get_config(**kwargs)
self.app.config = _Config(
root_path=self.app.root_path,
defaults=self.app.config,
_config=client.config,
)