]> git.immae.eu Git - github/fretlink/ansible-kong-app.git/commitdiff
add dhall interface 7/head
authorHussein Ait-Lahcen <hussein.ait-lahcen@fretlink.com>
Mon, 19 Nov 2018 14:51:21 +0000 (15:51 +0100)
committerHussein Ait-Lahcen <hussein.ait-lahcen@fretlink.com>
Tue, 20 Nov 2018 16:29:11 +0000 (17:29 +0100)
20 files changed:
.travis.yml
dhall-1.18.0.nix [new file with mode: 0644]
dhall/Config.dhall [new file with mode: 0644]
dhall/Vault.dhall [new file with mode: 0644]
dhall/functions.dhall [new file with mode: 0644]
dhall/server/Server.dhall [new file with mode: 0644]
dhall/server/functions.dhall [new file with mode: 0644]
dhall/server/mkServer.dhall [new file with mode: 0644]
dhall/server/service/Service.dhall [new file with mode: 0644]
dhall/server/service/functions.dhall [new file with mode: 0644]
dhall/server/service/plugin/Config.dhall [new file with mode: 0644]
dhall/server/service/plugin/CorrelationId.dhall [new file with mode: 0644]
dhall/server/service/plugin/Plugin.dhall [new file with mode: 0644]
dhall/server/service/plugin/functions.dhall [new file with mode: 0644]
dhall/server/service/plugin/mkIPRestriction.dhall [new file with mode: 0644]
dhall/server/service/plugin/mkRequestTermination.dhall [new file with mode: 0644]
dhall/server/service/plugin/mkRequestTransformer.dhall [new file with mode: 0644]
dhall/server/service/route/Route.dhall [new file with mode: 0644]
dhall/types.dhall [new file with mode: 0644]
scripts/dhall_check.sh [new file with mode: 0755]

index de15287e6a4605c6300ea3454e258e91dd56b8d8..f18b9b37a952e4b5a3bdfb2387260174ef97c309 100644 (file)
@@ -7,6 +7,7 @@ sudo: false
 install:
   # Install ansible
   - nix-env -i python2.7-ansible python2.7-ansible-lint
+  - nix-env -if ./dhall-1.18.0.nix
 
   # Check ansible version
   - ansible --version
@@ -19,6 +20,7 @@ script:
   - ansible-playbook tests/test.yml -i tests/inventory --syntax-check
   - ansible-lint .
   - ansible-playbook tests/test.yml -i tests/inventory -C -D
+  - scripts/dhall_check.sh
 
 notifications:
   webhooks: https://galaxy.ansible.com/api/v1/notifications/
