changeset 7696:4af0d235b570

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.
author John Rouillard <rouilj@ieee.org>
date Tue, 07 Nov 2023 12:11:37 -0500
parents 2be7a8f66ea7
children c73a1177c2b2
files CHANGES.txt doc/reference.txt roundup/backends/back_postgresql.py roundup/backends/rdbms_common.py roundup/configuration.py
diffstat 5 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Sun Nov 05 23:01:29 2023 -0500
+++ b/CHANGES.txt	Tue Nov 07 12:11:37 2023 -0500
@@ -92,7 +92,11 @@
 - issue685275 - add pragma show_retired to control display of retired
   items when using list/table. Add pragma display_header to print
   headers for display command. Header displays designator and
-  retired/active status.
+  retired/active status. (John Rouillard)
+- support config.ini rdbms option 'service'. Allow use of a
+  PostgreSQL connection service file for configuring database on a
+  per-tracker basis. Also replaces use of PGSERVICE env variable for
+  single instance trackers. (From ML question by ivanov. John Rouillard)
 
 2023-07-13 2.3.0
 
--- a/doc/reference.txt	Sun Nov 05 23:01:29 2023 -0500
+++ b/doc/reference.txt	Tue Nov 07 12:11:37 2023 -0500
@@ -293,6 +293,19 @@
  password -- ``roundup``
   Database user password.
 
+ service -- default *blank*
+  Use to define the Connection Service for your PostgreSQL connection
+  when using a system-wide pg_service.conf or ~/.pg_service.conf as
+  discussed in
+  https://www.postgresql.org/docs/current/libpq-pgservice.html.
+
+  Setting this to the name of the service allows different trackers to
+  connect to different services when running multiple trackers under
+  one Roundup server. If you are only running one tracker, you can set
+  the PGSERVICE environment variable. Note that other settings
+  specified in this file (rdbms: user, password, port, host, (db)name)
+  will override the corresponding connection service setting.
+
  read_default_file -- ``~/.my.cnf``
   Name of the MySQL defaults file. Only used in MySQL connections.
 
--- a/roundup/backends/back_postgresql.py	Sun Nov 05 23:01:29 2023 -0500
+++ b/roundup/backends/back_postgresql.py	Tue Nov 07 12:11:37 2023 -0500
@@ -176,8 +176,13 @@
 
     def sql_open_connection(self):
         db = connection_dict(self.config, 'database')
-        logging.getLogger('roundup.hyperdb').info(
-            'open database %r' % db['database'])
+        # database option always present: log it if not null
+        if db['database']:
+            logging.getLogger('roundup.hyperdb').info(
+                'open database %r' % db['database'])
+        if 'service' in db:  # only log if used
+            logging.getLogger('roundup.hyperdb').info(
+                'open database via service %r' % db['service'])
         try:
             conn = psycopg2.connect(**db)
         except psycopg2.OperationalError as message:
--- a/roundup/backends/rdbms_common.py	Sun Nov 05 23:01:29 2023 -0500
+++ b/roundup/backends/rdbms_common.py	Tue Nov 07 12:11:37 2023 -0500
@@ -112,8 +112,8 @@
     d = {}
     if dbnamestr:
         d[dbnamestr] = config.RDBMS_NAME
-    for name in ('host', 'port', 'password', 'user', 'read_default_group',
-                 'read_default_file'):
+    for name in ('host', 'port', 'password', 'user', 'service',
+                 'read_default_group', 'read_default_file'):
         cvar = 'RDBMS_'+name.upper()
         if config[cvar] is not None:
             d[name] = config[cvar]
--- a/roundup/configuration.py	Sun Nov 05 23:01:29 2023 -0500
+++ b/roundup/configuration.py	Tue Nov 07 12:11:37 2023 -0500
@@ -1451,6 +1451,10 @@
         (SecretNullableOption, 'password', 'roundup',
             "Database user password.",
             ['MYSQL_DBPASSWORD']),
+        (NullableOption, 'service', '',
+            "Name of the PostgreSQL connection service for this Roundup\n"
+            "instance. Only used in Postgresql connections. You need to set\n"
+            "up a pg_service.conf file usable by psql use this option."),
         (NullableOption, 'read_default_file', '~/.my.cnf',
             "Name of the MySQL defaults file.\n"
             "Only used in MySQL connections."),

Roundup Issue Tracker: http://roundup-tracker.org/