Code cleanups
This commit is contained in:
parent
dd5d4f1acd
commit
8eb8d83bea
3 changed files with 20 additions and 22 deletions
|
@ -1,4 +1,4 @@
|
||||||
from flask import jsonify, current_app
|
from flask import jsonify
|
||||||
from flask_jwt_extended import jwt_required
|
from flask_jwt_extended import jwt_required
|
||||||
from flask_cors import cross_origin
|
from flask_cors import cross_origin
|
||||||
|
|
||||||
|
@ -34,16 +34,12 @@ APP_DATA = {"id": 1, "name": "Nextcloud", "selected": True, "status": "ON for ev
|
||||||
@cross_origin()
|
@cross_origin()
|
||||||
def get_apps():
|
def get_apps():
|
||||||
apps = AppsService.get_all_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)
|
return jsonify(apps)
|
||||||
|
|
||||||
|
|
||||||
@api_v1.route('/apps/<string:slug>', methods=['GET'])
|
@api_v1.route('/apps/<string:slug>', methods=['GET'])
|
||||||
@jwt_required()
|
@jwt_required()
|
||||||
def get_app(slug):
|
def get_app(slug):
|
||||||
|
|
||||||
app = AppsService.get_app(slug)
|
app = AppsService.get_app(slug)
|
||||||
return jsonify(app)
|
return jsonify(app)
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ class AppsService:
|
||||||
app = App.query.filter_by(slug=slug).first()
|
app = App.query.filter_by(slug=slug).first()
|
||||||
return app.to_json()
|
return app.to_json()
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_app_roles():
|
def get_app_roles():
|
||||||
app_roles = AppRole.query.all()
|
app_roles = AppRole.query.all()
|
||||||
|
|
|
@ -55,20 +55,24 @@ class App(db.Model):
|
||||||
f"stackspin-{self.slug}-kustomization-variables",
|
f"stackspin-{self.slug}-kustomization-variables",
|
||||||
"flux-system")
|
"flux-system")
|
||||||
domain_key = f"{self.slug}_domain"
|
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 config map found with this domain name for this service, return
|
||||||
if ks_config_map is None or domain_key not in ks_config_map.keys():
|
# 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(
|
domain_secret = k8s.get_kubernetes_secret_data(
|
||||||
"stackspin-cluster-variables",
|
"stackspin-cluster-variables",
|
||||||
"flux-system")
|
"flux-system")
|
||||||
domain = base64.b64decode(domain_secret['domain']).decode()
|
domain = base64.b64decode(domain_secret['domain']).decode()
|
||||||
|
|
||||||
# See if there is another default subdomain for this app than just
|
# See if there is another default subdomain for this app than just
|
||||||
# "slug.{domain}"
|
# "slug.{domain}"
|
||||||
if self.slug in DEFAULT_APP_SUBDOMAINS:
|
if self.slug in DEFAULT_APP_SUBDOMAINS:
|
||||||
return f"https://{DEFAULT_APP_SUBDOMAINS[self.slug]}.{domain}"
|
return f"https://{DEFAULT_APP_SUBDOMAINS[self.slug]}.{domain}"
|
||||||
|
|
||||||
# No default known
|
# No default known
|
||||||
return f"https://{self.slug}.{domain}"
|
return f"https://{self.slug}.{domain}"
|
||||||
return f"https://{ks_config_map[domain_key]}"
|
|
||||||
|
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
"""Returns an AppStatus object that describes the current cluster state"""
|
"""Returns an AppStatus object that describes the current cluster state"""
|
||||||
|
@ -197,8 +201,7 @@ class App(db.Model):
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
"slug": self.slug,
|
"slug": self.slug,
|
||||||
"external": self.external,
|
"external": self.external,
|
||||||
"url": self.get_url(),
|
"url": self.get_url()}
|
||||||
"status": self.get_status()}
|
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Reference in a new issue