diff --git a/dhall-1.18.0.nix b/dhall-1.18.0.nix
new file mode 100644 (file)
index 0000000..d6522bd
--- /dev/null
@@ -0,0 +1,16 @@
+{ pkgs ? import <nixpkgs> {} }: with pkgs;
+
+stdenv.mkDerivation rec {
+  name = "dhall-${version}";
+  version = "1.18.0";
+  phases = [ "installPhase "];
+  src = fetchurl {
+    url = "https://github.com/dhall-lang/dhall-haskell/releases/download/${version}/dhall-${version}-x86_64-linux.tar.bz2";
+    sha256 = "0jvw6ss96xifb21mzpvfjzvaffcnpj0jhpc4rd36cl2r22800qgx";
+  };
+  installPhase = ''
+    mkdir -p $out/bin
+    tar -xjf $src
+    mv bin/dhall $out/bin/
+  '';
+}
diff --git a/dhall/Config.dhall b/dhall/Config.dhall
new file mode 100644 (file)
index 0000000..f1a28fc
--- /dev/null
@@ -0,0 +1 @@
+let Server = ./server/Server.dhall in { kong_servers : List Server }
diff --git a/dhall/Vault.dhall b/dhall/Vault.dhall
new file mode 100644 (file)
index 0000000..56cd0e5
--- /dev/null
@@ -0,0 +1 @@
+{ appAdminApiKey : Text, accessKey : Text }
diff --git a/dhall/functions.dhall b/dhall/functions.dhall
new file mode 100644 (file)
index 0000000..6465760
--- /dev/null
@@ -0,0 +1 @@
+{ Server = ./server/functions.dhall }
diff --git a/dhall/server/Server.dhall b/dhall/server/Server.dhall
new file mode 100644 (file)
index 0000000..beddd7d
--- /dev/null
@@ -0,0 +1,9 @@
+    let Service = ./service/Service.dhall
+
+in  { kong_app_admin_url :
+        Text
+    , kong_app_admin_apikey :
+        Text
+    , services :
+        List Service
+    }
diff --git a/dhall/server/functions.dhall b/dhall/server/functions.dhall
new file mode 100644 (file)
index 0000000..2775fb9
--- /dev/null
@@ -0,0 +1 @@
+{ Service = ./service/functions.dhall, mkServer = ./mkServer.dhall }
diff --git a/dhall/server/mkServer.dhall b/dhall/server/mkServer.dhall
new file mode 100644 (file)
index 0000000..f02055b
--- /dev/null
@@ -0,0 +1,17 @@
+    let Server = ./Server.dhall
+
+in  let Service = ./service/Service.dhall
+
+in  let Vault = ./../Vault.dhall
+
+in    λ(vault : Vault)
+    → λ(adminUrl : Text)
+    → λ(services : List Service)
+    →   { kong_app_admin_url =
+            adminUrl
+        , kong_app_admin_apikey =
+            vault.appAdminApiKey
+        , services =
+            services
+        }
+      : Server
diff --git a/dhall/server/service/Service.dhall b/dhall/server/service/Service.dhall
new file mode 100644 (file)
index 0000000..f238553
--- /dev/null
@@ -0,0 +1,5 @@
+    let Plugin = ./plugin/Plugin.dhall
+
+in  let Route = ./route/Route.dhall
+
+in  { name : Text, url : Text, plugins : List Plugin, routes : List Route }
diff --git a/dhall/server/service/functions.dhall b/dhall/server/service/functions.dhall
new file mode 100644 (file)
index 0000000..08f25c0
--- /dev/null
@@ -0,0 +1 @@
+{ Plugin = ./plugin/functions.dhall }
diff --git a/dhall/server/service/plugin/Config.dhall b/dhall/server/service/plugin/Config.dhall
new file mode 100644 (file)
index 0000000..73a333f
--- /dev/null
@@ -0,0 +1,9 @@
+< CorrelationId :
+    { header_name : Text, echo_downstream : Bool }
+| RequestTransformer :
+    { `add.headers` : Text }
+| RequestTermination :
+    { status_code : Natural, content_type : Text, body : Text }
+| IPRestriction :
+    { whitelist : Text }
+>
diff --git a/dhall/server/service/plugin/CorrelationId.dhall b/dhall/server/service/plugin/CorrelationId.dhall
new file mode 100644 (file)
index 0000000..d96bfc9
--- /dev/null
@@ -0,0 +1,11 @@
+    let Plugin = ./Plugin.dhall
+
+in  let config = constructors ./Config.dhall
+
+in    { name =
+          "correlation-id"
+      , config =
+          config.CorrelationId
+          { header_name = "X-correl", echo_downstream = True }
+      }
+    : Plugin
diff --git a/dhall/server/service/plugin/Plugin.dhall b/dhall/server/service/plugin/Plugin.dhall
new file mode 100644 (file)
index 0000000..548061c
--- /dev/null
@@ -0,0 +1 @@
+let Config = ./Config.dhall in { name : Text, config : Config }
diff --git a/dhall/server/service/plugin/functions.dhall b/dhall/server/service/plugin/functions.dhall
new file mode 100644 (file)
index 0000000..dcf2c9a
--- /dev/null
@@ -0,0 +1,9 @@
+{ mkRequestTermination =
+    ./mkRequestTermination.dhall
+, mkRequestTransformer =
+    ./mkRequestTransformer.dhall
+, mkIPRestriction =
+    ./mkIPRestriction.dhall
+, CorrelationId =
+    ./CorrelationId.dhall
+}
diff --git a/dhall/server/service/plugin/mkIPRestriction.dhall b/dhall/server/service/plugin/mkIPRestriction.dhall
new file mode 100644 (file)
index 0000000..f803769
--- /dev/null
@@ -0,0 +1,11 @@
+    let Plugin = ./Plugin.dhall
+
+in  let config = constructors ./Config.dhall
+
+in    λ(whiteList : Text)
+    →   { name =
+            "ip-restriction"
+        , config =
+            config.IPRestriction { whitelist = whiteList }
+        }
+      : Plugin
diff --git a/dhall/server/service/plugin/mkRequestTermination.dhall b/dhall/server/service/plugin/mkRequestTermination.dhall
new file mode 100644 (file)
index 0000000..aff538f
--- /dev/null
@@ -0,0 +1,20 @@
+    let Plugin = ./Plugin.dhall
+
+in  let config = constructors ./Config.dhall
+
+in    λ(statusCode : Natural)
+    → λ(contentType : Text)
+    → λ(body : Text)
+    →   { name =
+            "request-termination"
+        , config =
+            config.RequestTermination
+            { status_code =
+                statusCode
+            , content_type =
+                contentType
+            , body =
+                body
+            }
+        }
+      : Plugin
diff --git a/dhall/server/service/plugin/mkRequestTransformer.dhall b/dhall/server/service/plugin/mkRequestTransformer.dhall
new file mode 100644 (file)
index 0000000..90789c8
--- /dev/null
@@ -0,0 +1,11 @@
+    let Plugin = ./Plugin.dhall
+
+in  let config = constructors ./Config.dhall
+
+in    λ(header : Text)
+    →   { name =
+            "request-transformer"
+        , config =
+            config.RequestTransformer { `add.headers` = header }
+        }
+      : Plugin
diff --git a/dhall/server/service/route/Route.dhall b/dhall/server/service/route/Route.dhall
new file mode 100644 (file)
index 0000000..c0fa1a9
--- /dev/null
@@ -0,0 +1 @@
+{ paths : List Text, protocols : List Text, hosts : List Text }
diff --git a/dhall/types.dhall b/dhall/types.dhall
new file mode 100644 (file)
index 0000000..938dc74
--- /dev/null
@@ -0,0 +1,13 @@
+{ Vault =
+    ./Vault.dhall
+, Config =
+    ./Config.dhall
+, Server =
+    ./server/Server.dhall
+, Service =
+    ./server/service/Service.dhall
+, Plugin =
+    ./server/service/plugin/Plugin.dhall
+, Route =
+    ./server/service/route/Route.dhall
+}
diff --git a/scripts/dhall_check.sh b/scripts/dhall_check.sh
new file mode 100755 (executable)
index 0000000..6fc7fd1
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+pushd () {
+  command pushd "$@" > /dev/null
+}
+
+popd () {
+  command popd "$@" > /dev/null
+}
+
+go() {
+  local ERROR=0;
+  for file in $(find -type f -name "*.dhall"); do
+    pushd $(dirname $file);
+    cat $(basename $file) | dhall --explain resolve > /dev/null;
+    echo "Type checking ${file}"
+    if [ "$?" -ne "0" ]; then
+      echo "Failed to resolve $file"
+      ERROR=1;
+    fi;
+    popd;
+  done;
+  exit $ERROR;
+}
+
+go