#123 config: make sure URLs end with a slash
Merged 3 years ago by frantisekz. Opened 3 years ago by kparal.

file modified
+14 -1
@@ -53,7 +53,20 @@ 

  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)

@@ -28,7 +28,7 @@ 

  

      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)

file modified
+2 -2
@@ -5,10 +5,10 @@ 

  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

This prevents missing slashes or double slashes, depending on what the user
provides in a config file and how the code is written.


I was bothered by double slashed in our tickets, e.g. here:
https://pagure.io/fedora-qa/blocker-review/issue/24

rebased onto f3c8bbd

3 years ago

I am not sure end_with_slash() is necessary (I don't see this in any of our other projects, api endpoints should always end with slash, afaik).

But in the end, it doesn't hurt to have it as convenience :)

Rebased for you, merging.

Thanks!

Pull-Request has been merged by frantisekz

3 years ago