From 92bf92a70818d91a0d753993ee204956d0c65070 Mon Sep 17 00:00:00 2001 From: Greg Cox Date: Fri, 2 Aug 2024 14:04:00 +0000 Subject: [PATCH] simplify vanity_url parsing, IAM-1399 The prior form did an incomplete precheck and assumed goodness based on that. This rewrite collapses the function into a single, safer check. --- dashboard/op/yaml_loader.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dashboard/op/yaml_loader.py b/dashboard/op/yaml_loader.py index 8509ea22..7d7f7762 100644 --- a/dashboard/op/yaml_loader.py +++ b/dashboard/op/yaml_loader.py @@ -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 @@ -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