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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ PgLOG.pglog("hello", PgLOG.LOGWRN)
python -c "import rda_python_common; print(rda_python_common.__version__)"
```

You should see the installed version (currently `2.1.8`). If the import
You should see the installed version (currently `2.1.9`). If the import
fails, double-check that the active Python environment is the one where you
ran `pip install`.

Expand Down
5 changes: 4 additions & 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 = "2.1.8"
version = "2.1.9"
authors = [
{ name="Zaihua Ji", email="zji@ucar.edu" },
]
Expand Down Expand Up @@ -32,5 +32,8 @@ pythonpath = [
"src"
]

[tool.setuptools.package-data]
rda_python_common = ["*.usg"]

[project.scripts]
pgpassword = "rda_python_common.pgpassword:main"
2 changes: 1 addition & 1 deletion src/rda_python_common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from . import PgLOG, PgUtil, PgDBI, PgFile, PgLock, PgCMD, PgSIG, PgOPT, PgSplit

__version__ = "2.1.8"
__version__ = "2.1.9"

__all__ = [
"PgLOG",
Expand Down
43 changes: 24 additions & 19 deletions src/rda_python_common/pgpassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,29 @@ def read_parameters(self):
Parse ``sys.argv`` and apply CLI overrides.

Recognized options:
-l URL -- OpenBao URL (stored in self.PGDBI['BAOURL'])
-k TOKEN -- OpenBao token name (stored in self.PGDBI['BAOTOKEN'])
-d NAME -- PostgreSQL database name
-c NAME -- PostgreSQL schema name
-u NAME -- PostgreSQL login user name
-h HOST -- PostgreSQL server host name
-p PORT -- PostgreSQL port number
-? / --help -- show usage and exit
-l URL -- OpenBao URL (stored in self.PGDBI['BAOURL'])
-k TOKEN -- OpenBao token name (stored in self.PGDBI['BAOTOKEN'])
-d NAME -- PostgreSQL database name
-c NAME -- PostgreSQL schema name
-u NAME -- PostgreSQL login user name
-h HOST -- PostgreSQL server host name
-p PORT -- PostgreSQL port number

If no arguments are supplied a usage message is printed and the
process exits with status 0. Unknown options or stray values
cause an immediate error exit via ``self.pglog(..., LGEREX)``.
With no arguments, all defaults inherited from PgDBI/PgLOG are
used and the password lookup proceeds. Unknown options, stray
values, or an option without its required value cause an
immediate error exit via ``self.pglog(..., LGEREX)``.
"""
argv = sys.argv[1:]
opt = None
dohelp = True
for arg in argv:
if re.match(r'^-[a-zA-Z]$', arg):
if arg in ('-?', '-help', '--help'):
self.set_help_path(__file__)
self.show_usage("pgpassword")
elif re.match(r'^-[a-zA-Z]$', arg):
if opt:
self.pglog("-" + opt + ": missing option value", self.LGEREX)
opt = arg[1:]
elif opt:
if opt == 'l':
Expand All @@ -91,13 +97,12 @@ def read_parameters(self):
self.dbopt = True
self.DBINFO[self.DBFLDS[opt]] = arg
else:
self.pglog(arg + ": Unknown option", self.LGEREX)
dohelp = False
self.pglog("-" + opt + ": Unknown option", self.LGEREX)
opt = None
else:
self.pglog(arg + ": Value provided without option", self.LGEREX)
if dohelp:
self.set_help_path(__file__)
self.show_usage("pgpassword")
self.pglog(arg + ": value provided without option", self.LGEREX)
if opt:
self.pglog("-" + opt + ": missing option value", self.LGEREX)

# get the pgpassword
def start_actions(self):
Expand All @@ -114,7 +119,7 @@ def start_actions(self):
self.password = self.get_baopassword()
if not self.password: self.password = self.get_pgpassword()

# main function to excecute this script
# main function to execute this script
def main():
"""Entry point for the ``pgpassword`` console script: print the retrieved password to stdout."""
object = PgPassword()
Expand Down
11 changes: 8 additions & 3 deletions src/rda_python_common/pgpassword.usg
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
file. The retrieved password is printed to stdout so that shell
wrappers and other RDA utilities can capture it.

Usage: pgpassword [-l OpenBaoURL] [-k TokenName] [-d DBNAME] \
Usage: pgpassword [-?] [-l OpenBaoURL] [-k TokenName] [-d DBNAME] \
[-c SCHEMA] [-u USName] [-h DBHOST] [-p DBPORT]

With no options, pgpassword retrieves the password using all defaults
inherited from PgDBI/PgLOG (see per-option defaults below).

- Option -?, show this usage information and exit (also -help
and --help);

- Option -l, OpenBao URL used to retrieve passwords. Overrides
the BAOURL value from the PgDBI configuration.
Default: https://bao.k8s.ucar.edu/
Expand All @@ -33,8 +39,7 @@
Default: 5432

If any of -d, -c, -u, -h, or -p is supplied, the values are applied
via default_scinfo() before the password lookup is performed. With no
arguments, this usage information is displayed and the program exits.
via default_scinfo() before the password lookup is performed.

Examples:

Expand Down
Loading