Skip to content
Snippets Groups Projects
Verified Commit 9e83dc31 authored by Maarten de Waard's avatar Maarten de Waard :angel:
Browse files

correctly return URLs for apps

parent fd28d5b7
No related branches found
No related tags found
1 merge request!55Resolve "Merge dashboard and dashboard-backend repos"
......@@ -15,4 +15,4 @@ class AppsService:
@staticmethod
def get_app_roles():
app_roles = AppRole.query.all()
return [{"user_id": app_role.user_id, "app_id": app_role.app_id, "role_id": app_role.role_id} for app_role in app_roles]
\ No newline at end of file
return [{"user_id": app_role.user_id, "app_id": app_role.app_id, "role_id": app_role.role_id} for app_role in app_roles]
"""Everything to do with Apps"""
import os
import base64
from sqlalchemy import ForeignKey, Integer, String, Boolean
from sqlalchemy.orm import relationship
......@@ -11,6 +12,11 @@ import helpers.kubernetes as k8s
#from .apps import APP_NOT_INSTALLED_STATUS
APP_NOT_INSTALLED_STATUS = "Not installed"
DEFAULT_APP_SUBDOMAINS = {
"nextcloud": "files",
"wordpress": "www",
"monitoring": "grafana",
}
class App(db.Model):
"""
......@@ -22,13 +28,26 @@ class App(db.Model):
name = db.Column(String(length=64))
slug = db.Column(String(length=64), unique=True)
external = db.Column(Boolean, unique=False, nullable=False, default=True, server_default='0')
# The URL is only stored in the DB for external applications; otherwise the
# URL is stored in a configmap (see get_url)
url = db.Column(String(length=128), unique=False)
def __repr__(self):
return f"{self.id} <{self.name}>"
def get_url(self):
"""Returns the URL where this application is running"""
"""
Returns the URL where this application is running
For external applications: the URL is stored in the database
For internal applications: the URL is stored in a configmap named
`stackspin-{self.slug}-kustomization-variables under
`{self.slug_domain}`. This function reads that configmap. If the
configmap does not contain a URL for the application (which is
possible, if the app is not installed yet, for example), we return a
default URL.
"""
if self.external:
return self.url
......@@ -38,10 +57,20 @@ 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():
return None
return 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}"
return f"https://{ks_config_map[domain_key]}"
def get_status(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment