rda-python-common 2.1.8__py3-none-any.whl → 2.1.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rda_python_common/__init__.py +1 -1
- rda_python_common/pg_cmd.py +7 -1
- rda_python_common/pg_log.py +12 -7
- rda_python_common/pgpassword.py +24 -19
- rda_python_common/pgpassword.usg +57 -0
- {rda_python_common-2.1.8.dist-info → rda_python_common-2.1.10.dist-info}/METADATA +2 -2
- {rda_python_common-2.1.8.dist-info → rda_python_common-2.1.10.dist-info}/RECORD +11 -10
- {rda_python_common-2.1.8.dist-info → rda_python_common-2.1.10.dist-info}/WHEEL +0 -0
- {rda_python_common-2.1.8.dist-info → rda_python_common-2.1.10.dist-info}/entry_points.txt +0 -0
- {rda_python_common-2.1.8.dist-info → rda_python_common-2.1.10.dist-info}/licenses/LICENSE +0 -0
- {rda_python_common-2.1.8.dist-info → rda_python_common-2.1.10.dist-info}/top_level.txt +0 -0
rda_python_common/__init__.py
CHANGED
rda_python_common/pg_cmd.py
CHANGED
|
@@ -389,7 +389,7 @@ class PgCMD(PgLock):
|
|
|
389
389
|
if pgrqst: pgctl = self.get_dsrqst_control(pgrqst, logact)
|
|
390
390
|
return pgctl
|
|
391
391
|
|
|
392
|
-
def get_dynamic_options(self, cmd, oindex, otype):
|
|
392
|
+
def get_dynamic_options(self, cmd, oindex, otype, hostname=None):
|
|
393
393
|
"""Runs cmd to retrieve dynamic option strings, retrying on timeout.
|
|
394
394
|
|
|
395
395
|
Executes the command up to three times, retrying when a connection
|
|
@@ -401,6 +401,11 @@ class PgCMD(PgLock):
|
|
|
401
401
|
oindex (int or None): Object index appended to cmd when truthy.
|
|
402
402
|
otype (str or None): Object type appended to cmd when truthy;
|
|
403
403
|
'R' selects the first option from a slash-separated pair.
|
|
404
|
+
hostname (str or None): If provided, the command is executed
|
|
405
|
+
remotely via ``ssh <hostname> ...`` instead of locally; the
|
|
406
|
+
leading command name is resolved to its absolute path via
|
|
407
|
+
``command_path`` so the remote shell does not depend on its
|
|
408
|
+
own PATH.
|
|
404
409
|
|
|
405
410
|
Returns:
|
|
406
411
|
str: The parsed option string, or '' if the command produced no
|
|
@@ -408,6 +413,7 @@ class PgCMD(PgLock):
|
|
|
408
413
|
"""
|
|
409
414
|
if oindex: cmd += " {}".format(oindex)
|
|
410
415
|
if otype: cmd += ' ' + otype
|
|
416
|
+
if hostname: cmd = "ssh {} {}".format(hostname, self.command_path(cmd))
|
|
411
417
|
ret = options = ''
|
|
412
418
|
for loop in range(3):
|
|
413
419
|
ret = self.pgsystem(cmd, self.LOGWRN, 1299) # 1+2+16+256+1024
|
rda_python_common/pg_log.py
CHANGED
|
@@ -180,6 +180,7 @@ class PgLOG:
|
|
|
180
180
|
self.BCHCMDS = {'PBS': 'qsub'}
|
|
181
181
|
# global dists to cashe information
|
|
182
182
|
self.COMMANDS = {}
|
|
183
|
+
self.CMDPATHS = {} # cache of bare command name -> full path (or '' if not found)
|
|
183
184
|
self.PBSHOSTS = []
|
|
184
185
|
self.PBSSTATS = {}
|
|
185
186
|
# set additional common PGLOG values
|
|
@@ -1197,15 +1198,19 @@ class PgLOG:
|
|
|
1197
1198
|
Returns:
|
|
1198
1199
|
String with the leading command resolved to its full path, or the
|
|
1199
1200
|
original *cmdstr* if the command already contains a path separator
|
|
1200
|
-
or cannot be found via ``shutil.which``.
|
|
1201
|
+
or cannot be found via ``shutil.which``. Results of the
|
|
1202
|
+
``shutil.which`` lookup are cached in ``self.CMDPATHS``.
|
|
1201
1203
|
"""
|
|
1202
1204
|
if not cmdstr: return ''
|
|
1203
|
-
|
|
1204
|
-
cmd =
|
|
1205
|
-
if
|
|
1206
|
-
|
|
1207
|
-
pcmd
|
|
1208
|
-
|
|
1205
|
+
sp = cmdstr.find(' ')
|
|
1206
|
+
cmd = cmdstr if sp < 0 else cmdstr[:sp]
|
|
1207
|
+
if '/' in cmd or '\\' in cmd: return cmdstr
|
|
1208
|
+
pcmd = self.CMDPATHS.get(cmd)
|
|
1209
|
+
if pcmd is None:
|
|
1210
|
+
pcmd = shutil.which(cmd) or ''
|
|
1211
|
+
self.CMDPATHS[cmd] = pcmd
|
|
1212
|
+
if not pcmd: return cmdstr
|
|
1213
|
+
return pcmd if sp < 0 else pcmd + cmdstr[sp:]
|
|
1209
1214
|
|
|
1210
1215
|
def add_carbon_copy(self, cc=None, isstr=None, exclude=0, specialist=None):
|
|
1211
1216
|
"""Update the Cc address list in ``PGLOG['CCDADDR']``.
|
rda_python_common/pgpassword.py
CHANGED
|
@@ -64,23 +64,29 @@ class PgPassword(PgDBI):
|
|
|
64
64
|
Parse ``sys.argv`` and apply CLI overrides.
|
|
65
65
|
|
|
66
66
|
Recognized options:
|
|
67
|
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
70
|
-
-
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
67
|
+
-? / --help -- show usage and exit
|
|
68
|
+
-l URL -- OpenBao URL (stored in self.PGDBI['BAOURL'])
|
|
69
|
+
-k TOKEN -- OpenBao token name (stored in self.PGDBI['BAOTOKEN'])
|
|
70
|
+
-d NAME -- PostgreSQL database name
|
|
71
|
+
-c NAME -- PostgreSQL schema name
|
|
72
|
+
-u NAME -- PostgreSQL login user name
|
|
73
|
+
-h HOST -- PostgreSQL server host name
|
|
74
|
+
-p PORT -- PostgreSQL port number
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
With no arguments, all defaults inherited from PgDBI/PgLOG are
|
|
77
|
+
used and the password lookup proceeds. Unknown options, stray
|
|
78
|
+
values, or an option without its required value cause an
|
|
79
|
+
immediate error exit via ``self.pglog(..., LGEREX)``.
|
|
78
80
|
"""
|
|
79
81
|
argv = sys.argv[1:]
|
|
80
82
|
opt = None
|
|
81
|
-
dohelp = True
|
|
82
83
|
for arg in argv:
|
|
83
|
-
if
|
|
84
|
+
if arg in ('-?', '-help', '--help'):
|
|
85
|
+
self.set_help_path(__file__)
|
|
86
|
+
self.show_usage("pgpassword")
|
|
87
|
+
elif re.match(r'^-[a-zA-Z]$', arg):
|
|
88
|
+
if opt:
|
|
89
|
+
self.pglog("-" + opt + ": missing option value", self.LGEREX)
|
|
84
90
|
opt = arg[1:]
|
|
85
91
|
elif opt:
|
|
86
92
|
if opt == 'l':
|
|
@@ -91,13 +97,12 @@ class PgPassword(PgDBI):
|
|
|
91
97
|
self.dbopt = True
|
|
92
98
|
self.DBINFO[self.DBFLDS[opt]] = arg
|
|
93
99
|
else:
|
|
94
|
-
self.pglog(
|
|
95
|
-
|
|
100
|
+
self.pglog("-" + opt + ": Unknown option", self.LGEREX)
|
|
101
|
+
opt = None
|
|
96
102
|
else:
|
|
97
|
-
self.pglog(arg + ":
|
|
98
|
-
if
|
|
99
|
-
self.
|
|
100
|
-
self.show_usage("pgpassword")
|
|
103
|
+
self.pglog(arg + ": value provided without option", self.LGEREX)
|
|
104
|
+
if opt:
|
|
105
|
+
self.pglog("-" + opt + ": missing option value", self.LGEREX)
|
|
101
106
|
|
|
102
107
|
# get the pgpassword
|
|
103
108
|
def start_actions(self):
|
|
@@ -114,7 +119,7 @@ class PgPassword(PgDBI):
|
|
|
114
119
|
self.password = self.get_baopassword()
|
|
115
120
|
if not self.password: self.password = self.get_pgpassword()
|
|
116
121
|
|
|
117
|
-
# main function to
|
|
122
|
+
# main function to execute this script
|
|
118
123
|
def main():
|
|
119
124
|
"""Entry point for the ``pgpassword`` console script: print the retrieved password to stdout."""
|
|
120
125
|
object = PgPassword()
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
Retrieve a PostgreSQL login password for use by RDA python applications.
|
|
3
|
+
The password is looked up first from OpenBao (using the URL and token
|
|
4
|
+
configured in PgDBI) and, if not found there, from the user's .pgpass
|
|
5
|
+
file. The retrieved password is printed to stdout so that shell
|
|
6
|
+
wrappers and other RDA utilities can capture it.
|
|
7
|
+
|
|
8
|
+
Usage: pgpassword [-?] [-l OpenBaoURL] [-k TokenName] [-d DBNAME] \
|
|
9
|
+
[-c SCHEMA] [-u USName] [-h DBHOST] [-p DBPORT]
|
|
10
|
+
|
|
11
|
+
With no options, pgpassword retrieves the password using all defaults
|
|
12
|
+
inherited from PgDBI/PgLOG (see per-option defaults below).
|
|
13
|
+
|
|
14
|
+
- Option -?, show this usage information and exit (also -help
|
|
15
|
+
and --help);
|
|
16
|
+
|
|
17
|
+
- Option -l, OpenBao URL used to retrieve passwords. Overrides
|
|
18
|
+
the BAOURL value from the PgDBI configuration.
|
|
19
|
+
Default: https://bao.k8s.ucar.edu/
|
|
20
|
+
|
|
21
|
+
- Option -k, OpenBao token name used to authenticate the password
|
|
22
|
+
lookup. Overrides the BAOTOKEN value from the PgDBI
|
|
23
|
+
configuration.
|
|
24
|
+
|
|
25
|
+
- Option -d, PostgreSQL database name.
|
|
26
|
+
Default: rdadb
|
|
27
|
+
|
|
28
|
+
- Option -c, PostgreSQL schema name.
|
|
29
|
+
Default: dssdb
|
|
30
|
+
|
|
31
|
+
- Option -u, PostgreSQL login user name.
|
|
32
|
+
Default: dssdb (same as the -c default)
|
|
33
|
+
|
|
34
|
+
- Option -h, PostgreSQL server host name.
|
|
35
|
+
Default: value of the DSSDBHOST environment variable, or
|
|
36
|
+
rda-db.ucar.edu if DSSDBHOST is not set.
|
|
37
|
+
|
|
38
|
+
- Option -p, PostgreSQL server port number.
|
|
39
|
+
Default: 5432
|
|
40
|
+
|
|
41
|
+
If any of -d, -c, -u, -h, or -p is supplied, the values are applied
|
|
42
|
+
via default_scinfo() before the password lookup is performed.
|
|
43
|
+
|
|
44
|
+
Examples:
|
|
45
|
+
|
|
46
|
+
1. Retrieve the password for the default database/user configured
|
|
47
|
+
in PgDBI:
|
|
48
|
+
|
|
49
|
+
pgpassword
|
|
50
|
+
|
|
51
|
+
2. Retrieve the password for a specific database, schema and user:
|
|
52
|
+
|
|
53
|
+
pgpassword -d rdadb -c dssdb -u metauser
|
|
54
|
+
|
|
55
|
+
3. Retrieve the password from a custom OpenBao endpoint:
|
|
56
|
+
|
|
57
|
+
pgpassword -l https://bao.example.org -k my-token -d rdadb
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rda_python_common
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.10
|
|
4
4
|
Summary: RDA Python common library codes shared by other RDA python packages
|
|
5
5
|
Author-email: Zaihua Ji <zji@ucar.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/NCAR/rda-python-common
|
|
@@ -92,7 +92,7 @@ PgLOG.pglog("hello", PgLOG.LOGWRN)
|
|
|
92
92
|
python -c "import rda_python_common; print(rda_python_common.__version__)"
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
You should see the installed version (currently `2.1.
|
|
95
|
+
You should see the installed version (currently `2.1.10`). If the import
|
|
96
96
|
fails, double-check that the active Python environment is the one where you
|
|
97
97
|
ran `pip install`.
|
|
98
98
|
|
|
@@ -7,21 +7,22 @@ rda_python_common/PgOPT.py,sha256=Kn4JYezZhZwAn2usiIYHoHiymGHRgsN299dxyXbKwkI,56
|
|
|
7
7
|
rda_python_common/PgSIG.py,sha256=eTJJ3XxutsQ3JSg6uYRpH26ZmrVUup3ShqDFLWXLruA,35803
|
|
8
8
|
rda_python_common/PgSplit.py,sha256=SSg5_Qu5PqP44EkqebO-V_cErNcdE2QtORgFHQ7RqlQ,8822
|
|
9
9
|
rda_python_common/PgUtil.py,sha256=OqESKCd72b9g8m8jwjPJhXDtPYlW6G8oSOhwChvz2Cg,48600
|
|
10
|
-
rda_python_common/__init__.py,sha256=
|
|
11
|
-
rda_python_common/pg_cmd.py,sha256=
|
|
10
|
+
rda_python_common/__init__.py,sha256=FNcDisQ9NznJzOx1igxplnMqrQulXb-D3Kqi6o8hxDY,995
|
|
11
|
+
rda_python_common/pg_cmd.py,sha256=PiQaAeb7l92LceqMwSzLpz9nD5pDRHJcEZxTDn-HeCs,33255
|
|
12
12
|
rda_python_common/pg_dbi.py,sha256=q6LT4a4lwo-sM2LEqgrEVkAlh886xeKiz4feqRKw-7c,116238
|
|
13
13
|
rda_python_common/pg_file.py,sha256=RzQTxnht4bFOVty4qoYPREawMCUsnFIbWm2pfEez1fE,161993
|
|
14
14
|
rda_python_common/pg_lock.py,sha256=31EaVDjCkcx3-n8-KnzG18R8Pz7Z6KyFsEqcml6Iq5c,32702
|
|
15
|
-
rda_python_common/pg_log.py,sha256=
|
|
15
|
+
rda_python_common/pg_log.py,sha256=Vr0z7mujcotvHEEXNPbJRUx5gNbBWfVGZJ30ms9h7iE,80953
|
|
16
16
|
rda_python_common/pg_opt.py,sha256=sXrlzFWpR2XMak6NlA0MPvErBuQnY6gHM5OsHtoeIPQ,82496
|
|
17
17
|
rda_python_common/pg_password.py,sha256=X-eIDwdqBhtrhrbDTNWle-0JtWsyIVZdDOZaBu7cFHM,2343
|
|
18
18
|
rda_python_common/pg_sig.py,sha256=wLKBmFNWAmxWJFC2L3SLsD4n464kzzHbIFFNBlCW6kI,52759
|
|
19
19
|
rda_python_common/pg_split.py,sha256=aAWKUZPmZ-LQ_fJ3DSKzPKxJw0fMDJ2fgP8ZT629M30,16375
|
|
20
20
|
rda_python_common/pg_util.py,sha256=bjp2civRIhqaBSR8oOtyRzYIZBdwB90SzmJLjRIA7fc,87280
|
|
21
|
-
rda_python_common/pgpassword.py,sha256=
|
|
22
|
-
rda_python_common
|
|
23
|
-
rda_python_common-2.1.
|
|
24
|
-
rda_python_common-2.1.
|
|
25
|
-
rda_python_common-2.1.
|
|
26
|
-
rda_python_common-2.1.
|
|
27
|
-
rda_python_common-2.1.
|
|
21
|
+
rda_python_common/pgpassword.py,sha256=aTQaO59QokWrv2EKom4TvKhNW2Mr6aFMMBVG4DCbcKI,5023
|
|
22
|
+
rda_python_common/pgpassword.usg,sha256=Wrle6A8sdlMGx3ZEAmE6TNDPOlG84Whe0T3rCNFzPfY,2013
|
|
23
|
+
rda_python_common-2.1.10.dist-info/licenses/LICENSE,sha256=1dck4EAQwv8QweDWCXDx-4Or0S8YwiCstaso_H57Pno,1097
|
|
24
|
+
rda_python_common-2.1.10.dist-info/METADATA,sha256=uA5vJ1a2J-arJe3_pMzR4PMj6fGlaWKz1ZVqJLCAhGE,11092
|
|
25
|
+
rda_python_common-2.1.10.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
26
|
+
rda_python_common-2.1.10.dist-info/entry_points.txt,sha256=pZgVNWspcK-F1TbPav7C3C9NdeHDZMm_25fW9weix00,65
|
|
27
|
+
rda_python_common-2.1.10.dist-info/top_level.txt,sha256=KVQmx7D3DD-jsiheqL8HdTrRE14hpRnZY5_ioMArA5k,18
|
|
28
|
+
rda_python_common-2.1.10.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|