refactored k8s -> c4k & fixed cljs tests

This commit is contained in:
jem 2021-06-05 17:12:01 +02:00
parent 444cb32554
commit fd81f414d0
19 changed files with 92 additions and 67 deletions

View file

@ -26,7 +26,7 @@ stages:
- mkdir -p /root/.lein
- echo "{:auth {:repository-auth {#\"clojars\" {:username \"${CLOJARS_USER}\" :password \"${CLOJARS_TOKEN_DOMAINDRIVENARCHITECTURE}\" }}}}" > ~/.lein/profiles.clj
.test-cljs:
test-cljs:
<<: *cljs
stage: build_and_test
script:

View file

@ -1,26 +1,28 @@
{
"name": "k8s-keycloak",
"name": "c4k-keycloak",
"description": "Generate k8s yaml for a keycloak deployment.",
"author": "meissa GmbH",
"version": "0.1.5-SNAPSHOT",
"homepage": "https://gitlab.com/domaindrivenarchitecture/k8s-keycloak#readme",
"repository": "https://www.npmjs.com/package/k8s-keycloak",
"license": "APACHE2",
"main": "k8s-keycloak.js",
"main": "c4k-keycloak.js",
"bin": {
"k8s-keycloak": "./k8s-keycloak.js"
"c4k-keycloak": "./c4k-keycloak.js"
},
"keywords": [
"cljs",
"keycloak",
"k8s",
"deplyoment",
"yaml"
"yaml",
"convention4kubernetes"
],
"bugs": {
"url": "https://gitlab.com/domaindrivenarchitecture/k8s-keycloak/issues"
},
"dependencies": {
"js-base64": "^3.6.1",
"js-yaml": "^4.0.0"
},
"devDependencies": {

View file

@ -1,4 +1,4 @@
(defproject org.domaindrivenarchitecture/k8s-keycloak "0.1.0-SNAPSHOT"
(defproject org.domaindrivenarchitecture/c4k-keycloak "0.1.0-SNAPSHOT"
:description "keycloak k8s-installation package"
:url "https://domaindrivenarchitecture.org"
:license {:name "Apache License, Version 2.0"
@ -22,7 +22,7 @@
:dependencies [[dda/data-test "0.1.1"]]}
:dev {:plugins [[lein-shell "0.5.0"]]}
:uberjar {:aot :all
:main dda.k8s-keycloak.uberjar
:main dda.c4k-keycloak.uberjar
:uberjar-name "k8s-keycloak-standalone.jar"
:dependencies [[org.clojure/tools.cli "1.0.206"]
[ch.qos.logback/logback-classic "1.3.0-alpha4"

View file

@ -1,13 +1,14 @@
{:source-paths ["src/main/cljc"
"src/main/cljs"
"src/main/resources"
"src/test/cljc"]
"src/test/cljc"
"src/test/resources"]
:dependencies [[aero "1.1.6"]
[orchestra "2021.01.01-1"]
[expound "0.8.9"]]
:dev-http {8080 "public"}
:builds {:frontend {:target :browser
:modules {:main {:init-fn dda.k8s-keycloak.browser/init}}
:modules {:main {:init-fn dda.c4k-keycloak.browser/init}}
:release {}
:compiler-options {:optimizations :advanced}}
:test {:target :node-test

View file

@ -1,4 +1,4 @@
(ns dda.k8s-keycloak.base64
(ns dda.c4k-keycloak.base64
(:import (java.util Base64)))
(defn encode

View file

@ -1,11 +1,11 @@
(ns dda.k8s-keycloak.uberjar
(ns dda.c4k-keycloak.uberjar
(:gen-class)
(:require
[clojure.spec.alpha :as s]
[clojure.string :as cs]
[clojure.tools.reader.edn :as edn]
[expound.alpha :as expound]
[dda.k8s-keycloak.core :as core]))
[dda.c4k-keycloak.core :as core]))
(def usage
"usage:

View file

@ -1,4 +1,4 @@
(ns dda.k8s-keycloak.yaml
(ns dda.c4k-keycloak.yaml
(:require
[clojure.java.io :as io]
[clj-yaml.core :as yaml]

View file

@ -1,4 +1,4 @@
(ns dda.k8s-keycloak.common
(ns dda.c4k-keycloak.common
(:require
[clojure.walk]))

View file

@ -1,12 +1,12 @@
(ns dda.k8s-keycloak.core
(ns dda.c4k-keycloak.core
(:require
[clojure.string :as cs]
[clojure.spec.alpha :as s]
#?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]])
[dda.k8s-keycloak.yaml :as yaml]
[dda.k8s-keycloak.keycloak :as kc]
[dda.k8s-keycloak.postgres :as pg]))
[dda.c4k-keycloak.yaml :as yaml]
[dda.c4k-keycloak.keycloak :as kc]
[dda.c4k-keycloak.postgres :as pg]))
(def config? (s/keys :req-un [::kc/fqdn]
:opt-un [::kc/issuer]))

View file

@ -1,9 +1,9 @@
(ns dda.k8s-keycloak.keycloak
(ns dda.c4k-keycloak.keycloak
(:require
[clojure.spec.alpha :as s]
[dda.k8s-keycloak.yaml :as yaml]
[dda.k8s-keycloak.base64 :as b64]
[dda.k8s-keycloak.common :as cm]))
[dda.c4k-keycloak.yaml :as yaml]
[dda.c4k-keycloak.base64 :as b64]
[dda.c4k-keycloak.common :as cm]))
(s/def ::keycloak-admin-user cm/bash-env-string?)
(s/def ::keycloak-admin-password cm/bash-env-string?)

View file

@ -1,9 +1,9 @@
(ns dda.k8s-keycloak.postgres
(ns dda.c4k-keycloak.postgres
(:require
[clojure.spec.alpha :as s]
[dda.k8s-keycloak.yaml :as yaml]
[dda.k8s-keycloak.base64 :as b64]
[dda.k8s-keycloak.common :as cm]))
[dda.c4k-keycloak.yaml :as yaml]
[dda.c4k-keycloak.base64 :as b64]
[dda.c4k-keycloak.common :as cm]))
(s/def ::postgres-db-user cm/bash-env-string?)
(s/def ::postgres-db-password cm/bash-env-string?)

View file

@ -0,0 +1,11 @@
(ns dda.c4k-keycloak.base64
(:require
["js-base64" :as b64]))
(defn encode
[string]
(.encode b64/Base64 string))
(defn decode
[string]
(.decode b64/Base64 string))

View file

@ -1,9 +1,9 @@
(ns dda.k8s-keycloak.browser
(ns dda.c4k-keycloak.browser
(:require
[clojure.spec.alpha :as s]
[clojure.tools.reader.edn :as edn]
[expound.alpha :as expound]
[dda.k8s-keycloak.core :as core]))
[dda.c4k-keycloak.core :as core]))
(defn print-debug [sth]
(print "debug " sth)

View file

@ -0,0 +1,44 @@
(ns dda.c4k-keycloak.yaml
(:require
["js-yaml" :as yaml]
[shadow.resource :as rc]))
(def postgres-config (rc/inline "postgres/config.yaml"))
(def postgres-secret (rc/inline "postgres/secret.yaml"))
(def postgres-deployment (rc/inline "postgres/deployment.yaml"))
(def postgres-service (rc/inline "postgres/service.yaml"))
(def keycloak-secret (rc/inline "keycloak/secret.yaml"))
(def keycloak-deployment (rc/inline "keycloak/deployment.yaml"))
(def keycloak-certificate (rc/inline "keycloak/certificate.yaml"))
(def keycloak-ingress (rc/inline "keycloak/ingress.yaml"))
(def keycloak-service (rc/inline "keycloak/service.yaml"))
(def ingress-test (rc/inline "ingress_test.yaml"))
(defn load-resource [resource-name]
(case resource-name
"postgres/config.yaml" postgres-config
"postgres/secret.yaml" postgres-secret
"postgres/deployment.yaml" postgres-deployment
"postgres/service.yaml" postgres-service
"keycloak/secret.yaml" keycloak-secret
"keycloak/deployment.yaml" keycloak-deployment
"keycloak/certificate.yaml" keycloak-certificate
"keycloak/ingress.yaml" keycloak-ingress
"keycloak/service.yaml" keycloak-service
"ingress_test.yaml" ingress-test))
(defn from-string [input]
(js->clj (yaml/load input)
:keywordize-keys true))
(defn to-string [edn]
(yaml/dump (clj->js edn)))

View file

@ -1,9 +0,0 @@
(ns dda.k8s-keycloak.base64)
(defn encode
[string]
(.btoa js/window string))
(defn decode
[string]
(.atob js/window string))

View file

@ -1,24 +0,0 @@
(ns dda.k8s-keycloak.yaml
(:require
["js-yaml" :as yaml]
[shadow.resource :as rc]
))
(def config (rc/inline "config.yaml"))
(def cron (rc/inline "cron.yaml"))
(def deployment (rc/inline "deployment.yaml"))
(defn load-resource [resource-name]
(case resource-name
"config.yaml" config
"cron.yaml" cron
"deployment.yaml" deployment))
(defn from-string [input]
(js->clj (yaml/load input)
:keywordize-keys true))
(defn to-string [edn]
(yaml/dump (clj->js edn)))

View file

@ -1,8 +1,8 @@
(ns dda.k8s-keycloak.keycloak-test
(ns dda.c4k-keycloak.keycloak-test
(:require
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
[dda.k8s-keycloak.keycloak :as cut]))
[dda.c4k-keycloak.keycloak :as cut]))
(deftest should-generate-secret
(is (= {:apiVersion "v1"

View file

@ -1,8 +1,8 @@
(ns dda.k8s-keycloak.postgres-test
(ns dda.c4k-keycloak.postgres-test
(:require
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
[dda.k8s-keycloak.postgres :as cut]))
[dda.c4k-keycloak.postgres :as cut]))
(deftest should-generate-secret
(is (= {:apiVersion "v1"

View file

@ -1,8 +1,8 @@
(ns dda.k8s-keycloak.yaml-test
(ns dda.c4k-keycloak.yaml-test
(:require
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
[dda.k8s-keycloak.yaml :as cut]))
[dda.c4k-keycloak.yaml :as cut]))
(deftest should-parse-yaml-string
(is (= {:hallo "welt"}