From e2eee7f3bb80ea0940d9dd2ae19fdfedb0e57494 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 1 Jul 2020 20:42:47 +0200 Subject: [PATCH] Spec out a second approach --- second.py | 45 +++++++++++++++++++++++++++++------ templates/second/index.html | 16 +++++++++++++ templates/second/install.html | 20 ++++++++++++++++ 3 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 templates/second/index.html create mode 100644 templates/second/install.html diff --git a/second.py b/second.py index 2aadaf2..99c77ed 100644 --- a/second.py +++ b/second.py @@ -1,27 +1,58 @@ """Less flashy version. Mord hard-coding.""" from pathlib import Path +from shlex import split +from subprocess import run from flask import Flask, render_template +from flask_wtf import FlaskForm from ruamel.yaml import YAML +from wtforms import PasswordField, StringField +from wtforms.validators import DataRequired app = Flask(__name__) - -# Note(decentral1se): load from env vars at some point app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' yaml = YAML() -# Note(decentral1se): paths needs to change dependening -# on deployment mode ./data in dev, /data in production +APPS = {"gitea": "https://git.autonomic.zone/compose-stacks/gitea"} DATA_DIR = Path("./data") -STATIC_DIR = Path(app.root_path).absolute() / "static" + +class GiteaConfigForm(FlaskForm): + app_name = StringField("Application name", default="Gitea") + db_host = StringField("Database host", default="mariadb:3306") + db_name = StringField("Database name", default="gitea") + db_passwd = PasswordField("Database password", validators=[DataRequired()]) + db_root_passwd = PasswordField( + "Root database password", validators=[DataRequired()] + ) + db_type = StringField("Database type", default="mysql") + db_user = StringField("Database user", default="mysql") + domain = StringField("Domain name", validators=[DataRequired()]) + ssh_port = StringField("SSH port", default="2222") + stack_name = StringField("Stack name", default="gitea") + internal_token = PasswordField("Internal token", validators=[DataRequired()]) + jwt_secret = PasswordField("JWT secret", validators=[DataRequired()]) + + +def clone_app_template(app_name): + """Git clone an app template repository.""" + clone_path = DATA_DIR / app_name + clone_url = apps[app_name] + run(split(f"git clone {clone_url} {clone_path}")) @app.route("/") -def home(): - pass +def index(): + return render_template("second/index.html", apps=[app for app in APPS]) + + +@app.route("/") +def app_config(app_name): + if app_name == "gitea": + form = GiteaConfigForm() + return render_template("second/install.html", app_name=app_name, form=form) if __name__ == "__main__": diff --git a/templates/second/index.html b/templates/second/index.html new file mode 100644 index 0000000..3365ddd --- /dev/null +++ b/templates/second/index.html @@ -0,0 +1,16 @@ + + + + + + Magic App + + +

List of apps that can be installed:

+ + {% endfor %} + + diff --git a/templates/second/install.html b/templates/second/install.html new file mode 100644 index 0000000..b09156f --- /dev/null +++ b/templates/second/install.html @@ -0,0 +1,20 @@ + + + + + + Install {{ app_name }} + + +

Install {{ app_name }}

+
+ {% for field in form %} +
+ {{ field.label() }} + {{ field() }} +
+ {% endfor %} + +
+ +