aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGaëtan <36162164+gaetanfl@users.noreply.github.com>2018-11-20 20:32:43 +0100
committerGitHub <noreply@github.com>2018-11-20 20:32:43 +0100
commit66401fc939cd73628561d4832c3e219f0b44d8de (patch)
treeca5b2bc2ea4c15d91476436ca4376108f5a78d88
parent6bbc5a167fb43110a5b16746c112298f392be2b8 (diff)
parent77e27a11c31fee82c2ff30613bc832f5171fa845 (diff)
downloadansible-kong-app-66401fc939cd73628561d4832c3e219f0b44d8de.tar.gz
ansible-kong-app-66401fc939cd73628561d4832c3e219f0b44d8de.tar.zst
ansible-kong-app-66401fc939cd73628561d4832c3e219f0b44d8de.zip
Merge pull request #7 from haitlahcen/dhall-interfacev0.5
add dhall interface
-rw-r--r--.travis.yml2
-rw-r--r--dhall-1.18.0.nix16
-rw-r--r--dhall/Config.dhall1
-rw-r--r--dhall/Vault.dhall1
-rw-r--r--dhall/functions.dhall1
-rw-r--r--dhall/server/Server.dhall9
-rw-r--r--dhall/server/functions.dhall1
-rw-r--r--dhall/server/mkServer.dhall17
-rw-r--r--dhall/server/service/Service.dhall5
-rw-r--r--dhall/server/service/functions.dhall1
-rw-r--r--dhall/server/service/plugin/Config.dhall9
-rw-r--r--dhall/server/service/plugin/CorrelationId.dhall11
-rw-r--r--dhall/server/service/plugin/Plugin.dhall1
-rw-r--r--dhall/server/service/plugin/functions.dhall9
-rw-r--r--dhall/server/service/plugin/mkIPRestriction.dhall11
-rw-r--r--dhall/server/service/plugin/mkRequestTermination.dhall20
-rw-r--r--dhall/server/service/plugin/mkRequestTransformer.dhall11
-rw-r--r--dhall/server/service/route/Route.dhall1
-rw-r--r--dhall/types.dhall13
-rwxr-xr-xscripts/dhall_check.sh26
20 files changed, 166 insertions, 0 deletions
diff --git a/.travis.yml b/.travis.yml
index de15287..f18b9b3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,6 +7,7 @@ sudo: false
7install: 7install:
8 # Install ansible 8 # Install ansible
9 - nix-env -i python2.7-ansible python2.7-ansible-lint 9 - nix-env -i python2.7-ansible python2.7-ansible-lint
10 - nix-env -if ./dhall-1.18.0.nix
10 11
11 # Check ansible version 12 # Check ansible version
12 - ansible --version 13 - ansible --version
@@ -19,6 +20,7 @@ script:
19 - ansible-playbook tests/test.yml -i tests/inventory --syntax-check 20 - ansible-playbook tests/test.yml -i tests/inventory --syntax-check
20 - ansible-lint . 21 - ansible-lint .
21 - ansible-playbook tests/test.yml -i tests/inventory -C -D 22 - ansible-playbook tests/test.yml -i tests/inventory -C -D
23 - scripts/dhall_check.sh
22 24
23notifications: 25notifications:
24 webhooks: https://galaxy.ansible.com/api/v1/notifications/ 26 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
index 0000000..d6522bd
--- /dev/null
+++ b/dhall-1.18.0.nix
@@ -0,0 +1,16 @@
1{ pkgs ? import <nixpkgs> {} }: with pkgs;
2
3stdenv.mkDerivation rec {
4 name = "dhall-${version}";
5 version = "1.18.0";
6 phases = [ "installPhase "];
7 src = fetchurl {
8 url = "https://github.com/dhall-lang/dhall-haskell/releases/download/${version}/dhall-${version}-x86_64-linux.tar.bz2";
9 sha256 = "0jvw6ss96xifb21mzpvfjzvaffcnpj0jhpc4rd36cl2r22800qgx";
10 };
11 installPhase = ''
12 mkdir -p $out/bin
13 tar -xjf $src
14 mv bin/dhall $out/bin/
15 '';
16}
diff --git a/dhall/Config.dhall b/dhall/Config.dhall
new file mode 100644
index 0000000..f1a28fc
--- /dev/null
+++ b/dhall/Config.dhall
@@ -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
index 0000000..56cd0e5
--- /dev/null
+++ b/dhall/Vault.dhall
@@ -0,0 +1 @@
{ appAdminApiKey : Text, accessKey : Text }
diff --git a/dhall/functions.dhall b/dhall/functions.dhall
new file mode 100644
index 0000000..6465760
--- /dev/null
+++ b/dhall/functions.dhall
@@ -0,0 +1 @@
{ Server = ./server/functions.dhall }
diff --git a/dhall/server/Server.dhall b/dhall/server/Server.dhall
new file mode 100644
index 0000000..beddd7d
--- /dev/null
+++ b/dhall/server/Server.dhall
@@ -0,0 +1,9 @@
1 let Service = ./service/Service.dhall
2
3in { kong_app_admin_url :
4 Text
5 , kong_app_admin_apikey :
6 Text
7 , services :
8 List Service
9 }
diff --git a/dhall/server/functions.dhall b/dhall/server/functions.dhall
new file mode 100644
index 0000000..2775fb9
--- /dev/null
+++ b/dhall/server/functions.dhall
@@ -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
index 0000000..f02055b
--- /dev/null
+++ b/dhall/server/mkServer.dhall
@@ -0,0 +1,17 @@
1 let Server = ./Server.dhall
2
3in let Service = ./service/Service.dhall
4
5in let Vault = ./../Vault.dhall
6
7in λ(vault : Vault)
8 → λ(adminUrl : Text)
9 → λ(services : List Service)
10 → { kong_app_admin_url =
11 adminUrl
12 , kong_app_admin_apikey =
13 vault.appAdminApiKey
14 , services =
15 services
16 }
17 : Server
diff --git a/dhall/server/service/Service.dhall b/dhall/server/service/Service.dhall
new file mode 100644
index 0000000..f238553
--- /dev/null
+++ b/dhall/server/service/Service.dhall
@@ -0,0 +1,5 @@
1 let Plugin = ./plugin/Plugin.dhall
2
3in let Route = ./route/Route.dhall
4
5in { 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
index 0000000..08f25c0
--- /dev/null
+++ b/dhall/server/service/functions.dhall
@@ -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
index 0000000..73a333f
--- /dev/null
+++ b/dhall/server/service/plugin/Config.dhall
@@ -0,0 +1,9 @@
1< CorrelationId :
2 { header_name : Text, echo_downstream : Bool }
3| RequestTransformer :
4 { `add.headers` : Text }
5| RequestTermination :
6 { status_code : Natural, content_type : Text, body : Text }
7| IPRestriction :
8 { whitelist : Text }
9>
diff --git a/dhall/server/service/plugin/CorrelationId.dhall b/dhall/server/service/plugin/CorrelationId.dhall
new file mode 100644
index 0000000..d96bfc9
--- /dev/null
+++ b/dhall/server/service/plugin/CorrelationId.dhall
@@ -0,0 +1,11 @@
1 let Plugin = ./Plugin.dhall
2
3in let config = constructors ./Config.dhall
4
5in { name =
6 "correlation-id"
7 , config =
8 config.CorrelationId
9 { header_name = "X-correl", echo_downstream = True }
10 }
11 : Plugin
diff --git a/dhall/server/service/plugin/Plugin.dhall b/dhall/server/service/plugin/Plugin.dhall
new file mode 100644
index 0000000..548061c
--- /dev/null
+++ b/dhall/server/service/plugin/Plugin.dhall
@@ -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
index 0000000..dcf2c9a
--- /dev/null
+++ b/dhall/server/service/plugin/functions.dhall
@@ -0,0 +1,9 @@
1{ mkRequestTermination =
2 ./mkRequestTermination.dhall
3, mkRequestTransformer =
4 ./mkRequestTransformer.dhall
5, mkIPRestriction =
6 ./mkIPRestriction.dhall
7, CorrelationId =
8 ./CorrelationId.dhall
9}
diff --git a/dhall/server/service/plugin/mkIPRestriction.dhall b/dhall/server/service/plugin/mkIPRestriction.dhall
new file mode 100644
index 0000000..f803769
--- /dev/null
+++ b/dhall/server/service/plugin/mkIPRestriction.dhall
@@ -0,0 +1,11 @@
1 let Plugin = ./Plugin.dhall
2
3in let config = constructors ./Config.dhall
4
5in λ(whiteList : Text)
6 → { name =
7 "ip-restriction"
8 , config =
9 config.IPRestriction { whitelist = whiteList }
10 }
11 : Plugin
diff --git a/dhall/server/service/plugin/mkRequestTermination.dhall b/dhall/server/service/plugin/mkRequestTermination.dhall
new file mode 100644
index 0000000..aff538f
--- /dev/null
+++ b/dhall/server/service/plugin/mkRequestTermination.dhall
@@ -0,0 +1,20 @@
1 let Plugin = ./Plugin.dhall
2
3in let config = constructors ./Config.dhall
4
5in λ(statusCode : Natural)
6 → λ(contentType : Text)
7 → λ(body : Text)
8 → { name =
9 "request-termination"
10 , config =
11 config.RequestTermination
12 { status_code =
13 statusCode
14 , content_type =
15 contentType
16 , body =
17 body
18 }
19 }
20 : Plugin
diff --git a/dhall/server/service/plugin/mkRequestTransformer.dhall b/dhall/server/service/plugin/mkRequestTransformer.dhall
new file mode 100644
index 0000000..90789c8
--- /dev/null
+++ b/dhall/server/service/plugin/mkRequestTransformer.dhall
@@ -0,0 +1,11 @@
1 let Plugin = ./Plugin.dhall
2
3in let config = constructors ./Config.dhall
4
5in λ(header : Text)
6 → { name =
7 "request-transformer"
8 , config =
9 config.RequestTransformer { `add.headers` = header }
10 }
11 : Plugin
diff --git a/dhall/server/service/route/Route.dhall b/dhall/server/service/route/Route.dhall
new file mode 100644
index 0000000..c0fa1a9
--- /dev/null
+++ b/dhall/server/service/route/Route.dhall
@@ -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
index 0000000..938dc74
--- /dev/null
+++ b/dhall/types.dhall
@@ -0,0 +1,13 @@
1{ Vault =
2 ./Vault.dhall
3, Config =
4 ./Config.dhall
5, Server =
6 ./server/Server.dhall
7, Service =
8 ./server/service/Service.dhall
9, Plugin =
10 ./server/service/plugin/Plugin.dhall
11, Route =
12 ./server/service/route/Route.dhall
13}
diff --git a/scripts/dhall_check.sh b/scripts/dhall_check.sh
new file mode 100755
index 0000000..6fc7fd1
--- /dev/null
+++ b/scripts/dhall_check.sh
@@ -0,0 +1,26 @@
1#!/usr/bin/env bash
2
3pushd () {
4 command pushd "$@" > /dev/null
5}
6
7popd () {
8 command popd "$@" > /dev/null
9}
10
11go() {
12 local ERROR=0;
13 for file in $(find -type f -name "*.dhall"); do
14 pushd $(dirname $file);
15 cat $(basename $file) | dhall --explain resolve > /dev/null;
16 echo "Type checking ${file}"
17 if [ "$?" -ne "0" ]; then
18 echo "Failed to resolve $file"
19 ERROR=1;
20 fi;
21 popd;
22 done;
23 exit $ERROR;
24}
25
26go