Skip to content

Commit

Permalink
Merge pull request #499 from gcoxmoz/application-cleanup
Browse files Browse the repository at this point in the history
Application cleanup
  • Loading branch information
dividehex authored Aug 15, 2024
2 parents 039afe0 + 92bf92a commit f969405
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions dashboard/op/yaml_loader.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""File based loader. Will fetch connected apps from yml file instead."""

import logging
import os
import yaml


logger = logging.getLogger(__name__)


class Application(object):
class Application:
def __init__(self, app_dict):
self.app_dict = app_dict
self.apps = self._load_data()
Expand All @@ -24,7 +23,6 @@ def _load_data(self):
except yaml.YAMLError as e:
stream = None
logger.info(e)
pass
return stream

def _render_data(self):
Expand All @@ -35,28 +33,27 @@ def _render_data(self):
def _alphabetize(self):
self.apps["apps"].sort(key=lambda a: a["application"]["name"].lower())

def _find(self, name, path):
for root, dirs, files in os.walk(path):
if name in files:
return os.path.join(root, name)

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

return app_name

def vanity_urls(self):
'''
Parse apps.yml, return list of dicts, each dict is
{'/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 f969405

Please sign in to comment.