diff --git a/requirements-test.txt b/requirements-test.txt index 4ee14e0b..baded558 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,16 +1,17 @@ decorator # dependency of swh.core[http] djangorestframework-stubs django-stubs django-test-migrations hypothesis pytest pytest-django pytest-mock requests-mock != 1.9.0, != 1.9.1 swh.core[http] >= 0.0.95 swh.loader.git >= 0.8.0 swh-scheduler[testing] >= 0.5.0 swh.storage >= 0.1.1 types-docutils +types-psycopg2 types-pyyaml types-requests diff --git a/swh/web/settings/production.py b/swh/web/settings/production.py index a15ead4f..e490a057 100644 --- a/swh/web/settings/production.py +++ b/swh/web/settings/production.py @@ -1,48 +1,61 @@ # Copyright (C) 2017-2021 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information """ Django production settings for swh-web. """ from .common import * # noqa from .common import CACHES, MIDDLEWARE, REST_FRAMEWORK, WEBPACK_LOADER, swh_web_config MIDDLEWARE += [ "swh.web.common.middlewares.HtmlMinifyMiddleware", ] if swh_web_config.get("throttling", {}).get("cache_uri"): CACHES.update( { "default": { "BACKEND": "django.core.cache.backends.memcached.MemcachedCache", "LOCATION": swh_web_config["throttling"]["cache_uri"], } } ) # Setup support for proxy headers USE_X_FORWARDED_HOST = True SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") # We're going through seven (or, in that case, 2) proxies thanks to Varnish REST_FRAMEWORK["NUM_PROXIES"] = 2 db_conf = swh_web_config["production_db"] +if db_conf.get("name", "").startswith("postgresql://"): + # poor man's support for dsn connection string... + import psycopg2 + + with psycopg2.connect(db_conf.get("name")) as cnx: + dsn_dict = cnx.get_dsn_parameters() + + db_conf["name"] = dsn_dict.get("dbname") + db_conf["host"] = dsn_dict.get("host") + db_conf["port"] = dsn_dict.get("port") + db_conf["user"] = dsn_dict.get("user") + db_conf["password"] = dsn_dict.get("password") + # https://docs.djangoproject.com/en/1.10/ref/settings/#databases DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", "NAME": db_conf.get("name"), "HOST": db_conf.get("host"), "PORT": db_conf.get("port"), "USER": db_conf.get("user"), "PASSWORD": db_conf.get("password"), } } WEBPACK_LOADER["DEFAULT"]["CACHE"] = True