Skip to content

Commit

Permalink
Merge pull request #511 from cymed/allow-debugging-psycopg-conn
Browse files Browse the repository at this point in the history
Add debug points to database utils
  • Loading branch information
ponceta authored Dec 20, 2024
2 parents 942b461 + 5934328 commit 249054f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugin/teksi_wastewater/utils/database_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections
import configparser
import os
import re
from typing import List

from .plugin_utils import logger
Expand Down Expand Up @@ -87,10 +88,13 @@ def read_pgservice(service_name):
# Path for pg_service.conf
if os.environ.get("PGSERVICEFILE"):
PG_CONFIG_PATH = os.environ.get("PGSERVICEFILE")
logger.debug(f"PGSERVICEFILE: {PG_CONFIG_PATH}")
elif os.environ.get("PGSYSCONFDIR"):
PG_CONFIG_PATH = os.path.join(os.environ.get("PGSYSCONFDIR"), "pg_service.conf")
logger.debug(f"PGSYSCONFDIR: {PG_CONFIG_PATH}")
else:
PG_CONFIG_PATH = os.path.expanduser("~/.pg_service.conf")
logger.debug(f"PG_CONFIG_PATH: {PG_CONFIG_PATH}")

config = configparser.ConfigParser()
if os.path.exists(PG_CONFIG_PATH):
Expand Down Expand Up @@ -134,6 +138,8 @@ def get_pgconf_as_psycopg_dsn() -> List[str]:
parts = []
for key in pgconf:
parts.append(f"{key}={pgconf[key]}")
dsn_masked_pwd = re.sub(r"(password=).+", r"\1[PASSWORD]", " ".join(parts))
logger.debug(f"psycopg dsn: {dsn_masked_pwd}")
return " ".join(parts)

@staticmethod
Expand Down

0 comments on commit 249054f

Please sign in to comment.