Make PlaygroundForm configurable via YAML file

Lauri Võsandi 2 months ago
parent 59cc322c18
commit f9152bd6cb
  1. 3
  2. 25
  3. 62
  4. 18

@ -1,4 +1,5 @@
ADD config /config
ADD app /app
ENTRYPOINT /app/ /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 = ""
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")
argocd = BooleanField("Instantiate ArgoCD instance in this namespace")
submit = SubmitField("Confirm")
with open(path) as fh:
for kwargs in yaml.safe_load(
if kwargs["default"]:
kwargs["render_kw"] = {"checked": ""}
setattr(PlaygroundForm, kwargs["name"], BooleanField(**kwargs))
@ -87,6 +89,7 @@ async def create_sandbox(email, values):
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 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="" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<link href="" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<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 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.description }}
{%- for error in field.errors %}
<span class="form__error">{{ error }}</span>
{% endfor %}
{% endif %}
{% endfor %}
<div class="container">
<button type="submit" class="btn btn-primary">Create sandbox</button>

@ -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"
- name: argocd
description: "Set up separate ArgoCD instance for this namespace"
default: false