rda-python-common 2.0.2__py3-none-any.whl → 2.0.4__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/pg_password.py +91 -0
- rda_python_common/pgpassword.py +65 -66
- {rda_python_common-2.0.2.dist-info → rda_python_common-2.0.4.dist-info}/METADATA +1 -1
- {rda_python_common-2.0.2.dist-info → rda_python_common-2.0.4.dist-info}/RECORD +8 -8
- {rda_python_common-2.0.2.dist-info → rda_python_common-2.0.4.dist-info}/entry_points.txt +0 -1
- rda_python_common/pg_pass.py +0 -91
- {rda_python_common-2.0.2.dist-info → rda_python_common-2.0.4.dist-info}/WHEEL +0 -0
- {rda_python_common-2.0.2.dist-info → rda_python_common-2.0.4.dist-info}/licenses/LICENSE +0 -0
- {rda_python_common-2.0.2.dist-info → rda_python_common-2.0.4.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
##################################################################################
|
|
4
|
+
#
|
|
5
|
+
# Title: pg_password
|
|
6
|
+
# Author: Zaihua Ji, zji@ucar.edu
|
|
7
|
+
# Date: 2025-10-27
|
|
8
|
+
# Purpose: python script to retrieve passwords for postgrsql login to connect a
|
|
9
|
+
# gdex database from inside an python application
|
|
10
|
+
#
|
|
11
|
+
# Github: https://github.com/NCAR/rda-python-common.git
|
|
12
|
+
#
|
|
13
|
+
##################################################################################
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
import re
|
|
18
|
+
import pwd
|
|
19
|
+
import hvac
|
|
20
|
+
from . import PgLOG
|
|
21
|
+
from . import PgDBI
|
|
22
|
+
|
|
23
|
+
DBFLDS = {
|
|
24
|
+
'd' : 'dbname',
|
|
25
|
+
'c' : 'scname',
|
|
26
|
+
'h' : 'dbhost',
|
|
27
|
+
'p' : 'dbport',
|
|
28
|
+
'u' : 'lnname'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
DBINFO = {
|
|
32
|
+
'dbname' : "",
|
|
33
|
+
'scname' : "",
|
|
34
|
+
'lnname' : "",
|
|
35
|
+
'dbhost' : "",
|
|
36
|
+
'dbport' : 5432
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#
|
|
40
|
+
# main function to excecute this script
|
|
41
|
+
#
|
|
42
|
+
def main():
|
|
43
|
+
|
|
44
|
+
permit = False
|
|
45
|
+
argv = sys.argv[1:]
|
|
46
|
+
opt = None
|
|
47
|
+
dohelp = True
|
|
48
|
+
dbopt = False
|
|
49
|
+
|
|
50
|
+
for arg in argv:
|
|
51
|
+
if re.match(r'^-\w+$', arg):
|
|
52
|
+
opt = arg[1:]
|
|
53
|
+
elif opt:
|
|
54
|
+
if opt == 'l':
|
|
55
|
+
PgDBI.PGDBI['BAOURL'] = arg
|
|
56
|
+
elif opt == 'k':
|
|
57
|
+
PgDBI.PGDBI['BAOTOKEN'] = arg
|
|
58
|
+
elif opt in DBFLDS:
|
|
59
|
+
dbopt = True
|
|
60
|
+
DBINFO[DBFLDS[opt]] = arg
|
|
61
|
+
else:
|
|
62
|
+
PgLOG.pglog(arg + ": Unknown option", PgLOG.LGEREX)
|
|
63
|
+
dohelp = False
|
|
64
|
+
else:
|
|
65
|
+
PgLOG.pglog(arg + ": Value provided without option", PgLOG.LGEREX)
|
|
66
|
+
|
|
67
|
+
if dohelp:
|
|
68
|
+
print("Usage: pg_password [-l OpenBaoURL] [-k TokenName] [-d DBNAME] \\")
|
|
69
|
+
print(" [-c SCHEMA] [-u USName] [-h DBHOST] [-p DBPORT]")
|
|
70
|
+
print(" -l OpenBao URL to retrieve passwords")
|
|
71
|
+
print(" -k OpenBao Token Name to retrieve passwords")
|
|
72
|
+
print(" -d PostgreSQL Database Name")
|
|
73
|
+
print(" -c PostgreSQL Schema Name")
|
|
74
|
+
print(" -u PostgreSQL Login User Name")
|
|
75
|
+
print(" -h PostgreSQL Server Host Name")
|
|
76
|
+
print(" -p PostgreSQL Port Number")
|
|
77
|
+
sys.exit(0)
|
|
78
|
+
|
|
79
|
+
if dbopt:
|
|
80
|
+
PgDBI.default_scinfo(DBINFO['dbname'], DBINFO['scname'], DBINFO['dbhost'],
|
|
81
|
+
DBINFO['lnname'], None, DBINFO['dbport'])
|
|
82
|
+
|
|
83
|
+
pwname = PgDBI.get_baopassword()
|
|
84
|
+
if not pwname: pwname = PgDBI.get_pgpassword()
|
|
85
|
+
print(pwname)
|
|
86
|
+
sys.exit(0)
|
|
87
|
+
|
|
88
|
+
#
|
|
89
|
+
# call main() to start program
|
|
90
|
+
#
|
|
91
|
+
if __name__ == "__main__": main()
|
rda_python_common/pgpassword.py
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
# Title: pgpassword
|
|
6
6
|
# Author: Zaihua Ji, zji@ucar.edu
|
|
7
7
|
# Date: 2025-10-27
|
|
8
|
+
# 2025-12-02 convert to class PgPassword
|
|
8
9
|
# Purpose: python script to retrieve passwords for postgrsql login to connect a
|
|
9
10
|
# gdex database from inside an python application
|
|
10
11
|
#
|
|
@@ -12,81 +13,79 @@
|
|
|
12
13
|
#
|
|
13
14
|
##################################################################################
|
|
14
15
|
|
|
15
|
-
import os
|
|
16
16
|
import sys
|
|
17
17
|
import re
|
|
18
|
-
import
|
|
19
|
-
import hvac
|
|
20
|
-
from . import PgLOG
|
|
21
|
-
from . import PgDBI
|
|
18
|
+
from .pg_dbi import PgDBI
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
'd' : 'dbname',
|
|
25
|
-
'c' : 'scname',
|
|
26
|
-
'h' : 'dbhost',
|
|
27
|
-
'p' : 'dbport',
|
|
28
|
-
'u' : 'lnname'
|
|
29
|
-
}
|
|
20
|
+
class PgPassword(PgDBI):
|
|
30
21
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
def __init__(self):
|
|
23
|
+
super().__init__() # initialize parent class
|
|
24
|
+
self.DBFLDS = {
|
|
25
|
+
'd' : 'dbname',
|
|
26
|
+
'c' : 'scname',
|
|
27
|
+
'h' : 'dbhost',
|
|
28
|
+
'p' : 'dbport',
|
|
29
|
+
'u' : 'lnname'
|
|
30
|
+
}
|
|
31
|
+
self.DBINFO = {
|
|
32
|
+
'dbname' : "",
|
|
33
|
+
'scname' : "",
|
|
34
|
+
'lnname' : "",
|
|
35
|
+
'dbhost' : "",
|
|
36
|
+
'dbport' : 5432
|
|
37
|
+
}
|
|
38
|
+
self.dbopt = False
|
|
39
|
+
self.password = ''
|
|
38
40
|
|
|
39
|
-
#
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
PgDBI.PGDBI['BAOTOKEN'] = arg
|
|
59
|
-
elif opt in DBFLDS:
|
|
60
|
-
dbopt = True
|
|
61
|
-
DBINFO[DBFLDS[opt]] = arg
|
|
41
|
+
# read in command line parameters
|
|
42
|
+
def read_parameters(self):
|
|
43
|
+
argv = sys.argv[1:]
|
|
44
|
+
opt = None
|
|
45
|
+
dohelp = True
|
|
46
|
+
for arg in argv:
|
|
47
|
+
if re.match(r'^-\w+$', arg):
|
|
48
|
+
opt = arg[1:]
|
|
49
|
+
elif opt:
|
|
50
|
+
if opt == 'l':
|
|
51
|
+
self.PGDBI['BAOURL'] = arg
|
|
52
|
+
elif opt == 'k':
|
|
53
|
+
self.PGDBI['BAOTOKEN'] = arg
|
|
54
|
+
elif opt in self.DBFLDS:
|
|
55
|
+
self.dbopt = True
|
|
56
|
+
self.DBINFO[self.DBFLDS[opt]] = arg
|
|
57
|
+
else:
|
|
58
|
+
self.pglog(arg + ": Unknown option", self.LGEREX)
|
|
59
|
+
dohelp = False
|
|
62
60
|
else:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
self.pglog(arg + ": Value provided without option", self.LGEREX)
|
|
62
|
+
if dohelp:
|
|
63
|
+
print("Usage: pgpassword [-l OpenBaoURL] [-k TokenName] [-d DBNAME] \\")
|
|
64
|
+
print(" [-c SCHEMA] [-u USName] [-h DBHOST] [-p DBPORT]")
|
|
65
|
+
print(" -l OpenBao URL to retrieve passwords")
|
|
66
|
+
print(" -k OpenBao Token Name to retrieve passwords")
|
|
67
|
+
print(" -d PostgreSQL Database Name")
|
|
68
|
+
print(" -c PostgreSQL Schema Name")
|
|
69
|
+
print(" -u PostgreSQL Login User Name")
|
|
70
|
+
print(" -h PostgreSQL Server Host Name")
|
|
71
|
+
print(" -p PostgreSQL Port Number")
|
|
72
|
+
sys.exit(0)
|
|
67
73
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
print(" -u PostgreSQL Login User Name")
|
|
76
|
-
print(" -h PostgreSQL Server Host Name")
|
|
77
|
-
print(" -p PostgreSQL Port Number")
|
|
78
|
-
sys.exit(0)
|
|
74
|
+
# get the pgpassword
|
|
75
|
+
def start_actions(self):
|
|
76
|
+
if self.dbopt:
|
|
77
|
+
self.default_scinfo(self.DBINFO['dbname'], self.DBINFO['scname'], self.DBINFO['dbhost'],
|
|
78
|
+
self.DBINFO['lnname'], None, self.DBINFO['dbport'])
|
|
79
|
+
self.password = self.get_baopassword()
|
|
80
|
+
if not self.password: self.password = self.get_pg_pass()
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
print(pwname)
|
|
82
|
+
# main function to excecute this script
|
|
83
|
+
def main():
|
|
84
|
+
object = PgPassword()
|
|
85
|
+
object.read_parameters()
|
|
86
|
+
object.start_actions()
|
|
87
|
+
print(object.password)
|
|
87
88
|
sys.exit(0)
|
|
88
89
|
|
|
89
|
-
#
|
|
90
90
|
# call main() to start program
|
|
91
|
-
#
|
|
92
91
|
if __name__ == "__main__": main()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rda_python_common
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.4
|
|
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
|
|
@@ -14,14 +14,14 @@ rda_python_common/pg_file.py,sha256=FoBC5GyLrXcSewUC6dfTj_QeDO1HTFDeF15CdTfXH_c,
|
|
|
14
14
|
rda_python_common/pg_lock.py,sha256=BsyPebNOKtui0Wf_JCmIm89wrH5EUQfTD_vr8HcQ3wo,24098
|
|
15
15
|
rda_python_common/pg_log.py,sha256=RKL05xDvxyJcsCdWtwY1AyBs4kXwOvQsNITOXBgngSI,60109
|
|
16
16
|
rda_python_common/pg_opt.py,sha256=yqOrTrDjq0sEQiN5uCR1mhfwwEqTc99qi0u0kmkk5dg,62707
|
|
17
|
-
rda_python_common/
|
|
17
|
+
rda_python_common/pg_password.py,sha256=X-eIDwdqBhtrhrbDTNWle-0JtWsyIVZdDOZaBu7cFHM,2343
|
|
18
18
|
rda_python_common/pg_sig.py,sha256=_NBXhjB-4_rJEgj8UUmOq52IUXNINld_iICsRrdztso,36782
|
|
19
19
|
rda_python_common/pg_split.py,sha256=v3xufJ1_CiFHR4wejLm5k0TDKJmeKPqu0kdLEBoWe-A,10057
|
|
20
20
|
rda_python_common/pg_util.py,sha256=12a0z9zMBo2aZWYS-j0vQvnFDHhdkmMwcPxtHxRvEjE,54868
|
|
21
|
-
rda_python_common/pgpassword.py,sha256=
|
|
22
|
-
rda_python_common-2.0.
|
|
23
|
-
rda_python_common-2.0.
|
|
24
|
-
rda_python_common-2.0.
|
|
25
|
-
rda_python_common-2.0.
|
|
26
|
-
rda_python_common-2.0.
|
|
27
|
-
rda_python_common-2.0.
|
|
21
|
+
rda_python_common/pgpassword.py,sha256=rR3qBZvz-jIxnbQwGCQSgyh1gZmDSenl1l0Rp6G2rvE,2919
|
|
22
|
+
rda_python_common-2.0.4.dist-info/licenses/LICENSE,sha256=1dck4EAQwv8QweDWCXDx-4Or0S8YwiCstaso_H57Pno,1097
|
|
23
|
+
rda_python_common-2.0.4.dist-info/METADATA,sha256=28eZFtoWatYrLoVWgpuAgQyydFn07avGEw6PxmWQ-JE,740
|
|
24
|
+
rda_python_common-2.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
25
|
+
rda_python_common-2.0.4.dist-info/entry_points.txt,sha256=pZgVNWspcK-F1TbPav7C3C9NdeHDZMm_25fW9weix00,65
|
|
26
|
+
rda_python_common-2.0.4.dist-info/top_level.txt,sha256=KVQmx7D3DD-jsiheqL8HdTrRE14hpRnZY5_ioMArA5k,18
|
|
27
|
+
rda_python_common-2.0.4.dist-info/RECORD,,
|
rda_python_common/pg_pass.py
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
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
|
-
from .pg_dbi import PgDBI
|
|
19
|
-
|
|
20
|
-
class PgPassword(PgDBI):
|
|
21
|
-
|
|
22
|
-
def __init__(self):
|
|
23
|
-
super().__init__() # initialize parent class
|
|
24
|
-
self.DBFLDS = {
|
|
25
|
-
'd' : 'dbname',
|
|
26
|
-
'c' : 'scname',
|
|
27
|
-
'h' : 'dbhost',
|
|
28
|
-
'p' : 'dbport',
|
|
29
|
-
'u' : 'lnname'
|
|
30
|
-
}
|
|
31
|
-
self.DBINFO = {
|
|
32
|
-
'dbname' : "",
|
|
33
|
-
'scname' : "",
|
|
34
|
-
'lnname' : "",
|
|
35
|
-
'dbhost' : "",
|
|
36
|
-
'dbport' : 5432
|
|
37
|
-
}
|
|
38
|
-
self.dbopt = False
|
|
39
|
-
self.password = ''
|
|
40
|
-
|
|
41
|
-
# read in command line parameters
|
|
42
|
-
def read_parameters(self):
|
|
43
|
-
argv = sys.argv[1:]
|
|
44
|
-
opt = None
|
|
45
|
-
dohelp = True
|
|
46
|
-
for arg in argv:
|
|
47
|
-
if re.match(r'^-\w+$', arg):
|
|
48
|
-
opt = arg[1:]
|
|
49
|
-
elif opt:
|
|
50
|
-
if opt == 'l':
|
|
51
|
-
self.PGDBI['BAOURL'] = arg
|
|
52
|
-
elif opt == 'k':
|
|
53
|
-
self.PGDBI['BAOTOKEN'] = arg
|
|
54
|
-
elif opt in self.DBFLDS:
|
|
55
|
-
self.dbopt = True
|
|
56
|
-
self.DBINFO[self.DBFLDS[opt]] = arg
|
|
57
|
-
else:
|
|
58
|
-
self.pglog(arg + ": Unknown option", self.LGEREX)
|
|
59
|
-
dohelp = False
|
|
60
|
-
else:
|
|
61
|
-
self.pglog(arg + ": Value provided without option", self.LGEREX)
|
|
62
|
-
if dohelp:
|
|
63
|
-
print("Usage: pg_pass [-l OpenBaoURL] [-k TokenName] [-d DBNAME] \\")
|
|
64
|
-
print(" [-c SCHEMA] [-u USName] [-h DBHOST] [-p DBPORT]")
|
|
65
|
-
print(" -l OpenBao URL to retrieve passwords")
|
|
66
|
-
print(" -k OpenBao Token Name to retrieve passwords")
|
|
67
|
-
print(" -d PostgreSQL Database Name")
|
|
68
|
-
print(" -c PostgreSQL Schema Name")
|
|
69
|
-
print(" -u PostgreSQL Login User Name")
|
|
70
|
-
print(" -h PostgreSQL Server Host Name")
|
|
71
|
-
print(" -p PostgreSQL Port Number")
|
|
72
|
-
sys.exit(0)
|
|
73
|
-
|
|
74
|
-
# get the pgpassword
|
|
75
|
-
def start_actions(self):
|
|
76
|
-
if self.dbopt:
|
|
77
|
-
self.default_scinfo(self.DBINFO['dbname'], self.DBINFO['scname'], self.DBINFO['dbhost'],
|
|
78
|
-
self.DBINFO['lnname'], None, self.DBINFO['dbport'])
|
|
79
|
-
self.password = self.get_baopassword()
|
|
80
|
-
if not self.password: self.password = self.get_pg_pass()
|
|
81
|
-
|
|
82
|
-
# main function to excecute this script
|
|
83
|
-
def main():
|
|
84
|
-
object = PgPassword()
|
|
85
|
-
object.read_parameters()
|
|
86
|
-
object.start_actions()
|
|
87
|
-
print(object.password)
|
|
88
|
-
sys.exit(0)
|
|
89
|
-
|
|
90
|
-
# call main() to start program
|
|
91
|
-
if __name__ == "__main__": main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|