Enable deleting apps by using CLI

This commit is contained in:
Maarten de Waard 2022-09-22 16:14:49 +02:00
parent 5893ee39a3
commit caa9b2e79b
No known key found for this signature in database
GPG key ID: 1D3E893A657CC8DA
4 changed files with 95 additions and 33 deletions

View file

@ -88,27 +88,23 @@ def list_app():
)
@click.argument("slug")
def delete_app(slug):
"""Removes app from database
"""Removes app from database as well as uninstalls it from the cluster
:param slug: str Slug of app to remove
"""
current_app.logger.info(f"Trying to delete app: {slug}")
obj = App.query.filter_by(slug=slug).first()
app_obj = App.query.filter_by(slug=slug).first()
if not obj:
if not app_obj:
current_app.logger.info("Not found")
return
# Deleting will (probably) fail if there are still roles attached. This is a
# PoC implementation only. Actually management of apps and roles will be
# done by the backend application
db.session.delete(obj)
db.session.commit()
current_app.logger.info("Success")
deleted = app_obj.delete()
current_app.logger.info(f"Success: {deleted}")
return
@app_cli.command("get_status")
@app_cli.command("status")
@click.argument("slug")
def get_status_app(slug):
def status_app(slug):
"""Gets the current app status from the Kubernetes cluster
:param slug: str Slug of app to remove
"""
@ -125,8 +121,8 @@ def get_status_app(slug):
@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
"""Installs app into Kubernetes cluster
:param slug: str Slug of app to install
"""
current_app.logger.info(f"Installing app: {slug}")
@ -140,11 +136,28 @@ def install_app(slug):
if current_status == APP_NOT_INSTALLED_STATUS:
app.install()
current_app.logger.info(
f"App {slug} installing... use `get_status` to see status")
f"App {slug} installing... use `status` to see status")
else:
current_app.logger.error("App {slug} should have status"
f" {APP_NOT_INSTALLED_STATUS} but has status: {current_status}")
@app_cli.command("roles")
@click.argument("slug")
def roles_app(slug):
"""Gets a list of roles for this app
:param slug: str Slug of app queried
"""
current_app.logger.info(f"Getting roles 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("Roles: ")
for role in app.roles:
current_app.logger.info(role)
cli.cli.add_command(app_cli)