Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue 2665] Add db name to connection url and remove logging #2826

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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