Secret key multi-worker generating bugfix, volume instead of dir in mariadb, upd deps
This commit is contained in:
parent
4509d02425
commit
edbf0233ba
6 changed files with 64 additions and 16 deletions
|
@ -7,26 +7,47 @@ from pydantic import BaseSettings
|
|||
|
||||
# Directories
|
||||
file_dir = Path(__file__).parent
|
||||
templates_dir = str(
|
||||
file_dir.parent / 'templates'
|
||||
)
|
||||
static_dir = str(
|
||||
file_dir.parent / 'static'
|
||||
)
|
||||
templates_dir = str(file_dir.parent / 'templates')
|
||||
static_dir = str(file_dir.parent / 'static')
|
||||
|
||||
|
||||
# Main configuration
|
||||
class Settings(BaseSettings):
|
||||
debug: bool = False
|
||||
secret_key: str = secrets.token_hex(32)
|
||||
secret_key: str = 'secret'
|
||||
app_host: str = '127.0.0.1'
|
||||
app_port: int = 8000
|
||||
|
||||
|
||||
# Instantiate Settings class
|
||||
settings = Settings()
|
||||
|
||||
|
||||
# Jinja templates handler
|
||||
templates = Jinja2Templates(
|
||||
directory=templates_dir,
|
||||
)
|
||||
|
||||
|
||||
def secret_key_check() -> None:
|
||||
"""Generates a secret key automatically
|
||||
if the env var `secret_key` is not set
|
||||
or contains text `secret`"""
|
||||
|
||||
if settings.secret_key == 'secret':
|
||||
|
||||
key_file = Path('/tmp/secret_key')
|
||||
|
||||
if key_file.exists():
|
||||
with key_file.open('rt') as f:
|
||||
secret_key = f.read()
|
||||
|
||||
else:
|
||||
secret_key = secrets.token_hex(32)
|
||||
with key_file.open('wt') as f:
|
||||
f.write(secret_key)
|
||||
|
||||
settings.secret_key = secret_key
|
||||
|
||||
|
||||
# Call the function
|
||||
secret_key_check()
|
||||
|
|
Loading…
Add table
Reference in a new issue