Skip to content

Commit

Permalink
Add support for "peer" authentication with PostgreSQL (#4255)
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
giovannipizzi authored Aug 19, 2020
1 parent 45d4cfa commit fe8333e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion aiida/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit fe8333e

Please sign in to comment.