This commit is contained in:
bom 2021-05-21 17:29:24 +02:00
parent 4b30021201
commit a98aae76bf
3 changed files with 52 additions and 14 deletions

View file

@ -6,19 +6,46 @@
:cljs [orchestra.core :refer-macros [defn-spec]])
[dda.k8s-keycloak.yaml :as yaml]))
(def config? any?)
(defn bash-env-string?
[input]
(and (string? input)
(not (re-matches #".*['\"\$]+.*" input))))
(defn fqdn-string?
[input]
(and (string? input)
(not (nil? (re-matches #"(?=^.{4,253}\.?$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}\.?$)" input)))))
(s/def ::user-name bash-env-string?)
(s/def ::user-password string?)
(s/def ::fqdn fqdn-string?)
(def config? (s/keys :req-un [::user-name ::user-password ::fqdn]
:opt-un [::issuer]))
(def auth? any?)
(def config? config?)
(defn generate-config [my-config my-auth]
(->
(yaml/from-string (yaml/load-resource "config.yaml"))
(assoc-in [:data :config.edn] (str my-config))
(assoc-in [ :data :credentials.edn] (str my-auth))
))
(assoc-in [ :data :credentials.edn] (str my-auth))))
(defn generate-deployment []
(yaml/from-string (yaml/load-resource "deployment.yaml")))
(defn generate-deployment [config]
(let [user (:user config)
password (:password config)]
(->
(yaml/from-string (yaml/load-resource "deployment.yaml"))
(assoc-in [:spec :template :spec :containers]
[{:name "keycloak"
:image "quay.io/keycloak/keycloak:13.0.0"
:env
[{:name "KEYCLOAK_USER", :value user}
{:name "KEYCLOAK_PASSWORD", :value password}
{:name "PROXY_ADDRESS_FORWARDING", :value "true"}]
:ports [{:name "http", :containerPort 8080}]
:readinessProbe {:httpGet {:path "/auth/realms/master", :port 8080}}}]))))
(defn generate-certificate [config]
(let [{:keys [fqdn issuer]
@ -41,12 +68,20 @@
(assoc-in [:spec :rules] [{:host fqdn
:http {:paths [{:backend {:serviceName "keycloak"
:servicePort 8080}}]}}]))))
(defn generate-service []
(yaml/from-string (yaml/load-resource "service.yaml")))
(defn-spec generate any?
[my-config string?
my-auth string?]
(cs/join "\n"
[(yaml/to-string (generate-config my-config my-auth))
"---"
(yaml/to-string (generate-config))
"---"
(yaml/to-string (generate-ingress))
"---"
(yaml/to-string (generate-service))
"---"
(yaml/to-string (generate-deployment))]))

View file

@ -63,7 +63,7 @@
:issuer :prod}))))
(deftest should-generate-deployment
(is (= {{:apiVersion "apps/v1"
(is (= {:apiVersion "apps/v1"
:kind "Deployment"
:metadata {:name "keycloak", :namespace "default", :labels {:app "keycloak"}}
:spec
@ -73,12 +73,12 @@
{:metadata {:labels {:app "keycloak"}}
:spec
{:containers
[({:name "keycloak"
[{:name "keycloak"
:image "quay.io/keycloak/keycloak:13.0.0"
:env
({:name "KEYCLOAK_USER", :value "admin"}
{:name "KEYCLOAK_PASSWORD", :value "admin"}
{:name "PROXY_ADDRESS_FORWARDING", :value "true"})
:ports ({:name "http", :containerPort 8080})
:readinessProbe {:httpGet {:path "/auth/realms/master", :port 8080}}})]}}}}}
(cut/generate-deployment))))
[{:name "KEYCLOAK_USER", :value "testuser"}
{:name "KEYCLOAK_PASSWORD", :value "test1234"}
{:name "PROXY_ADDRESS_FORWARDING", :value "true"}]
:ports [{:name "http", :containerPort 8080}]
:readinessProbe {:httpGet {:path "/auth/realms/master", :port 8080}}}]}}}}
(cut/generate-deployment {:user "testuser" :password "test1234"}))))

View file

@ -1 +1,4 @@
{}
{:fqdn "test.de"
:user-name "testuser"
:user-password "test1234"
:issuer :prod}