rda-python-common 2.0.0__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/PgCMD.py +603 -0
- rda_python_common/PgDBI.py +2306 -0
- rda_python_common/PgFile.py +3118 -0
- rda_python_common/PgLOG.py +1689 -0
- rda_python_common/PgLock.py +640 -0
- rda_python_common/PgOPT.py +1740 -0
- rda_python_common/PgSIG.py +1164 -0
- rda_python_common/PgSplit.py +299 -0
- rda_python_common/PgUtil.py +1854 -0
- rda_python_common/__init__.py +0 -0
- rda_python_common/pg_cmd.py +493 -0
- rda_python_common/pg_dbi.py +1885 -0
- rda_python_common/pg_file.py +2462 -0
- rda_python_common/pg_lock.py +533 -0
- rda_python_common/pg_log.py +1352 -0
- rda_python_common/pg_opt.py +1447 -0
- rda_python_common/pg_pass.py +92 -0
- rda_python_common/pg_sig.py +879 -0
- rda_python_common/pg_split.py +260 -0
- rda_python_common/pg_util.py +1534 -0
- rda_python_common/pgpassword.py +92 -0
- rda_python_common-2.0.0.dist-info/METADATA +20 -0
- rda_python_common-2.0.0.dist-info/RECORD +27 -0
- rda_python_common-2.0.0.dist-info/WHEEL +5 -0
- rda_python_common-2.0.0.dist-info/entry_points.txt +3 -0
- rda_python_common-2.0.0.dist-info/licenses/LICENSE +21 -0
- rda_python_common-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
##################################################################################
|
|
4
|
+
#
|
|
5
|
+
# Title: pg_pass
|
|
6
|
+
# Author: Zaihua Ji, zji@ucar.edu
|
|
7
|
+
# Date: 2025-10-27
|
|
8
|
+
# 2025-12-02 convert to class PgPassword
|
|
9
|
+
# Purpose: python script to retrieve passwords for postgrsql login to connect a
|
|
10
|
+
# gdex database from inside an python application
|
|
11
|
+
#
|
|
12
|
+
# Github: https://github.com/NCAR/rda-python-common.git
|
|
13
|
+
#
|
|
14
|
+
##################################################################################
|
|
15
|
+
|
|
16
|
+
import sys
|
|
17
|
+
import re
|
|
18
|
+
import hvac
|
|
19
|
+
from .pg_dbi import PgDBI
|
|
20
|
+
|
|
21
|
+
class PgPassword(PgDBI):
|
|
22
|
+
|
|
23
|
+
def __init__(self):
|
|
24
|
+
super().__init__() # initialize parent class
|
|
25
|
+
self.DBFLDS = {
|
|
26
|
+
'd' : 'dbname',
|
|
27
|
+
'c' : 'scname',
|
|
28
|
+
'h' : 'dbhost',
|
|
29
|
+
'p' : 'dbport',
|
|
30
|
+
'u' : 'lnname'
|
|
31
|
+
}
|
|
32
|
+
self.DBINFO = {
|
|
33
|
+
'dbname' : "",
|
|
34
|
+
'scname' : "",
|
|
35
|
+
'lnname' : "",
|
|
36
|
+
'dbhost' : "",
|
|
37
|
+
'dbport' : 5432
|
|
38
|
+
}
|
|
39
|
+
self.dbopt = False
|
|
40
|
+
self.password = ''
|
|
41
|
+
|
|
42
|
+
# read in comman line parameters
|
|
43
|
+
def read_parameters(self):
|
|
44
|
+
argv = sys.argv[1:]
|
|
45
|
+
opt = None
|
|
46
|
+
dohelp = True
|
|
47
|
+
for arg in argv:
|
|
48
|
+
if re.match(r'^-\w+$', arg):
|
|
49
|
+
opt = arg[1:]
|
|
50
|
+
elif opt:
|
|
51
|
+
if opt == 'l':
|
|
52
|
+
self.PGDBI['BAOURL'] = arg
|
|
53
|
+
elif opt == 'k':
|
|
54
|
+
self.PGDBI['BAOTOKEN'] = arg
|
|
55
|
+
elif opt in self.DBFLDS:
|
|
56
|
+
self.dbopt = True
|
|
57
|
+
self.DBINFO[self.DBFLDS[opt]] = arg
|
|
58
|
+
else:
|
|
59
|
+
self.pglog(arg + ": Unknown option", self.LGEREX)
|
|
60
|
+
dohelp = False
|
|
61
|
+
else:
|
|
62
|
+
self.pglog(arg + ": Value provided without option", self.LGEREX)
|
|
63
|
+
if dohelp:
|
|
64
|
+
print("Usage: pg_pass [-l OpenBaoURL] [-k TokenName] [-d DBNAME] \\")
|
|
65
|
+
print(" [-c SCHEMA] [-u USName] [-h DBHOST] [-p DBPORT]")
|
|
66
|
+
print(" -l OpenBao URL to retrieve passwords")
|
|
67
|
+
print(" -k OpenBao Token Name to retrieve passwords")
|
|
68
|
+
print(" -d PostgreSQL Database Name")
|
|
69
|
+
print(" -c PostgreSQL Schema Name")
|
|
70
|
+
print(" -u PostgreSQL Login User Name")
|
|
71
|
+
print(" -h PostgreSQL Server Host Name")
|
|
72
|
+
print(" -p PostgreSQL Port Number")
|
|
73
|
+
sys.exit(0)
|
|
74
|
+
|
|
75
|
+
# get the pgpassword
|
|
76
|
+
def read_pgpassword(self):
|
|
77
|
+
if self.dbopt:
|
|
78
|
+
self.default_scinfo(self.DBINFO['dbname'], self.DBINFO['scname'], self.DBINFO['dbhost'],
|
|
79
|
+
self.DBINFO['lnname'], None, self.DBINFO['dbport'])
|
|
80
|
+
self.password = self.get_baopassword()
|
|
81
|
+
if not self.password: self.password = self.get_pg_pass()
|
|
82
|
+
|
|
83
|
+
# main function to excecute this script
|
|
84
|
+
def main():
|
|
85
|
+
pgpass = PgPassword()
|
|
86
|
+
pgpass.read_parameters()
|
|
87
|
+
pgpass.read_pgpassword()
|
|
88
|
+
print(pgpass.password)
|
|
89
|
+
sys.exit(0)
|
|
90
|
+
|
|
91
|
+
# call main() to start program
|
|
92
|
+
if __name__ == "__main__": main()
|