Skip to content

Commit 5807f78

Browse files
author
zaihuaji
committed
dbport as a string to search for pwname
1 parent e1f8cb8 commit 5807f78

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/rda_python_common/PgDBI.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# hard coded db ports for dbnames
3939
DBPORTS = {
40-
'default' : 5432
40+
'default' : 0
4141
}
4242

4343
DBPASS = {}
@@ -517,9 +517,9 @@ def pgconnect(reconnect = 0, pgcnt = 0, autocommit = True):
517517
config['host'] = PGDBI['DBHOST'] if PGDBI['DBHOST'] else PGDBI['DEFHOST']
518518
if not PGDBI['DBPORT']: PGDBI['DBPORT'] = get_dbport(PGDBI['DBNAME'])
519519
if PGDBI['DBPORT']: config['port'] = PGDBI['DBPORT']
520-
config['password'] = get_pgpass_password()
521-
520+
config['password'] = '***'
522521
sqlstr = "psycopg2.connect(**{})".format(config)
522+
config['password'] = get_pgpass_password()
523523
if PgLOG.PGLOG['DBGLEVEL']: PgLOG.pgdbg(1000, sqlstr)
524524
try:
525525
PgLOG.PGLOG['PGDBBUF'] = pgdb = PgSQL.connect(**config)
@@ -2221,8 +2221,10 @@ def pgname(str, sign = None):
22212221
def get_pgpass_password():
22222222

22232223
if PGDBI['PWNAME']: return PGDBI['PWNAME']
2224-
if not DBPASS: read_pgpass()
2225-
return DBPASS.get((PGDBI['DBSHOST'], PGDBI['DBPORT'], PGDBI['DBNAME'], PGDBI['LNNAME']))
2224+
if not DBPASS: read_pgpass()
2225+
dbport = str(PGDBI['DBPORT']) if PGDBI['DBPORT'] else '5432'
2226+
pwname = DBPASS.get((PGDBI['DBSHOST'], dbport, PGDBI['DBNAME'], PGDBI['LNNAME']))
2227+
if not pwname: pwname = DBPASS.get((PGDBI['DBHOST'], dbport, PGDBI['DBNAME'], PGDBI['LNNAME']))
22262228

22272229
#
22282230
# Reads the .pgpass file and returns a dictionary of credentials.
@@ -2234,7 +2236,7 @@ def read_pgpass():
22342236
for line in f:
22352237
line = line.strip()
22362238
if not line or line.startswith("#"): continue
2237-
dbhost, dbport, dbname, usname, pwname = line.split(":")
2238-
DBPASS[(dbhost, dbport, dbname, usname)] = pwname
2239+
dbhost, dbport, dbname, lnname, pwname = line.split(":")
2240+
DBPASS[(dbhost, dbport, dbname, lnname)] = pwname
22392241
except FileNotFoundError:
22402242
pass

0 commit comments

Comments
 (0)