Implement browser

This commit is contained in:
erik 2023-09-05 12:36:40 +02:00
parent 74b1c60fbe
commit bcdaf3e541

View file

@ -6,8 +6,9 @@
[dda.c4k-taiga.core :as core] [dda.c4k-taiga.core :as core]
[dda.c4k-taiga.taiga :as taiga] [dda.c4k-taiga.taiga :as taiga]
[dda.c4k-common.common :as cm] [dda.c4k-common.common :as cm]
[dda.c4k-common.predicate :as cp]
[dda.c4k-common.browser :as br] [dda.c4k-common.browser :as br]
)) [dda.c4k-common.postgres :as postgres]))
(defn generate-content [] (defn generate-content []
(cm/concat-vec (cm/concat-vec
@ -17,46 +18,38 @@
(br/generate-group (br/generate-group
"domain" "domain"
(cm/concat-vec (cm/concat-vec
(br/generate-input-field "fqdn" "The fully qualified domain name of your Taiga Instance:" "taiga.example.com")
(br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "staging") (br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" "staging")
(br/generate-input-field "mon-cluster-name" "(Optional) monitoring cluster name:" "taiga") (br/generate-input-field "mon-cluster-name" "(Optional) monitoring cluster name:" "taiga")
(br/generate-input-field "mon-cluster-stage" "(Optional) monitoring cluster stage:" "test") (br/generate-input-field "mon-cluster-stage" "(Optional) monitoring cluster stage:" "test")
(br/generate-input-field "mon-cloud-url" "(Optional) grafana cloud url:" "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push"))) (br/generate-input-field "mon-cloud-url" "(Optional) grafana cloud url:" "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push")))
(br/generate-group (br/generate-group
"taiga-data" "options"
(br/generate-text-area (cm/concat-vec
"taigas" "Contains fqdns, repo infos, an optional sha256sum-output for script execution for each taiga:" (br/generate-input-field "public-register-enabled" "(Optional) Allow public registration?" "false")
"{ :taigas (br/generate-input-field "enable-telemetry" "(Optional) Allow anonymous collection of usage data?" "false")
[{:unique-name \"test.io\", (br/generate-input-field "pv-storage-size-gb" "(Optional) The volume size of your postgres DB:" "5")
:fqdns [\"test.de\" \"www.test.de\"], (br/generate-input-field "storage-class-name" "(Optional) Name of storage class:" "local-path")
:gitea-host \"githost.de\", (br/generate-input-field "storage-media-size" "(Optional) The size of your media storage:" "5")
:gitea-repo \"repo\", (br/generate-input-field "storage-static-size" "(Optional) The size of your static data storage:" "5")
:branchname \"main\", (br/generate-input-field "storage-async-rabbitmq-size" "(Optional) The size of your rabbitmq async storage:" "5")
:sha256sum-output \"123456789ab123cd345de script-file-name.sh\"} (br/generate-input-field "storage-events-rabbitmq-size" "(Optional) The size of your rabbitmq events storage:" "5")))
{:unique-name \"example.io \",
:fqdns [\"example.org\" \"www.example.org\"],
:gitea-host \"githost.org\",
:gitea-repo \"repo\",
:branchname \"main\",
:build-cpu-request \"1500m\",
:build-cpu-limit \"3000m\",
:build-memory-request \"512Mi\",
:build-memory-limit \"1024Mi\"}] }"
"16"))
(br/generate-group (br/generate-group
"credentials" "credentials"
(br/generate-text-area (cm/concat-vec
"auth" "Your authentication data for each taiga or git repo:" (br/generate-input-field "postgres-db-user" "Your postgres user:" "postgres")
"{:mon-auth (br/generate-input-field "postgres-db-password" "Your postgres password:" "change-me")
{:grafana-cloud-user \"your-user-id\" (br/generate-input-field "mailer-user" "Allow taiga access to a mail account:" "mail[at]example.com")
:grafana-cloud-password \"your-cloud-password\"} (br/generate-input-field "mailer-pw" "Allow taiga access to a mail account:" "change-me")
:auth (br/generate-input-field "django-superuser-username" "The superusers username:" "admin")
[{:unique-name \"test.io\", (br/generate-input-field "django-superuser-password" "The superusers password:" "change-me")
:username \"someuser\", (br/generate-input-field "django-superuser-email" "The superusers email:" "mail[at]example.com")
:authtoken \"abedjgbasdodj\"} (br/generate-input-field "rabbitmq-user" "User for rabbitmq:" "user")
{:unique-name \"example.io\", (br/generate-input-field "rabbitmq-pw" "Password for the rabbitmq user:" "change-me")
:username \"someuser\", (br/generate-input-field "rabbitmq-erlang-cookie" "Random hash shared among all rabbitmq pods:" "change-me")
:authtoken \"abedjgbasdodj\"}]}" (br/generate-input-field "taiga-secret-key" "Random key shared among all taiga pods:" "change-me")
"7")) (br/generate-input-field "grafana-cloud-user" "Your grafana user name:" "user")
(br/generate-input-field "grafana-cloud-password" "Your grafana password:" "change-me")))
[(br/generate-br)] [(br/generate-br)]
(br/generate-button "generate-button" "Generate c4k yaml")))] (br/generate-button "generate-button" "Generate c4k yaml")))]
(br/generate-output "c4k-taiga-output" "Your c4k deployment.yaml:" "15"))) (br/generate-output "c4k-taiga-output" "Your c4k deployment.yaml:" "15")))
@ -68,14 +61,60 @@
:content :content
(generate-content)}) (generate-content)})
(defn auth-from-document []
(let [postgres-db-user (br/get-content-from-element "postgres-db-user" )
postgres-db-password (br/get-content-from-element "postgres-db-password" )
mailer-user (br/get-content-from-element "mailer-user" )
mailer-pw (br/get-content-from-element "mailer-pw" )
django-superuser-username (br/get-content-from-element "django-superuser-username" )
django-superuser-password (br/get-content-from-element "django-superuser-password" )
django-superuser-email (br/get-content-from-element "django-superuser-email" )
rabbitmq-user (br/get-content-from-element "rabbitmq-user" )
rabbitmq-pw (br/get-content-from-element "rabbitmq-pw" )
rabbitmq-erlang-cookie (br/get-content-from-element "rabbitmq-erlang-cookie" )
taiga-secret-key (br/get-content-from-element "taiga-secret-key" )
grafana-cloud-user (br/get-content-from-element "grafana-cloud-user" :optional true)
grafana-cloud-password (br/get-content-from-element "grafana-cloud-password" :optional true)]
(merge
{:postgres-db-user postgres-db-user}
{:postgres-db-password postgres-db-password}
{:mailer-user mailer-user}
{:mailer-pw mailer-pw}
{:django-superuser-username django-superuser-username}
{:django-superuser-password django-superuser-password}
{:django-superuser-email django-superuser-email}
{:rabbitmq-user rabbitmq-user}
{:rabbitmq-pw rabbitmq-pw}
{:rabbitmq-erlang-cookie rabbitmq-erlang-cookie}
{:taiga-secret-key taiga-secret-key}
(when (some? grafana-cloud-user)
{:mon-auth {:grafana-cloud-user grafana-cloud-user
:grafana-cloud-password grafana-cloud-password}}))))
(defn config-from-document [] (defn config-from-document []
(let [issuer (br/get-content-from-element "issuer" :optional true) (let [issuer (br/get-content-from-element "issuer" :optional true)
taigas (br/get-content-from-element "taigas" :deserializer edn/read-string) fqdn (br/get-content-from-element "fqdn" :deserializer edn/read-string)
public-register-enabled (br/get-content-from-element "public-register-enabled" :deserializer edn/read-string)
enable-telemetry (br/get-content-from-element "enable-telemetry" :deserializer edn/read-string)
pv-storage-size-gb (br/get-content-from-element "pv-storage-size-gb" :deserializer edn/read-string)
storage-class-name (br/get-content-from-element "storage-class-name" :deserializer edn/read-string)
storage-media-size (br/get-content-from-element "storage-media-size" :deserializer edn/read-string)
storage-static-size (br/get-content-from-element "storage-static-size" :deserializer edn/read-string)
storage-async-rabbitmq-size (br/get-content-from-element "storage-async-rabbitmq-size" :deserializer edn/read-string)
storage-events-rabbitmq-size (br/get-content-from-element "storage-events-rabbitmq-size" :deserializer edn/read-string)
mon-cluster-name (br/get-content-from-element "mon-cluster-name" :optional true) mon-cluster-name (br/get-content-from-element "mon-cluster-name" :optional true)
mon-cluster-stage (br/get-content-from-element "mon-cluster-stage" :optional true) mon-cluster-stage (br/get-content-from-element "mon-cluster-stage" :optional true)
mon-cloud-url (br/get-content-from-element "mon-cloud-url" :optional true)] mon-cloud-url (br/get-content-from-element "mon-cloud-url" :optional true)]
(merge (merge
{:taigas taigas} {:fqdn fqdn}
{:public-register-enabled public-register-enabled}
{:enable-telemetry enable-telemetry}
{:pv-storage-size-gb pv-storage-size-gb}
{:storage-class-name storage-class-name}
{:storage-media-size storage-media-size}
{:storage-static-size storage-static-size}
{:storage-async-rabbitmq-size storage-async-rabbitmq-size}
{:storage-events-rabbitmq-size storage-events-rabbitmq-size}
(when (not (st/blank? issuer)) (when (not (st/blank? issuer))
{:issuer issuer}) {:issuer issuer})
(when (some? mon-cluster-name) (when (some? mon-cluster-name)
@ -84,12 +123,32 @@
:grafana-cloud-url mon-cloud-url}})))) :grafana-cloud-url mon-cloud-url}}))))
(defn validate-all! [] (defn validate-all! []
(br/validate! "taigas" taiga/taigas? :deserializer edn/read-string) (br/validate! "fqdn" ::taiga/fqdn )
(br/validate! "issuer" ::taiga/issuer :optional true) (br/validate! "issuer" ::taiga/issuer :optional true)
(br/validate! "public-register-enabled" ::taiga/public-register-enabled :optional true)
(br/validate! "enable-telemetry" ::taiga/enable-telemetry :optional true)
(br/validate! "pv-storage-size-gb" ::postgres/pv-storage-size-gb :optional true)
(br/validate! "storage-class-name" ::taiga/storage-class-name :optional true)
(br/validate! "storage-media-size" ::taiga/storage-media-size :optional true)
(br/validate! "storage-static-size" ::taiga/storage-static-size :optional true)
(br/validate! "storage-async-rabbitmq-size" ::taiga/storage-async-rabbitmq-size :optional true)
(br/validate! "storage-events-rabbitmq-size" ::taiga/storage-events-rabbitmq-size :optional true)
(br/validate! "mon-cluster-name" ::mon/cluster-name :optional true) (br/validate! "mon-cluster-name" ::mon/cluster-name :optional true)
(br/validate! "mon-cluster-stage" ::mon/cluster-stage :optional true) (br/validate! "mon-cluster-stage" ::mon/cluster-stage :optional true)
(br/validate! "mon-cloud-url" ::mon/grafana-cloud-url :optional true) (br/validate! "mon-cloud-url" ::mon/grafana-cloud-url :optional true)
(br/validate! "auth" taiga/auth? :deserializer edn/read-string) (br/validate! "postgres-db-user" ::postgres/postgres-db-user )
(br/validate! "postgres-db-password" ::postgres/postgres-db-password )
(br/validate! "mailer-user" ::taiga/mailer-user )
(br/validate! "mailer-pw" ::taiga/mailer-pw )
(br/validate! "django-superuser-username" ::taiga/django-superuser-username )
(br/validate! "django-superuser-password" ::taiga/django-superuser-password )
(br/validate! "django-superuser-email" ::taiga/django-superuser-email )
(br/validate! "rabbitmq-user" ::taiga/rabbitmq-user )
(br/validate! "rabbitmq-pw" ::taiga/rabbitmq-pw )
(br/validate! "rabbitmq-erlang-cookie" ::taiga/rabbitmq-erlang-cookie )
(br/validate! "taiga-secret-key" ::taiga/taiga-secret-key )
(br/validate! "grafana-cloud-user" ::mon/grafana-cloud-user )
(br/validate! "grafana-cloud-password" ::mon/grafana-cloud-password )
(br/set-form-validated!)) (br/set-form-validated!))
(defn add-validate-listener [name] (defn add-validate-listener [name]
@ -104,13 +163,33 @@
#(do (validate-all!) #(do (validate-all!)
(-> (cm/generate-common (-> (cm/generate-common
(config-from-document) (config-from-document)
(br/get-content-from-element "auth" :deserializer edn/read-string) (auth-from-document)
core/config-defaults core/config-defaults
core/k8s-objects) core/k8s-objects)
(br/set-output!))))) (br/set-output!)))))
(add-validate-listener "taigas") (add-validate-listener "fqdn")
(add-validate-listener "issuer") (add-validate-listener "issuer")
(add-validate-listener "public-register-enabled")
(add-validate-listener "enable-telemetry")
(add-validate-listener "pv-storage-size-gb")
(add-validate-listener "storage-class-name")
(add-validate-listener "storage-media-size")
(add-validate-listener "storage-static-size")
(add-validate-listener "storage-async-rabbitmq-size")
(add-validate-listener "storage-events-rabbitmq-size")
(add-validate-listener "mon-cluster-name") (add-validate-listener "mon-cluster-name")
(add-validate-listener "mon-cluster-stage") (add-validate-listener "mon-cluster-stage")
(add-validate-listener "mon-cloud-url") (add-validate-listener "mon-cloud-url")
(add-validate-listener "auth")) (add-validate-listener "postgres-db-user")
(add-validate-listener "postgres-db-password")
(add-validate-listener "mailer-user")
(add-validate-listener "mailer-pw")
(add-validate-listener "django-superuser-username")
(add-validate-listener "django-superuser-password")
(add-validate-listener "django-superuser-email")
(add-validate-listener "rabbitmq-user")
(add-validate-listener "rabbitmq-pw")
(add-validate-listener "rabbitmq-erlang-cookie")
(add-validate-listener "taiga-secret-key")
(add-validate-listener "grafana-cloud-user")
(add-validate-listener "grafana-cloud-password"))