diff --git a/images/ckan/2.9/patches/00_patch_sql_url.patch b/images/ckan/2.9/patches/00_patch_sql_url.patch new file mode 100644 index 0000000..46a7135 --- /dev/null +++ b/images/ckan/2.9/patches/00_patch_sql_url.patch @@ -0,0 +1,11 @@ +--- ckan/ckan/model/__init__.py 2021-02-16 14:47:06.168327441 +0100 ++++ ckan/ckan/model/__init__.py 2021-02-16 14:48:00.740780218 +0100 +@@ -266,7 +266,7 @@ + self.reset_alembic_output() + alembic_config = AlembicConfig(self._alembic_ini) + alembic_config.set_main_option( +- "sqlalchemy.url", str(self.metadata.bind.url) ++ "sqlalchemy.url", str(self.metadata.bind.url).replace('%', '%%') + ) + try: + sqlalchemy_migrate_version = self.metadata.bind.execute( diff --git a/images/ckan/2.9/patches/02_patch_postgres_username_split.patch b/images/ckan/2.9/patches/02_patch_postgres_username_split.patch new file mode 100644 index 0000000..780b432 --- /dev/null +++ b/images/ckan/2.9/patches/02_patch_postgres_username_split.patch @@ -0,0 +1,11 @@ +--- ckan/ckanext/datastore/backend/postgres.py 2021-02-18 11:01:56.692267462 +0100 ++++ ckan/ckanext/datastore/backend/postgres-patch.py 2021-02-18 13:45:16.033193435 +0100 +@@ -1690,7 +1690,7 @@ + read only user. + ''' + write_connection = self._get_write_engine().connect() +- read_connection_user = sa_url.make_url(self.read_url).username ++ read_connection_user = sa_url.make_url(self.read_url).username.split("@")[0] + + drop_foo_sql = u'DROP TABLE IF EXISTS _foo' + diff --git a/images/ckan/2.9/setup/app/prerun.py b/images/ckan/2.9/setup/app/prerun.py index 60b22d6..ca4598f 100644 --- a/images/ckan/2.9/setup/app/prerun.py +++ b/images/ckan/2.9/setup/app/prerun.py @@ -2,6 +2,7 @@ import os import sys import subprocess import psycopg2 +from sqlalchemy.engine.url import make_url import urllib.request, urllib.error, urllib.parse import re @@ -23,7 +24,14 @@ def check_db_connection(retry=None): conn_str = os.environ.get('CKAN_SQLALCHEMY_URL', '') try: - connection = psycopg2.connect(conn_str) + db_user = make_url(conn_str).username + db_passwd = make_url(conn_str).password + db_host = make_url(conn_str).host + db_name = make_url(conn_str).database + connection = psycopg2.connect(user=db_user, + host=db_host, + password=db_passwd, + database=db_name) except psycopg2.Error as e: print((str(e))) @@ -96,7 +104,14 @@ def init_datastore(): datastore_perms_command = ['ckan', '-c', ckan_ini, 'datastore', 'set-permissions'] - connection = psycopg2.connect(conn_str) + db_user = make_url(conn_str).username + db_passwd = make_url(conn_str).password + db_host = make_url(conn_str).host + db_name = make_url(conn_str).database + connection = psycopg2.connect(user=db_user, + host=db_host, + password=db_passwd, + database=db_name) cursor = connection.cursor() print('[prerun] Initializing datastore db - start') @@ -106,8 +121,10 @@ def init_datastore(): stdout=subprocess.PIPE) perms_sql = datastore_perms.stdout.read() + perms_sql = perms_sql.decode('utf-8') + perms_sql = perms_sql.replace("@"+db_host, "") # Remove internal pg command as psycopg2 does not like it - perms_sql = re.sub('\\\\connect \"(.*)\"', '', perms_sql.decode('utf-8')) + perms_sql = re.sub('\\\\connect \"(.*)\"', '', perms_sql) cursor.execute(perms_sql) for notice in connection.notices: print(notice)