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

Allow SSL params for Auth #430

Merged
merged 7 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
40 changes: 30 additions & 10 deletions plugin/teksi_wastewater/interlis/utils/various.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import re
import subprocess
import tempfile
import uuid
from typing import List

from qgis.core import QgsExpression

from ...utils.database_utils import DatabaseUtils
from ...utils.plugin_utils import logger

Expand Down Expand Up @@ -36,16 +39,33 @@ def get_pgconf_as_ili_args() -> List[str]:
"""Returns the pgconf as a list of ili2db arguments"""
pgconf = DatabaseUtils.get_pgconf()
args = []
if pgconf["host"]:
args.extend(["--dbhost", '"' + pgconf["host"] + '"'])
if pgconf["port"]:
args.extend(["--dbport", '"' + pgconf["port"] + '"'])
if pgconf["user"]:
args.extend(["--dbusr", '"' + pgconf["user"] + '"'])
if pgconf["password"]:
args.extend(["--dbpwd", '"' + pgconf["password"] + '"'])
if pgconf["dbname"]:
args.extend(["--dbdatabase", '"' + pgconf["dbname"] + '"'])
dbparams = []
for key in pgconf:
if key == "host":
args.extend(["--dbhost", '"' + pgconf["host"] + '"'])
elif key == "port":
args.extend(["--dbport", '"' + pgconf["port"] + '"'])
elif key == "user":
args.extend(["--dbusr", '"' + pgconf["user"] + '"'])
elif key == "password":
args.extend(["--dbpwd", '"' + pgconf["password"] + '"'])
elif key == "dbname":
args.extend(["--dbdatabase", '"' + pgconf["dbname"] + '"'])
else:
dbparams.extend([f"{key}={pgconf[key]}"])
if dbparams:
# write into tempfile and add path to args
dbparams_path = os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))
cymed marked this conversation as resolved.
Show resolved Hide resolved
os.makedirs(dbparams_path, exist_ok=True)
with open(os.path.join(dbparams_path, "dbparams.txt"), "w") as f:
for param in dbparams:
f.write(param + "\n")
args.extend(["--dbparams", '"' + os.path.join(dbparams_path, "dbparams.txt") + '"'])
if not pgconf["user"]:
# allow loading PGUSER from overriden env variables
expression = QgsExpression("@PGUSER")
pguser = expression.evaluate()
args.extend(["--dbusr", f'"{pguser}"'])
return args


Expand Down
12 changes: 2 additions & 10 deletions plugin/teksi_wastewater/utils/database_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,8 @@ def get_pgconf_as_psycopg_dsn() -> List[str]:

pgconf = DatabaseUtils.get_pgconf()
parts = []
if pgconf["host"]:
parts.append(f"host={pgconf['host']}")
if pgconf["port"]:
parts.append(f"port={pgconf['port']}")
if pgconf["user"]:
parts.append(f"dbname={pgconf['dbname']}")
if pgconf["password"]:
parts.append(f"user={pgconf['user']}")
if pgconf["dbname"]:
parts.append(f"password={pgconf['password']}")
for key in pgconf:
parts.append(f"{key}={pgconf[key]}")
return " ".join(parts)

@staticmethod
Expand Down