Skip to content

Commit

Permalink
env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
chennisden committed Jun 3, 2024
1 parent c9e451c commit eab4c8a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions store/app/api/crud/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from botocore.exceptions import ClientError
from redis import Redis
from types_aiobotocore_dynamodb.service_resource import DynamoDBServiceResource
from store.settings import settings

logger = logging.getLogger(__name__)

Expand All @@ -31,8 +32,7 @@ async def __aenter__(self) -> Self:
db = await db.__aenter__()
self.__db = db

# TO-DO: USE ENV VARS
self.kv = Redis(host = 'localhost', port=6379, db=0)
self.kv = Redis(host = settings.redis.host, password=settings.redis.password, port=settings.redis.port, db=settings.redis.db)
return self

async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: # noqa: ANN401
Expand Down
5 changes: 5 additions & 0 deletions store/settings/configs/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ email:
email: ${oc.env:ROBOLIST_SMTP_EMAIL}
password: ${oc.env:ROBOLIST_SMTP_PASSWORD}
name: ${oc.env:ROBOLIST_SMTP_NAME}
redis:
host: ${oc.env:ROBOLIST_REDIS_HOST,localhost}
port: ${oc.env:ROBOLIST_REDIS_PORT,6379}
password: ${oc.env:ROBOLIST_REDIS_PASSWORD,}
db: ${oc.env:ROBOLIST_REDIS_DB,0}
7 changes: 7 additions & 0 deletions store/settings/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

from omegaconf import MISSING

@dataclass
class RedisSettings:
host: str = field(default=MISSING)
password: str = field(default=MISSING)
port: int = field(default=6379)
db: int = field(default=0)

@dataclass
class CryptoSettings:
Expand Down Expand Up @@ -37,6 +43,7 @@ class SiteSettings:

@dataclass
class EnvironmentSettings:
redis: RedisSettings = field(default_factory=RedisSettings)
user: UserSettings = field(default_factory=UserSettings)
crypto: CryptoSettings = field(default_factory=CryptoSettings)
email: EmailSettings = field(default_factory=EmailSettings)
Expand Down

0 comments on commit eab4c8a

Please sign in to comment.