Skip to content

Commit

Permalink
add db name to connection url; remove logging
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidDudas-Intuitial committed Nov 13, 2024
1 parent 7f943c5 commit 14b7eeb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
1 change: 1 addition & 0 deletions analytics/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PydanticBaseEnvConfig(BaseSettings):

class DBSettings(PydanticBaseEnvConfig):
db_host: str = Field(alias="DB_HOST")
name: str = Field(alias="DB_NAME")
port: int = Field(5432,alias="DB_PORT")
user: str = Field (alias="DB_USER")
password: Optional[str] = Field(None, alias="DB_PASSWORD")
Expand Down
9 changes: 2 additions & 7 deletions analytics/src/analytics/integrations/db.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# pylint: disable=invalid-name, line-too-long
"""Get a connection to the database using a SQLAlchemy engine object."""

import os

import boto3
from sqlalchemy import Engine, create_engine

Expand All @@ -27,15 +25,12 @@ def get_db() -> Engine:
db = get_db_settings()
# inspired by simpler-grants-gov/blob/main/api/src/adapters/db/clients/postgres_client.py
token = db.password if db.local_env is True else generate_iam_auth_token(db)
url = f"postgresql+psycopg://{db.user}:{token}@{db.db_host}:{db.port}?sslmode={db.ssl_mode}"
print(f"TEMP DEBUG: environment = {os.getenv('ENVIRONMENT', 'local')}")
print(f"TEMP DEBUG: db settings = {db}")
print(f"TEMP DEBUG: token has non-zero len? {len(str(token)) > 0}")
url = f"postgresql+psycopg://{db.user}:{token}@{db.db_host}:{db.port}/{db.name}?sslmode={db.ssl_mode}"

return create_engine(
url,
pool_pre_ping=True,
hide_parameters=False,
hide_parameters=True,
)


Expand Down

0 comments on commit 14b7eeb

Please sign in to comment.