draft of installing apps and getting app status
This commit is contained in:
parent
2baae3e61e
commit
cea3f5a3cb
13 changed files with 1148 additions and 7 deletions
|
|
@ -13,11 +13,11 @@ from flask.cli import AppGroup
|
|||
from ory_kratos_client.api import v0alpha2_api as kratos_api
|
||||
from sqlalchemy import func
|
||||
|
||||
from config import *
|
||||
from config import HYDRA_ADMIN_URL,KRATOS_ADMIN_URL,KRATOS_PUBLIC_URL
|
||||
from helpers import KratosUser
|
||||
from cliapp import cli
|
||||
from areas.roles import Role
|
||||
from areas.apps import AppRole, App
|
||||
from areas.apps import AppRole, App, APP_NOT_INSTALLED_STATUS
|
||||
from database import db
|
||||
|
||||
# APIs
|
||||
|
|
@ -66,7 +66,7 @@ def create_app(slug, name):
|
|||
if app_obj:
|
||||
current_app.logger.info(f"App definition: {name} ({slug}) already exists in database")
|
||||
return
|
||||
|
||||
|
||||
db.session.add(obj)
|
||||
db.session.commit()
|
||||
current_app.logger.info(f"App definition: {name} ({slug}) created")
|
||||
|
|
@ -106,6 +106,46 @@ def delete_app(slug):
|
|||
current_app.logger.info("Success")
|
||||
return
|
||||
|
||||
@app_cli.command("get_status")
|
||||
@click.argument("slug")
|
||||
def get_status_app(slug):
|
||||
"""Gets the current app status from the Kubernetes cluster
|
||||
:param slug: str Slug of app to remove
|
||||
"""
|
||||
current_app.logger.info(f"Getting status for app: {slug}")
|
||||
|
||||
app = App.query.filter_by(slug=slug).first()
|
||||
|
||||
if not app:
|
||||
current_app.logger.error(f"App {slug} does not exist")
|
||||
return
|
||||
|
||||
current_app.logger.info("Status: " + str(app.get_status()))
|
||||
|
||||
@app_cli.command("install")
|
||||
@click.argument("slug")
|
||||
def install_app(slug):
|
||||
"""Gets the current app status from the Kubernetes cluster
|
||||
:param slug: str Slug of app to remove
|
||||
"""
|
||||
current_app.logger.info(f"Installing app: {slug}")
|
||||
|
||||
app = App.query.filter_by(slug=slug).first()
|
||||
|
||||
if not app:
|
||||
current_app.logger.error(f"App {slug} does not exist")
|
||||
return
|
||||
|
||||
current_status = app.get_status()
|
||||
if current_status == APP_NOT_INSTALLED_STATUS:
|
||||
app.install()
|
||||
current_app.logger.info(
|
||||
f"App {slug} installing... use `get_status` to see status")
|
||||
else:
|
||||
current_app.logger.error("App {slug} should have status"
|
||||
f" {APP_NOT_INSTALLED_STATUS} but has status: {current_status}")
|
||||
|
||||
|
||||
|
||||
cli.cli.add_command(app_cli)
|
||||
|
||||
|
|
@ -274,7 +314,7 @@ def setpassword_user(email, password):
|
|||
# Execute UI sequence to set password, given we have a recovery URL
|
||||
result = kratos_user.ui_set_password(KRATOS_PUBLIC_URL, url, password)
|
||||
|
||||
except Exception as error:
|
||||
except Exception as error: # pylint: disable=broad-except
|
||||
current_app.logger.error(f"Error while setting password: {error}")
|
||||
return False
|
||||
|
||||
|
|
@ -313,7 +353,7 @@ def recover_user(email):
|
|||
url = kratos_user.get_recovery_link()
|
||||
|
||||
print(url)
|
||||
except Exception as error:
|
||||
except Exception as error: # pylint: disable=broad-except
|
||||
current_app.logger.error(f"Error while getting reset link: {error}")
|
||||
|
||||
|
||||
|
|
|
|||
Reference in a new issue