Make PlaygroundForm configurable via YAML file

main
Lauri Võsandi 2 months ago
parent 59cc322c18
commit f9152bd6cb
  1. 3
      Dockerfile
  2. 25
      app/sandbox-dashboard.py
  3. 62
      app/templates/add.html
  4. 18
      config/playground.yaml

@ -1,4 +1,5 @@
FROM harbor.k-space.ee/k-space/microservice-base
ADD config /config
ADD app /app
WORKDIR /app
ENTRYPOINT /app/sandbox-dashboard.py
ENTRYPOINT /app/sandbox-dashboard.py /config/playground.yaml

@ -1,32 +1,34 @@
#!/usr/bin/env python3
import os
import string
import random
import sys
import string
import yaml
from sanic import Sanic, response
from kubernetes_asyncio.client.api_client import ApiClient
from kubernetes_asyncio import client, config
from sanic_wtf import SanicForm
from wtforms import SubmitField, BooleanField
from wtforms import BooleanField
fallback_email = "lauri.vosandi@gmail.com"
characters = "abcdefghijkmnpqrstuvwxyz23456789"
app = Sanic("dashboard")
session = {}
_, path = sys.argv
if not app.config.get("WTF_CSRF_SECRET_KEY", ""):
raise ValueError("SANIC_WTF_CSRF_SECRET_KEY environment variable not set")
class PlaygroundForm(SanicForm):
harbor_project = BooleanField("Create Harbor project with"
"push/pull credentials in this sandbox, for Skaffold development")
dex = BooleanField(description="Instantiate Dex for this namespace")
logging = BooleanField("Instantiate Logmower stack for this namespace")
prometheus = BooleanField("Instantiate Prometheus for this namespace")
traefik = BooleanField("Instantiate dedicated Traeifk instance in this namespace")
subdomain = BooleanField("Create dedicated subdomain under codemowers.cloud")
argocd = BooleanField("Instantiate ArgoCD instance in this namespace")
submit = SubmitField("Confirm")
pass
with open(path) as fh:
for kwargs in yaml.safe_load(fh.read()):
if kwargs["default"]:
kwargs["render_kw"] = {"checked": ""}
setattr(PlaygroundForm, kwargs["name"], BooleanField(**kwargs))
@app.middleware("request")
@ -87,6 +89,7 @@ async def create_sandbox(email, values):
@app.ext.template("add.html")
async def add_namespace_form(request):
form = PlaygroundForm(request)
if form.validate():
sandbox_name = await create_sandbox(request.headers.get("X-Forwarded-User", fallback_email),
values=[{"name": key, "value": str(value)} for (key, value) in form.data.items() if key not in ("submit", "csrf_token")])

@ -6,45 +6,45 @@
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="/docs/4.0/assets/img/favicons/favicon.ico">
<title>Jumbotron Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
</head>
<body>
<br/>
<br/>
<br/>
<br/>
<main role="main">
<div class="container">
<p>Select feature flags for the namespace:</p>
<form action="/add" method="POST">
{{ form.csrf_token }}
{% for field in form %}
{{ field.label() }}
{{ field() }}<br/>
{% endfor %}
<button type="submit" />
</form>
</div>
<form action="/add" method="POST">
<main role="main">
<div class="container">
<p>Select feature flags for the sandbox:</p>
{{ form.csrf_token }}
<ul class="list-group">
{% for field in form %}
{% if field.type == "BooleanField" %}
<li class="list-group-item" style="user-select: none;">
<div class="form-check form-switch">
{{ field(class_="form-check-input")}}
<label class="form-check-label" for="{{ field.id }}">
{{ field.description }}
{%- for error in field.errors %}
<span class="form__error">{{ error }}</span>
{% endfor %}
</label>
</div>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
<br/>
<div class="container">
<p>
<button type="submit" class="btn btn-primary">Create sandbox</button>
</p>
</div>
</main>
</form>
</body>
</html>

@ -0,0 +1,18 @@
- name: prometheus
description: "Set up dedicated Prometheus instance for this sandbox"
default: true
- name: logging
description: "Enable logging with shared Logmower instance"
default: true
- name: traefik
description: "Set up dedicated Traefik instance for this sandbox"
default: false
- name: harbor_project
description: "Set up Docker registry push/pull secrets for Skaffold use"
default: true
- name: subdomain
default: false
description: "Create dedicated subdomain under codemowers.cloud"
- name: argocd
description: "Set up separate ArgoCD instance for this namespace"
default: false
Loading…
Cancel
Save