Implement custom config class; get SQLAlchemy database URI from config
This commit is contained in:
parent
31df889dcb
commit
04d434b4a3
7 changed files with 68 additions and 13 deletions
32
tofu_api/common/config/config.py
Normal file
32
tofu_api/common/config/config.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import yaml
|
||||
from flask import Config as BaseConfig
|
||||
|
||||
from .defaults import DefaultConfig
|
||||
|
||||
|
||||
class Config(BaseConfig):
|
||||
"""
|
||||
Custom config class for the Flask application.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Set app-specific default values
|
||||
self.from_object(DefaultConfig)
|
||||
|
||||
def from_yaml(self, filename: str, *, silent: bool = False) -> bool:
|
||||
"""
|
||||
Update config from a YAML file.
|
||||
"""
|
||||
return self.from_file(filename, load=yaml.safe_load, silent=silent)
|
||||
|
||||
# Properties for type safe access to config values
|
||||
|
||||
@property
|
||||
def sqlalchemy_database_uri(self) -> str:
|
||||
return self.get('SQLALCHEMY_DATABASE_URI')
|
||||
|
||||
@property
|
||||
def sqlalchemy_echo(self) -> bool:
|
||||
return bool(self.get('SQLALCHEMY_ECHO'))
|
||||
Loading…
Add table
Add a link
Reference in a new issue