-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Use
BaseSettings
of pydantic
for configuration
This is the recommended way as per the documentation of `fastapi` as it can be easily made available to routes.
- Loading branch information
Showing
2 changed files
with
46 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Configuration of API""" | ||
# to get a string like this run: | ||
# openssl rand -hex 32 | ||
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7" | ||
ALGORITHM = "HS256" | ||
ACCESS_TOKEN_EXPIRE_MINUTES = 30 | ||
"""Configuration settings for the application.""" | ||
from functools import lru_cache | ||
|
||
from pydantic import BaseSettings | ||
|
||
|
||
class Settings(BaseSettings): | ||
"""Configuration settings for the application.""" | ||
|
||
secret_key: str = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7" | ||
"""The secret key used to create access tokens.""" | ||
|
||
secret_key_algoritm: str = "HS256" | ||
"""The algorithm used to create access tokens.""" | ||
|
||
access_token_expire_minutes: int = 30 | ||
"""The number of minutes an access token remains valid.""" | ||
|
||
|
||
@lru_cache() | ||
def get_settings(): | ||
"""Return the configuration settings for the application. | ||
This function is cached and should be used preferentially over constructing ``Settings`` directly. | ||
""" | ||
return Settings() | ||
|
||
|
||
fake_users_db = { | ||
"[email protected]": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters