Skip to content

Commit

Permalink
simplify vanity_url parsing, IAM-1399
Browse files Browse the repository at this point in the history
The prior form did an incomplete precheck and assumed goodness based on that.  This rewrite collapses the function into a single, safer check.
  • Loading branch information
gcoxmoz committed Aug 2, 2024
1 parent eac12e7 commit 92bf92a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions dashboard/op/yaml_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ def _render_data(self):
def _alphabetize(self):
self.apps["apps"].sort(key=lambda a: a["application"]["name"].lower())

def _has_vanity(self, app):
try:
app["application"]["vanity_url"]
return True
except Exception:
return False

def _truncate(self, app_name):
"""If name is longer than allowed 18 chars truncate the name."""
app_name = (app_name[:16] + "..") if len(app_name) > 18 else app_name
Expand All @@ -52,8 +45,15 @@ def vanity_urls(self):
{'/some-redirect': 'https://some/destination'}
'''
redirects = []
for app in self.apps["apps"]:
if self._has_vanity(app):
for redirect in app["application"]["vanity_url"]:
redirects.append({redirect: app["application"]["url"]})
try:
all_apps = self.apps['apps']
except (TypeError, KeyError):
return redirects
for app_entry in all_apps:
app = app_entry['application']
yaml_vanity_url_list = app.get('vanity_url')
if not isinstance(yaml_vanity_url_list, list):
continue
for redirect in yaml_vanity_url_list:
redirects.append({redirect: app['url']})
return redirects

0 comments on commit 92bf92a

Please sign in to comment.