From 471a49a80f278ebaccd35468b941cf3ebc9ccbb3 Mon Sep 17 00:00:00 2001 From: tuxcoder Date: Tue, 26 Dec 2023 00:24:28 +0100 Subject: [PATCH] add list of services on main page --- lenticular_cloud/config_development.toml | 2 ++ lenticular_cloud/lenticular_services.py | 5 ++-- lenticular_cloud/model.py | 17 +++++++++++-- .../template/frontend/fido2.html.j2 | 0 .../template/frontend/index.html.j2 | 17 +++++++++++++ lenticular_cloud/views/frontend.py | 5 +++- module.nix | 24 ++++++++++++++++++- 7 files changed, 64 insertions(+), 6 deletions(-) delete mode 100644 lenticular_cloud/template/frontend/fido2.html.j2 diff --git a/lenticular_cloud/config_development.toml b/lenticular_cloud/config_development.toml index 306e0d9..4bc9b6e 100644 --- a/lenticular_cloud/config_development.toml +++ b/lenticular_cloud/config_development.toml @@ -32,6 +32,8 @@ ADMINS = [ [LENTICULAR_CLOUD_SERVICES.jabber] app_token = true # client_cert= true +icon = "https://seafile.milliways.info/media/favicons/favicon.png" +href = "https://seafile.milliways.info" [LENTICULAR_CLOUD_SERVICES.mail-cardav] diff --git a/lenticular_cloud/lenticular_services.py b/lenticular_cloud/lenticular_services.py index 784416c..51d8a22 100644 --- a/lenticular_cloud/lenticular_services.py +++ b/lenticular_cloud/lenticular_services.py @@ -1,11 +1,12 @@ from flask import Flask -from .model import Service import logging +from .model import Service + logger = logging.getLogger(__name__) -class LenticularServices(dict): +class LenticularServices(dict[str, Service]): def init_app(self, app: Flask) -> None: for service_name, service_config in app.config['LENTICULAR_CLOUD_SERVICES'].items(): diff --git a/lenticular_cloud/model.py b/lenticular_cloud/model.py index 27a1f82..135b937 100644 --- a/lenticular_cloud/model.py +++ b/lenticular_cloud/model.py @@ -58,6 +58,9 @@ class Service(object): def __init__(self, name: str): self._name = name self._app_token = False + self._icon: Optional[str] = None + self._href: Optional[str] = None + self._client_cert = False self._pki_config = { 'cn': '{username}', @@ -66,8 +69,6 @@ class Service(object): @staticmethod def from_config(name, config) -> 'Service': - """ - """ service = Service(name) if 'app_token' in config: service._app_token = bool(config['app_token']) @@ -75,6 +76,10 @@ class Service(object): service._client_cert = bool(config['client_cert']) if 'pki_config' in config: service._pki_config.update(config['pki_config']) + if 'icon' in config: + service._icon = str(config['icon']) + if 'href' in config: + service._href = str(config['href']) return service @@ -96,6 +101,14 @@ class Service(object): raise Exception('invalid call') return self._pki_config + @property + def icon(self) -> Optional[str]: + return self._icon + + @property + def href(self) -> Optional[str]: + return self._href + class Certificate(object): diff --git a/lenticular_cloud/template/frontend/fido2.html.j2 b/lenticular_cloud/template/frontend/fido2.html.j2 deleted file mode 100644 index e69de29..0000000 diff --git a/lenticular_cloud/template/frontend/index.html.j2 b/lenticular_cloud/template/frontend/index.html.j2 index ffe0a48..f2af783 100644 --- a/lenticular_cloud/template/frontend/index.html.j2 +++ b/lenticular_cloud/template/frontend/index.html.j2 @@ -1,2 +1,19 @@ {% extends 'frontend/base.html.j2' %} + + +{% block content %} +
+

Available Services

+ +
+ {% for service_name, service in lenticular_services.items() %} +
+ + {{ service_name }} + +
+ {% endfor %} +
+
+{% endblock %} diff --git a/lenticular_cloud/views/frontend.py b/lenticular_cloud/views/frontend.py index 3f1493a..676eb44 100644 --- a/lenticular_cloud/views/frontend.py +++ b/lenticular_cloud/views/frontend.py @@ -76,7 +76,10 @@ def index() -> ResponseReturnValue: next_url = session['next_url'] del session['next_url'] return redirect(next_url) - return render_template('frontend/index.html.j2') + return render_template( + 'frontend/index.html.j2', + lenticular_services=lenticular_services, + ) @frontend_views.route('/client_cert') diff --git a/module.nix b/module.nix index f486e7b..eb8d884 100644 --- a/module.nix +++ b/module.nix @@ -68,7 +68,29 @@ in HYDRA_PUBLIC_URL = mkOption { type = types.str; default = "https://${config.services.ory-hydra.public_domain}"; - }; + }; + LENTICULAR_CLOUD_SERVICES = mkOption { + type = types.attrsOf (types.submodule { + options = { + app_token = mkOption { + type = types.bool; + default = false; + description = "enables the app token function for this service"; + }; + href = mkOption { + type = types.str; + example = "https://service.example.com"; + description = "Link to the hosted service"; + }; + icon = mkOption { + type = types.str; + example = "https://service.example.com/favicon.png"; + description = "Link to an icon of the service"; + }; + }; + }); + default = {}; + }; }; }; };