Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[auth] Make it possible to use AuthConfig without superlogin #110

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions modelbaker/db_factory/pg_command_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,24 @@ def get_uri(self, su: bool = False, qgis: bool = False) -> str:
uri += ["dbname='{}'".format(self.configuration.database)]

# only provide authcfg to the uri when it's needed for QGIS specific things
if (
qgis
and self.configuration.dbauthid
and (
not service_config
or not (
service_config.get("user", None)
and service_config.get("password", None)
)
if self.configuration.dbauthid and (
not service_config
or not (
service_config.get("user", None)
and service_config.get("password", None)
)
):
uri += ["authcfg={}".format(self.configuration.dbauthid)]
if qgis:
# only provide authcfg to the uri when it's needed for QGIS specific things
uri += ["authcfg={}".format(self.configuration.dbauthid)]
else:
signedav marked this conversation as resolved.
Show resolved Hide resolved
# Operations like Export do not require superuser
# login and may be run with authconfig
from ..utils.db_utils import get_authconfig_map

authconfig_map = get_authconfig_map(self.configuration.dbauthid)
uri += ["user={}".format(authconfig_map.get("username"))]
uri += ["password={}".format(authconfig_map.get("password"))]
else:
if not service_config or not service_config.get("user", None):
uri += ["user={}".format(self.configuration.dbusr)]
Expand Down
19 changes: 17 additions & 2 deletions modelbaker/iliwrapper/ili2dbargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ def _get_db_args(configuration, hide_password=False):
db_args += ["--dbport", configuration.dbport]
if su:
db_args += ["--dbusr", configuration.base_configuration.super_pg_user]
elif configuration.dbauthid:
# Operations like Export can work with authconf
# and with no superuser login
from ..utils.db_utils import get_authconfig_map

authconfig_map = get_authconfig_map(configuration.dbauthid)
db_args += ["--dbusr", authconfig_map.get("username")]
else:
db_args += ["--dbusr", configuration.dbusr]
if (
not su
and configuration.dbpwd
and (configuration.dbpwd or configuration.dbauthid)
or su
and configuration.base_configuration.super_pg_password
):
Expand All @@ -68,8 +75,16 @@ def _get_db_args(configuration, hide_password=False):
"--dbpwd",
configuration.base_configuration.super_pg_password,
]
else:
elif configuration.dbpwd:
db_args += ["--dbpwd", configuration.dbpwd]
elif configuration.dbauthid:
# Operations like Export can work with authconf
# and with no superuser login
from ..utils.db_utils import get_authconfig_map
signedav marked this conversation as resolved.
Show resolved Hide resolved

authconfig_map = get_authconfig_map(configuration.dbauthid)
db_args += ["--dbpwd", authconfig_map.get("password")]

db_args += ["--dbdatabase", configuration.database]
db_args += ["--dbschema", configuration.dbschema or configuration.database]

Expand Down
Loading