From f3c8bbd92aad7342a85f7523d20693f13b8b2e1d Mon Sep 17 00:00:00 2001 From: Kamil Páral Date: Aug 21 2020 06:39:38 +0000 Subject: config: make sure URLs end with a slash This prevents missing slashes or double slashes, depending on what the user provides in a config file and how the code is written. --- diff --git a/blockerbugs/__init__.py b/blockerbugs/__init__.py index f8809f8..8c39b0e 100644 --- a/blockerbugs/__init__.py +++ b/blockerbugs/__init__.py @@ -53,7 +53,20 @@ if not app.testing: if os.getenv('DEBUG') == 'true': app.config["DEBUG"] = True -# "Hotfix" for proxy handling on current deployment, my guess is that the proxy server is set differently than it was, but what do I know... +# Make sure config URLs end with a slash, so that we have them all in an +# expected format +def end_with_slash(url): + if not url.endswith('/'): + return url + '/' + else: + return url + +for key in ['BUGZILLA_URL', 'KOJI_URL', 'BODHI_URL', 'FAS_BASE_URL', + 'PAGURE_URL', 'PAGURE_API']: + app.config[key] = end_with_slash(app.config[key]) + +# "Hotfix" for proxy handling on current deployment, my guess is that the proxy +# server is set differently than it was, but what do I know... if app.config["BEHIND_PROXY"]: from werkzeug.contrib.fixers import ProxyFix app.wsgi_app = ProxyFix(app.wsgi_app, num_proxies=1) diff --git a/blockerbugs/util/pagure_interface.py b/blockerbugs/util/pagure_interface.py index b0dddbc..42bbefe 100644 --- a/blockerbugs/util/pagure_interface.py +++ b/blockerbugs/util/pagure_interface.py @@ -28,7 +28,7 @@ def update_issue(issue_id, vote_summary): bug = Bug.query.filter_by(discussion_link=discussion_link).first() - bug_url = app.config['BUGZILLA_URL'] + "/show_bug.cgi?id=%s" % bug.bugid + bug_url = app.config['BUGZILLA_URL'] + "show_bug.cgi?id=%s" % bug.bugid title = Template(app.config['PAGURE_DISCUSSION_TITLE']).safe_substitute( bugid=bug.bugid, summary=bug.summary) diff --git a/conf/settings.py.example b/conf/settings.py.example index 1662546..ac0e815 100644 --- a/conf/settings.py.example +++ b/conf/settings.py.example @@ -5,10 +5,10 @@ SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://dbuser:dbpassword@dbhost:dbport FAS_ADMIN_GROUP = "magic-fas-group" FAS_USER = "magicuser@unicornsarereal.com" FAS_PASSWORD = "password" -BUGZILLA_URL = 'https://partner-bugzilla.redhat.com' +BUGZILLA_URL = 'https://partner-bugzilla.redhat.com/' BUGZILLA_XMLRPC = 'https://partner-bugzilla.redhat.com/xmlrpc.cgi' KOJI_URL = 'http://koji.stg.fedoraproject.org/' -BODHI_URL = 'https://admin.stg.fedoraproject.org/updates' +BODHI_URL = 'https://admin.stg.fedoraproject.org/updates/' FILE_LOGGING = False LOGFILE = '/var/log/blockerbugs/blockerbugs.log' SYSLOG_LOGGING = False