51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""Forms for app installation."""
|
|
from os import environ
|
|
|
|
from flask import request
|
|
from flask_wtf import FlaskForm
|
|
from wtforms import PasswordField, StringField
|
|
from wtforms.validators import DataRequired, Length
|
|
|
|
|
|
class GiteaInstallForm(FlaskForm):
|
|
"""Gitea installation form."""
|
|
|
|
# "simple"
|
|
app_name = StringField("Application name", default="Git with a cup of tea")
|
|
domain = StringField("Domain name", validators=[DataRequired()],)
|
|
stack_name = StringField("Stack name", default="magic-app-gitea")
|
|
|
|
# "advanced"
|
|
db_host = StringField("Database host", default="mariadb:3306")
|
|
db_name = StringField("Database name", default="gitea")
|
|
db_type = StringField("Database type", default="mysql")
|
|
db_user = StringField("Database user", default="mysql")
|
|
ssh_host_port = StringField("SSH host port", default="2225")
|
|
|
|
# secrets
|
|
db_passwd = PasswordField(
|
|
"Database password", validators=[DataRequired(), Length(min=32)],
|
|
)
|
|
db_root_passwd = PasswordField(
|
|
"Database root password", validators=[DataRequired(), Length(min=32)],
|
|
)
|
|
internal_token = PasswordField(
|
|
"Internal secret token", validators=[DataRequired(), Length(min=105)],
|
|
)
|
|
jwt_secret = PasswordField(
|
|
"JWT secret", validators=[DataRequired(), Length(min=43)],
|
|
)
|
|
secret_key = PasswordField(
|
|
"Secret key", validators=[DataRequired(), Length(min=64)],
|
|
)
|
|
|
|
|
|
def form_to_env(app_name, request_form):
|
|
"""Load form data into a environment."""
|
|
env = environ.copy()
|
|
|
|
for key in request_form.keys():
|
|
env[key.upper()] = request.form[key]
|
|
|
|
return env
|