Skip to content

Commit 29be6e1

Browse files
committed
feat(db): support using postgresql service connection file
Add new service rdbms config option to set the service name to be used with a postgresql service connection file. This can be done using the PGSERVICE environment variable for a single instance tracker server. For a multi-instance server this per-tracker config option is needed. Note that settings (host, user, (db)name...) in config.ini file will override the service connection file setting. Also setting PGSERVICE and service will use the service setting.
1 parent e146fbf commit 29be6e1

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

CHANGES.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ Features:
9292
- issue685275 - add pragma show_retired to control display of retired
9393
items when using list/table. Add pragma display_header to print
9494
headers for display command. Header displays designator and
95-
retired/active status.
95+
retired/active status. (John Rouillard)
96+
- support config.ini rdbms option 'service'. Allow use of a
97+
PostgreSQL connection service file for configuring database on a
98+
per-tracker basis. Also replaces use of PGSERVICE env variable for
99+
single instance trackers. (From ML question by ivanov. John Rouillard)
96100

97101
2023-07-13 2.3.0
98102

doc/reference.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,19 @@ Section **rdbms**
293293
password -- ``roundup``
294294
Database user password.
295295

296+
service -- default *blank*
297+
Use to define the Connection Service for your PostgreSQL connection
298+
when using a system-wide pg_service.conf or ~/.pg_service.conf as
299+
discussed in
300+
https://www.postgresql.org/docs/current/libpq-pgservice.html.
301+
302+
Setting this to the name of the service allows different trackers to
303+
connect to different services when running multiple trackers under
304+
one Roundup server. If you are only running one tracker, you can set
305+
the PGSERVICE environment variable. Note that other settings
306+
specified in this file (rdbms: user, password, port, host, (db)name)
307+
will override the corresponding connection service setting.
308+
296309
read_default_file -- ``~/.my.cnf``
297310
Name of the MySQL defaults file. Only used in MySQL connections.
298311

roundup/backends/back_postgresql.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,13 @@ class Database(rdbms_common.Database):
176176

177177
def sql_open_connection(self):
178178
db = connection_dict(self.config, 'database')
179-
logging.getLogger('roundup.hyperdb').info(
180-
'open database %r' % db['database'])
179+
# database option always present: log it if not null
180+
if db['database']:
181+
logging.getLogger('roundup.hyperdb').info(
182+
'open database %r' % db['database'])
183+
if 'service' in db: # only log if used
184+
logging.getLogger('roundup.hyperdb').info(
185+
'open database via service %r' % db['service'])
181186
try:
182187
conn = psycopg2.connect(**db)
183188
except psycopg2.OperationalError as message:

roundup/backends/rdbms_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def connection_dict(config, dbnamestr=None):
112112
d = {}
113113
if dbnamestr:
114114
d[dbnamestr] = config.RDBMS_NAME
115-
for name in ('host', 'port', 'password', 'user', 'read_default_group',
116-
'read_default_file'):
115+
for name in ('host', 'port', 'password', 'user', 'service',
116+
'read_default_group', 'read_default_file'):
117117
cvar = 'RDBMS_'+name.upper()
118118
if config[cvar] is not None:
119119
d[name] = config[cvar]

roundup/configuration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,10 @@ def str2value(self, value):
14511451
(SecretNullableOption, 'password', 'roundup',
14521452
"Database user password.",
14531453
['MYSQL_DBPASSWORD']),
1454+
(NullableOption, 'service', '',
1455+
"Name of the PostgreSQL connection service for this Roundup\n"
1456+
"instance. Only used in Postgresql connections. You need to set\n"
1457+
"up a pg_service.conf file usable by psql use this option."),
14541458
(NullableOption, 'read_default_file', '~/.my.cnf',
14551459
"Name of the MySQL defaults file.\n"
14561460
"Only used in MySQL connections."),

0 commit comments

Comments
 (0)