[IMP] sql_db: allow to customize pg connection's application_name

This is an improvement over commit f6c13d7 in order to allow full
customization of postgresql connection's `application_name`.

In a PID linux namespace the containers processes IDs might not be relevant
for a system administrator and one might want to customize the content of the
`application_name` just like it was possible to do before commit f6c13d7
using the `PGAPPNAME` environment variable.

This commit allows to expose an `ODOO_PGAPPNAME` environment variable whose
content will be interpolated with the PID (optional)

closes odoo/odoo#117921

X-original-commit: a4108eee91f8e9bf82be5a4be4b91bab16baa0df
Signed-off-by: Olivier Dony (odo) <odo@odoo.com>
This commit is contained in:
Fabien Meghazi
2023-04-11 09:21:08 +02:00
parent 7db7b3ef04
commit 5cbb0738be
+5 -1
View File
@@ -725,7 +725,11 @@ def connection_info_for(db_or_uri):
:param str db_or_uri: database name or postgres dsn
:rtype: (str, dict)
"""
app_name = "odoo-%d" % os.getpid()
if 'ODOO_PGAPPNAME' in os.environ:
# Using manual string interpolation for security reason and trimming at default NAMEDATALEN=63
app_name = os.environ['ODOO_PGAPPNAME'].replace('{pid}', str(os.getpid()))[0:63]
else:
app_name = "odoo-%d" % os.getpid()
if db_or_uri.startswith(('postgresql://', 'postgres://')):
# extract db from uri
us = urls.url_parse(db_or_uri)