From fd81f414d01953a13e4bc27b7e1e1687044fe4ad Mon Sep 17 00:00:00 2001 From: jem Date: Sat, 5 Jun 2021 17:12:01 +0200 Subject: [PATCH] refactored k8s -> c4k & fixed cljs tests --- .gitlab-ci.yml | 2 +- package.json | 10 +++-- project.clj | 4 +- shadow-cljs.edn | 5 ++- .../{k8s_keycloak => c4k_keycloak}/base64.clj | 2 +- .../uberjar.clj | 4 +- .../{k8s_keycloak => c4k_keycloak}/yaml.clj | 2 +- .../common.cljc | 2 +- .../{k8s_keycloak => c4k_keycloak}/core.cljc | 8 ++-- .../keycloak.cljc | 8 ++-- .../postgres.cljc | 8 ++-- src/main/cljs/dda/c4k_keycloak/base64.cljs | 11 +++++ .../browser.cljs | 4 +- src/main/cljs/dda/c4k_keycloak/yaml.cljs | 44 +++++++++++++++++++ src/main/cljs/dda/k8s_keycloak/base64.cljs | 9 ---- src/main/cljs/dda/k8s_keycloak/yaml.cljs | 24 ---------- .../keycloak_test.cljc | 4 +- .../postgres_test.cljc | 4 +- .../yaml_test.cljc | 4 +- 19 files changed, 92 insertions(+), 67 deletions(-) rename src/main/clj/dda/{k8s_keycloak => c4k_keycloak}/base64.clj (88%) rename src/main/clj/dda/{k8s_keycloak => c4k_keycloak}/uberjar.clj (96%) rename src/main/clj/dda/{k8s_keycloak => c4k_keycloak}/yaml.clj (95%) rename src/main/cljc/dda/{k8s_keycloak => c4k_keycloak}/common.cljc (97%) rename src/main/cljc/dda/{k8s_keycloak => c4k_keycloak}/core.cljc (89%) rename src/main/cljc/dda/{k8s_keycloak => c4k_keycloak}/keycloak.cljc (91%) rename src/main/cljc/dda/{k8s_keycloak => c4k_keycloak}/postgres.cljc (84%) create mode 100644 src/main/cljs/dda/c4k_keycloak/base64.cljs rename src/main/cljs/dda/{k8s_keycloak => c4k_keycloak}/browser.cljs (97%) create mode 100644 src/main/cljs/dda/c4k_keycloak/yaml.cljs delete mode 100644 src/main/cljs/dda/k8s_keycloak/base64.cljs delete mode 100644 src/main/cljs/dda/k8s_keycloak/yaml.cljs rename src/test/cljc/dda/{k8s_keycloak => c4k_keycloak}/keycloak_test.cljc (98%) rename src/test/cljc/dda/{k8s_keycloak => c4k_keycloak}/postgres_test.cljc (96%) rename src/test/cljc/dda/{k8s_keycloak => c4k_keycloak}/yaml_test.cljc (95%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 935745e..7c105ca 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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: diff --git a/package.json b/package.json index f77976b..d62430d 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/project.clj b/project.clj index ab8f102..d04ec48 100644 --- a/project.clj +++ b/project.clj @@ -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" diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 6769ec9..30cd941 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -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 diff --git a/src/main/clj/dda/k8s_keycloak/base64.clj b/src/main/clj/dda/c4k_keycloak/base64.clj similarity index 88% rename from src/main/clj/dda/k8s_keycloak/base64.clj rename to src/main/clj/dda/c4k_keycloak/base64.clj index 84f8a08..4f9bb50 100644 --- a/src/main/clj/dda/k8s_keycloak/base64.clj +++ b/src/main/clj/dda/c4k_keycloak/base64.clj @@ -1,4 +1,4 @@ -(ns dda.k8s-keycloak.base64 +(ns dda.c4k-keycloak.base64 (:import (java.util Base64))) (defn encode diff --git a/src/main/clj/dda/k8s_keycloak/uberjar.clj b/src/main/clj/dda/c4k_keycloak/uberjar.clj similarity index 96% rename from src/main/clj/dda/k8s_keycloak/uberjar.clj rename to src/main/clj/dda/c4k_keycloak/uberjar.clj index 5e33ad0..6cd37b3 100644 --- a/src/main/clj/dda/k8s_keycloak/uberjar.clj +++ b/src/main/clj/dda/c4k_keycloak/uberjar.clj @@ -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: diff --git a/src/main/clj/dda/k8s_keycloak/yaml.clj b/src/main/clj/dda/c4k_keycloak/yaml.clj similarity index 95% rename from src/main/clj/dda/k8s_keycloak/yaml.clj rename to src/main/clj/dda/c4k_keycloak/yaml.clj index 15a879e..c05db95 100644 --- a/src/main/clj/dda/k8s_keycloak/yaml.clj +++ b/src/main/clj/dda/c4k_keycloak/yaml.clj @@ -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] diff --git a/src/main/cljc/dda/k8s_keycloak/common.cljc b/src/main/cljc/dda/c4k_keycloak/common.cljc similarity index 97% rename from src/main/cljc/dda/k8s_keycloak/common.cljc rename to src/main/cljc/dda/c4k_keycloak/common.cljc index 0d36b97..6048fcb 100644 --- a/src/main/cljc/dda/k8s_keycloak/common.cljc +++ b/src/main/cljc/dda/c4k_keycloak/common.cljc @@ -1,4 +1,4 @@ -(ns dda.k8s-keycloak.common +(ns dda.c4k-keycloak.common (:require [clojure.walk])) diff --git a/src/main/cljc/dda/k8s_keycloak/core.cljc b/src/main/cljc/dda/c4k_keycloak/core.cljc similarity index 89% rename from src/main/cljc/dda/k8s_keycloak/core.cljc rename to src/main/cljc/dda/c4k_keycloak/core.cljc index 352e0ed..ad8ffdc 100644 --- a/src/main/cljc/dda/k8s_keycloak/core.cljc +++ b/src/main/cljc/dda/c4k_keycloak/core.cljc @@ -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])) diff --git a/src/main/cljc/dda/k8s_keycloak/keycloak.cljc b/src/main/cljc/dda/c4k_keycloak/keycloak.cljc similarity index 91% rename from src/main/cljc/dda/k8s_keycloak/keycloak.cljc rename to src/main/cljc/dda/c4k_keycloak/keycloak.cljc index 62be864..02dccb0 100644 --- a/src/main/cljc/dda/k8s_keycloak/keycloak.cljc +++ b/src/main/cljc/dda/c4k_keycloak/keycloak.cljc @@ -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?) diff --git a/src/main/cljc/dda/k8s_keycloak/postgres.cljc b/src/main/cljc/dda/c4k_keycloak/postgres.cljc similarity index 84% rename from src/main/cljc/dda/k8s_keycloak/postgres.cljc rename to src/main/cljc/dda/c4k_keycloak/postgres.cljc index 152cd4e..b3846ea 100644 --- a/src/main/cljc/dda/k8s_keycloak/postgres.cljc +++ b/src/main/cljc/dda/c4k_keycloak/postgres.cljc @@ -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?) diff --git a/src/main/cljs/dda/c4k_keycloak/base64.cljs b/src/main/cljs/dda/c4k_keycloak/base64.cljs new file mode 100644 index 0000000..8c1caa0 --- /dev/null +++ b/src/main/cljs/dda/c4k_keycloak/base64.cljs @@ -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)) diff --git a/src/main/cljs/dda/k8s_keycloak/browser.cljs b/src/main/cljs/dda/c4k_keycloak/browser.cljs similarity index 97% rename from src/main/cljs/dda/k8s_keycloak/browser.cljs rename to src/main/cljs/dda/c4k_keycloak/browser.cljs index 665633e..c03c48c 100644 --- a/src/main/cljs/dda/k8s_keycloak/browser.cljs +++ b/src/main/cljs/dda/c4k_keycloak/browser.cljs @@ -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) diff --git a/src/main/cljs/dda/c4k_keycloak/yaml.cljs b/src/main/cljs/dda/c4k_keycloak/yaml.cljs new file mode 100644 index 0000000..a6f68d4 --- /dev/null +++ b/src/main/cljs/dda/c4k_keycloak/yaml.cljs @@ -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))) \ No newline at end of file diff --git a/src/main/cljs/dda/k8s_keycloak/base64.cljs b/src/main/cljs/dda/k8s_keycloak/base64.cljs deleted file mode 100644 index b05b234..0000000 --- a/src/main/cljs/dda/k8s_keycloak/base64.cljs +++ /dev/null @@ -1,9 +0,0 @@ -(ns dda.k8s-keycloak.base64) - -(defn encode - [string] - (.btoa js/window string)) - -(defn decode - [string] - (.atob js/window string)) diff --git a/src/main/cljs/dda/k8s_keycloak/yaml.cljs b/src/main/cljs/dda/k8s_keycloak/yaml.cljs deleted file mode 100644 index 119c64a..0000000 --- a/src/main/cljs/dda/k8s_keycloak/yaml.cljs +++ /dev/null @@ -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))) \ No newline at end of file diff --git a/src/test/cljc/dda/k8s_keycloak/keycloak_test.cljc b/src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc similarity index 98% rename from src/test/cljc/dda/k8s_keycloak/keycloak_test.cljc rename to src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc index 72f0b80..88a0cd8 100644 --- a/src/test/cljc/dda/k8s_keycloak/keycloak_test.cljc +++ b/src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc @@ -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" diff --git a/src/test/cljc/dda/k8s_keycloak/postgres_test.cljc b/src/test/cljc/dda/c4k_keycloak/postgres_test.cljc similarity index 96% rename from src/test/cljc/dda/k8s_keycloak/postgres_test.cljc rename to src/test/cljc/dda/c4k_keycloak/postgres_test.cljc index 9b3d0fd..8344771 100644 --- a/src/test/cljc/dda/k8s_keycloak/postgres_test.cljc +++ b/src/test/cljc/dda/c4k_keycloak/postgres_test.cljc @@ -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" diff --git a/src/test/cljc/dda/k8s_keycloak/yaml_test.cljc b/src/test/cljc/dda/c4k_keycloak/yaml_test.cljc similarity index 95% rename from src/test/cljc/dda/k8s_keycloak/yaml_test.cljc rename to src/test/cljc/dda/c4k_keycloak/yaml_test.cljc index 838b5a5..cb31273 100644 --- a/src/test/cljc/dda/k8s_keycloak/yaml_test.cljc +++ b/src/test/cljc/dda/c4k_keycloak/yaml_test.cljc @@ -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"}