Code cleanups

This commit is contained in:
Mart van Santen 2022-10-03 12:47:25 +08:00
parent dd5d4f1acd
commit 8eb8d83bea
3 changed files with 20 additions and 22 deletions

View file

@ -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/<string:slug>', methods=['GET'])
@jwt_required()
def get_app(slug):
app = AppsService.get_app(slug)
return jsonify(app)

View file

@ -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()

View file

@ -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