From 701a442d126ebd816d2a9728dba5d3a306ba0efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominic=20Z=C3=B6ller?= Date: Wed, 10 Nov 2021 11:29:01 +0100 Subject: [PATCH] default config: add exemplary URL encoding step for SQLA DB URL params SQLAlchemy database URLs follow RFC-1738, so parameters like username and password need to be encoded accordingly. https://docs.sqlalchemy.org/en/13/core/engines.html#database-urls --- configs/development.py | 10 ++++++++-- configs/test.py | 2 +- powerdnsadmin/default_config.py | 10 ++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/configs/development.py b/configs/development.py index 06e32bc..2c2e63d 100644 --- a/configs/development.py +++ b/configs/development.py @@ -1,5 +1,6 @@ import os -basedir = os.path.abspath(os.path.abspath(os.path.dirname(__file__))) +#import urllib.parse +basedir = os.path.abspath(os.path.dirname(__file__)) ### BASIC APP CONFIG SALT = '$2b$12$yLUMTIfl21FKJQpTkRQXCu' @@ -16,7 +17,12 @@ SQLA_DB_NAME = 'pda' SQLALCHEMY_TRACK_MODIFICATIONS = True ### DATABASE - MySQL -# SQLALCHEMY_DATABASE_URI = 'mysql://' + SQLA_DB_USER + ':' + SQLA_DB_PASSWORD + '@' + SQLA_DB_HOST + '/' + SQLA_DB_NAME +#SQLALCHEMY_DATABASE_URI = 'mysql://{}:{}@{}/{}'.format( +# urllib.parse.quote_plus(SQLA_DB_USER), +# urllib.parse.quote_plus(SQLA_DB_PASSWORD), +# SQLA_DB_HOST, +# SQLA_DB_NAME +#) ### DATABASE - SQLite SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'pdns.db') diff --git a/configs/test.py b/configs/test.py index 7b7345d..6bbdd80 100644 --- a/configs/test.py +++ b/configs/test.py @@ -1,5 +1,5 @@ import os -basedir = os.path.abspath(os.path.abspath(os.path.dirname(__file__))) +basedir = os.path.abspath(os.path.dirname(__file__)) ### BASIC APP CONFIG SALT = '$2b$12$yLUMTIfl21FKJQpTkRQXCu' diff --git a/powerdnsadmin/default_config.py b/powerdnsadmin/default_config.py index 42b26b4..16b8161 100644 --- a/powerdnsadmin/default_config.py +++ b/powerdnsadmin/default_config.py @@ -1,5 +1,6 @@ import os -basedir = os.path.abspath(os.path.abspath(os.path.dirname(__file__))) +import urllib.parse +basedir = os.path.abspath(os.path.dirname(__file__)) ### BASIC APP CONFIG SALT = '$2b$12$yLUMTIfl21FKJQpTkRQXCu' @@ -18,7 +19,12 @@ SQLA_DB_NAME = 'pda' SQLALCHEMY_TRACK_MODIFICATIONS = True ### DATABASE - MySQL -SQLALCHEMY_DATABASE_URI = 'mysql://'+SQLA_DB_USER+':'+SQLA_DB_PASSWORD+'@'+SQLA_DB_HOST+'/'+SQLA_DB_NAME +SQLALCHEMY_DATABASE_URI = 'mysql://{}:{}@{}/{}'.format( + urllib.parse.quote_plus(SQLA_DB_USER), + urllib.parse.quote_plus(SQLA_DB_PASSWORD), + SQLA_DB_HOST, + SQLA_DB_NAME +) ### DATABASE - SQLite # SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'pdns.db')