Merge pull request #140 from grillazz/refactor

Refactor
This commit is contained in:
Jakub Miazek 2024-03-24 11:07:46 +01:00 committed by GitHub
commit 3b98c21590
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 5 deletions

2
.env
View File

@ -6,7 +6,6 @@ SQL_TEST_DB=testdb
SQL_HOST=db
SQL_USER=user
SQL_PASS=secret
#SQL_URL=postgresql+asyncpg://${SQL_USER}:${SQL_PASS}@${SQL_HOST}/${SQL_DB}
# Postgres
POSTGRES_SERVER=db
@ -20,7 +19,6 @@ POSTGRES_PASSWORD=secret
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_DB=2
REDIS_URL="redis://${REDIS_HOST}:${REDIS_PORT}/${REDIS_DB}"
JWT_EXPIRE=3600
JWT_ALGORITHM=HS256

View File

@ -23,11 +23,9 @@ jobs:
SQL_USER: app-user
POSTGRES_PASSWORD: secret
PGPASSWORD: secret
# SQL_URL: postgresql+asyncpg://app-user:secret@localhost:5432/testdb
REDIS_HOST: 127.0.0.1
REDIS_PORT: 6379
REDIS_DB: 2
REDIS_URL: redis://127.0.0.1:6379/2
JWT_EXPIRE: 3600
JWT_ALGORITHM: HS256

View File

@ -11,15 +11,44 @@ class Settings(BaseSettings):
env_ignore_empty=True,
extra="ignore"
)
redis_url: RedisDsn = os.getenv("REDIS_URL")
jwt_algorithm: str = os.getenv("JWT_ALGORITHM")
jwt_expire: int = os.getenv("JWT_EXPIRE")
REDIS_HOST: str
REDIS_PORT: int
REDIS_DB: str
JWT_ALGORITHM: str
JWT_EXPIRE: int
SQL_USER: str
SQL_PASS: str
SQL_HOST: str
SQL_DB: str
@computed_field
@property
def redis_url(self) -> RedisDsn:
"""
This is a computed field that generates a RedisDsn URL for redis-py.
The URL is built using the MultiHostUrl.build method, which takes the following parameters:
- scheme: The scheme of the URL. In this case, it is "redis".
- host: The host of the Redis database, retrieved from the REDIS_HOST environment variable.
- port: The port of the Redis database, retrieved from the REDIS_PORT environment variable.
- path: The path of the Redis database, retrieved from the REDIS_DB environment variable.
Returns:
RedisDsn: The constructed RedisDsn URL for redis-py.
"""
return MultiHostUrl.build(
scheme="redis",
host=self.REDIS_HOST,
port=self.REDIS_PORT,
path=self.REDIS_DB,
)
@computed_field
@property
def asyncpg_url(self) -> PostgresDsn: