Skip to content

Commit

Permalink
Merge pull request #17 from yipeeio/flat_validation
Browse files Browse the repository at this point in the history
Flat validation - complete.
  • Loading branch information
markemeis authored Jan 3, 2019
2 parents cdcd6ea + 56dd7fb commit dbfcb46
Show file tree
Hide file tree
Showing 41 changed files with 2,487 additions and 166 deletions.
19 changes: 18 additions & 1 deletion api/test/convert_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,24 @@ describe('Yipee Convert API Tests:', function() {
{
"id": "56e37323-3e8b-4049-a41c-14517cfe62f8",
"name": "one",
"type": "container"
"type": "container",
"cgroup": "c0a367cc-6070-491d-90ec-b78451359604"
}
],
"container-group": [
{
"name": "cgOne",
"type": "container-group",
"containers": [
"56e37323-3e8b-4049-a41c-14517cfe62f8"
],
"source": "k8s",
"container-names": [
"one"
],
"pod": "4a981264-533a-46c6-b8a2-61837e98d70c",
"id": "c0a367cc-6070-491d-90ec-b78451359604",
"controller-type": "Deployment"
}
],
"app-info": [
Expand Down
19 changes: 18 additions & 1 deletion api/test/download_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,24 @@ describe('Yipee Download API Tests:', function() {
{
"id": "56e37323-3e8b-4049-a41c-14517cfe62f8",
"name": "one",
"type": "container"
"type": "container",
"cgroup": "c0a367cc-6070-491d-90ec-b78451359604"
}
],
"container-group": [
{
"name": "cgOne",
"type": "container-group",
"containers": [
"56e37323-3e8b-4049-a41c-14517cfe62f8"
],
"source": "k8s",
"container-names": [
"one"
],
"pod": "4a981264-533a-46c6-b8a2-61837e98d70c",
"id": "c0a367cc-6070-491d-90ec-b78451359604",
"controller-type": "Deployment"
}
],
"app-info": [
Expand Down
9 changes: 6 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash
CVT_IMG=yipee-converter
API_IMG=yipee-api
UI_IMG=yipee-ui
TAG=1.2

CVT_IMG=yipee-converter:$TAG
API_IMG=yipee-api:$TAG
UI_IMG=yipee-ui:$TAG


(cd converter; docker build -t $CVT_IMG .) || exit 1
(cd api; bash api_build.sh $CVT_IMG $API_IMG) || exit 1
Expand Down
8 changes: 5 additions & 3 deletions converter/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
[prismatic/schema "1.1.7"]
[potemkin "0.4.5"]
[com.networknt/json-schema-validator "0.1.7"]
[environ "1.1.0"]
[inflections "0.13.0"]
[arete "0.6.0"]]
[arete "0.6.1"]]

:main ^:skip-aot converter.core
:plugins [[lein-cloverage "1.0.9"]]
:plugins [[lein-cloverage "1.0.9"] [lein-environ "1.1.0"]]
:jvm-opts ["-Xmx1g" "-server"]
:target-path "target/%s"
:repositories [["buildrepo" {:url "file:buildrepo" :username "" :password ""}]]
:resource-paths ["logconfig" "resources/tools.jar"]
:profiles {:uberjar {:aot :all}
:dev {:dependencies
:dev {:env {:build-time "true"}
:dependencies
[[clj-http/clj-http "3.7.0"]]}})
26 changes: 8 additions & 18 deletions converter/src/composecvt/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[clojure.pprint :as pprint]
[k8scvt.api :as k8s]
[k8scvt.util :as util]
[k8scvt.flat-validator :as fv]
[composecvt.compose-to-flat]
[composecvt.flat-to-compose]
[composecvt.validators :as v]))
Expand All @@ -29,28 +30,17 @@
(defn wmes-of-type [srclist typ]
(filter #(= (:type %) typ) srclist))

(defn results-and-errors [wmes]
(let [results wmes
errors (wmes-of-type results :validation-error)]
(if (empty? errors)
[results true]
[errors false])))

(defn do-convert [converter valid-results]
(let [retlist (converter :run-list valid-results)]
{::retval (dissoc (first retlist) :type)}))

(defn return-errors [results]
(let [errmsgs (str/join
"\n" (map util/format-validation-error results))]
{::reterr errmsgs}))

(defn cvtc2f [composeobj]
(binding [util/*wmes-by-id* (atom {})]
(let [to-flat (engine :composecvt.compose-to-flat)
inputobj (list (assoc composeobj :type :compose))
results (to-flat :run-list inputobj)]
{::retval (group-by :type results)})))
results (to-flat :run-list inputobj)
fvalidate (engine :k8scvt.flat-validator)
[fv-results fv-ok] (k8s/results-and-errors
(fvalidate :run-list results))]
(if fv-ok
{::retval (group-by :type results)}
(k8s/return-fv-errors fv-results)))))

(defn load-and-validate-import [ctx]
(let [body (k8s/b64decode-if-possible (body-as-string ctx))
Expand Down
Loading

0 comments on commit dbfcb46

Please sign in to comment.