From cb53015995eef6cb788b33ae13b2aed3b80c862f Mon Sep 17 00:00:00 2001 From: Giovanni Pizzi Date: Sat, 11 Jul 2020 16:11:11 +0200 Subject: [PATCH] Add support for "peer" authentication with PostgreSQL PostgreSQL allows "peer" authentication to connect to the database. This is signaled by a `hostname` that is set to `None` through `pgsu`. In this case, the `hostname` part of the connection string of the SQLAlchemy engine should be left empty. If it is `None` it is converted to an empty string otherwise it would be converted to the string literal "None". --- aiida/backends/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aiida/backends/utils.py b/aiida/backends/utils.py index ebbe03912c..ebea81ab48 100644 --- a/aiida/backends/utils.py +++ b/aiida/backends/utils.py @@ -24,12 +24,16 @@ def create_sqlalchemy_engine(profile, **kwargs): from sqlalchemy import create_engine from aiida.common import json + # The hostname may be `None`, which is a valid value in the case of peer authentication for example. In this case + # it should be converted to an empty string, because otherwise the `None` will be converted to string literal "None" + hostname = profile.database_hostname or '' separator = ':' if profile.database_port else '' + engine_url = 'postgresql://{user}:{password}@{hostname}{separator}{port}/{name}'.format( separator=separator, user=profile.database_username, password=profile.database_password, - hostname=profile.database_hostname, + hostname=hostname, port=profile.database_port, name=profile.database_name )