diff --git a/areas/apps/apps.py b/areas/apps/apps.py index 142f5e3..de85bbc 100644 --- a/areas/apps/apps.py +++ b/areas/apps/apps.py @@ -1,4 +1,4 @@ -from flask import jsonify, current_app +from flask import jsonify from flask_jwt_extended import jwt_required from flask_cors import cross_origin @@ -34,16 +34,12 @@ APP_DATA = {"id": 1, "name": "Nextcloud", "selected": True, "status": "ON for ev @cross_origin() def get_apps(): apps = AppsService.get_all_apps() - for obj in apps: - current_app.logger.info(obj['slug']) - current_app.logger.info(str(obj)) return jsonify(apps) @api_v1.route('/apps/', methods=['GET']) @jwt_required() def get_app(slug): - app = AppsService.get_app(slug) return jsonify(app) diff --git a/areas/apps/apps_service.py b/areas/apps/apps_service.py index 635ac60..1e4f232 100644 --- a/areas/apps/apps_service.py +++ b/areas/apps/apps_service.py @@ -11,7 +11,6 @@ class AppsService: app = App.query.filter_by(slug=slug).first() return app.to_json() - @staticmethod def get_app_roles(): app_roles = AppRole.query.all() diff --git a/areas/apps/models.py b/areas/apps/models.py index 9f78310..511c443 100644 --- a/areas/apps/models.py +++ b/areas/apps/models.py @@ -55,20 +55,24 @@ class App(db.Model): f"stackspin-{self.slug}-kustomization-variables", "flux-system") domain_key = f"{self.slug}_domain" - # No config map found, or configmap not configured to contain the - # domain (yet). Return the default for this app - if ks_config_map is None or domain_key not in ks_config_map.keys(): - domain_secret = k8s.get_kubernetes_secret_data( - "stackspin-cluster-variables", - "flux-system") - domain = base64.b64decode(domain_secret['domain']).decode() - # See if there is another default subdomain for this app than just - # "slug.{domain}" - if self.slug in DEFAULT_APP_SUBDOMAINS: - return f"https://{DEFAULT_APP_SUBDOMAINS[self.slug]}.{domain}" - # No default known - return f"https://{self.slug}.{domain}" - return f"https://{ks_config_map[domain_key]}" + + # If config map found with this domain name for this service, return + # that URL + if ks_config_map and domain_key in ks_config_map.keys(): + return f"https://{ks_config_map[domain_key]}" + + domain_secret = k8s.get_kubernetes_secret_data( + "stackspin-cluster-variables", + "flux-system") + domain = base64.b64decode(domain_secret['domain']).decode() + + # See if there is another default subdomain for this app than just + # "slug.{domain}" + if self.slug in DEFAULT_APP_SUBDOMAINS: + return f"https://{DEFAULT_APP_SUBDOMAINS[self.slug]}.{domain}" + + # No default known + return f"https://{self.slug}.{domain}" def get_status(self): """Returns an AppStatus object that describes the current cluster state""" @@ -197,8 +201,7 @@ class App(db.Model): "name": self.name, "slug": self.slug, "external": self.external, - "url": self.get_url(), - "status": self.get_status()} + "url": self.get_url()} @property