diff --git a/ohayodash/base.py b/ohayodash/base.py index 67f31e9..adb0e1c 100644 --- a/ohayodash/base.py +++ b/ohayodash/base.py @@ -104,6 +104,31 @@ def get_bookmarks(tag: str = None) -> list: return bookmarks +def get_providers(tag: str = None) -> list: + """Get all 'provider' ConfigMaps from the cluster and produce a provider list.""" + v1 = kubernetes.client.CoreV1Api() + ret = v1.list_config_map_for_all_namespaces(watch=False) + + providers = [] + for cm in ret.items: + # Skip if the CM has no annotations + if cm.metadata.annotations is None: + continue + + # Skip if its not tagged as bookmark CM + if '{0}/providers'.format(ANNOTATION_BASE) not in cm.metadata.annotations: + continue + + # Skip if we're limited to a tag, and the CM has tags but not that one. + if not check_tags(tag, cm): + continue + + provider_data = yaml.safe_load(cm.data['providers']) + providers.extend(provider_data) + + return providers + + @base.route('/') @base.route('//') def index(tag=None): @@ -113,9 +138,11 @@ def index(tag=None): @base.route('/providers.json') @base.route('//providers.json') def providers(tag=None): - data_file = pkg_resources.resource_filename(__name__, 'data/providers.yaml') - with open(data_file, 'r') as fobj: - providers = yaml.safe_load(fobj) + providers = get_providers(tag) + if not providers: + data_file = pkg_resources.resource_filename(__name__, 'data/providers.yaml') + with open(data_file, 'r') as fobj: + providers.extend(yaml.safe_load(fobj)) return jsonify({'providers': providers}) diff --git a/ohayodash/data/providers.yaml b/ohayodash/data/providers.yaml index e8fd6f4..fdb1fd5 100644 --- a/ohayodash/data/providers.yaml +++ b/ohayodash/data/providers.yaml @@ -11,6 +11,10 @@ url: https://duckduckgo.com/ search: "?q=" prefix: /d +- name: Google + url: https://google.com/ + search: search/?q= + prefix: /g - name: iMDB url: https://imbdb.com/ search: find?q=