Skip to content
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "rda_python_common"
version = "3.0.4"
version = "3.0.5"
authors = [
{ name="Zaihua Ji", email="zji@ucar.edu" },
]
Expand Down
18 changes: 10 additions & 8 deletions src/rda_python_common/pg_dbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2624,15 +2624,17 @@ def pgname(self, str, sign = None):
def get_pgpass_password(self):
"""Return the database password for the current connection settings.

Checks PGDBI['PWNAME'] first, then tries OpenBao (get_baopassword()), and
finally falls back to the .pgpass file (get_pgpassword()).
Checks PGDBI['PWNAME'] first, then tries the .pgpass file (get_pgpassword()),
and finally falls back to OpenBao (get_baopassword()).

Returns:
str | None: Password string, or None when no credential is found.
"""
if self.PGDBI['PWNAME']: return self.PGDBI['PWNAME']
pwname = self.get_baopassword()
if not pwname: pwname = self.get_pgpassword()
pwname = self.get_pgpassword()
if not pwname: pwname = self.get_baopassword()
if not pwname:
self.pglog("Unable to find password for {} in .pgpass or OpenBao".format(self.PGDBI['DBNAME']), self.PGDBI['ERRLOG'])
return pwname

def get_pgpassword(self):
Expand Down Expand Up @@ -2677,8 +2679,8 @@ def read_pgpass(self):
if not line or line.startswith("#"): continue
dbhost, dbport, dbname, lnname, pwname = line.split(":")
self.DBPASS[(dbhost, dbport, dbname, lnname)] = pwname
except Exception as e:
self.pglog(str(e), self.PGDBI['ERRLOG'])
except Exception:
pass
Comment on lines 2679 to +2683

def read_openbao(self):
"""Read OpenBao secrets and populate DBBAOS with credentials for DBNAME.
Expand All @@ -2703,8 +2705,8 @@ def read_openbao(self):
mount_point='kv',
raise_on_deleted_version=False
)
except Exception as e:
return self.pglog(str(e), self.PGDBI['ERRLOG'])
except Exception:
return
Comment on lines 2707 to +2709
baos = read_response['data']['data']
for key in baos:
ms = re.match(r'^(\w*)pass(\w*)$', key)
Expand Down
Loading