aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorpaulrbr-fl <43074087+paulrbr-fl@users.noreply.github.com>2020-01-02 16:25:37 +0100
committerGitHub <noreply@github.com>2020-01-02 16:25:37 +0100
commit25250c8c24a3c0b32c92eee5552ad7156115f03c (patch)
tree02c178a19be0e233813600531c85ef7ad5e4c51c
parent027a2fa61a6044b2e967b29195312e4d98a96078 (diff)
parenta3c4b3d5444e5d79afbd823a9acc12220a91f41f (diff)
downloadansible-kong-app-25250c8c24a3c0b32c92eee5552ad7156115f03c.tar.gz
ansible-kong-app-25250c8c24a3c0b32c92eee5552ad7156115f03c.tar.zst
ansible-kong-app-25250c8c24a3c0b32c92eee5552ad7156115f03c.zip
Merge pull request #18 from paulrbr-fl/pre-function-pluginsv0.30
config(dhall): add a pre-function lua definition for HTTPS redirects
-rw-r--r--.travis.yml15
-rw-r--r--dhall/functions.dhall1
-rw-r--r--dhall/server/service/plugin/Config.dhall11
-rw-r--r--dhall/server/service/plugin/functions.dhall7
-rw-r--r--dhall/server/service/plugin/http2httpsRedirect.dhall15
-rw-r--r--dhall/server/service/plugin/mkPreFunction.dhall9
-rw-r--r--dhall/server/service/plugin/package.dhall7
-rw-r--r--dhall/types.dhall13
-rwxr-xr-xtests/kong.py22
-rw-r--r--tests/test.yml13
10 files changed, 79 insertions, 34 deletions
diff --git a/.travis.yml b/.travis.yml
index 7bf8ed8..14ab868 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,25 +1,36 @@
1--- 1---
2language: nix 2language: nix
3nix: 2.3.1
4
3 5
4# Use the new container infrastructure 6# Use the new container infrastructure
5sudo: false 7sudo: false
6 8
7install: 9install:
10 # Update nix channels
11 - nix-channel --add https://nixos.org/channels/nixpkgs-19.09-darwin nixpkgs
12 - nix-channel --remove nixpkgs-unstable
13 - nix-channel --update
14
8 # Install ansible 15 # Install ansible
9 - nix-env -i python2.7-ansible python2.7-ansible-lint 16 - nix-env -i python3 ansible ansible-lint
10 - nix-env -if ./dhall-1.26.1.nix 17 - nix-env -if ./dhall-1.26.1.nix
11 18
12 # Check ansible version 19 # Check ansible version
13 - ansible --version 20 - ansible --version
21 - ansible-lint --version
14 22
15 # Create ansible.cfg with correct roles_path 23 # Create ansible.cfg with correct roles_path
16 - printf '[defaults]\nroles_path=../' >ansible.cfg 24 - printf '[defaults]\nroles_path=../' >ansible.cfg
25 # Basic webserver to fake a Kong
26 - |
27 ./tests/kong.py&
17 28
18script: 29script:
19 # Basic role syntax check 30 # Basic role syntax check
20 - ansible-playbook tests/test.yml -i tests/inventory --syntax-check 31 - ansible-playbook tests/test.yml -i tests/inventory --syntax-check
21 - ansible-lint . 32 - ansible-lint .
22 - ansible-playbook tests/test.yml -i tests/inventory -C -D 33 - ansible-playbook tests/test.yml -i tests/inventory -D
23 - scripts/dhall_check.sh 34 - scripts/dhall_check.sh
24 35
25notifications: 36notifications:
diff --git a/dhall/functions.dhall b/dhall/functions.dhall
deleted file mode 100644
index 6465760..0000000
--- a/dhall/functions.dhall
+++ /dev/null
@@ -1 +0,0 @@
1{ Server = ./server/functions.dhall }
diff --git a/dhall/server/service/plugin/Config.dhall b/dhall/server/service/plugin/Config.dhall
index ea53361..1f60080 100644
--- a/dhall/server/service/plugin/Config.dhall
+++ b/dhall/server/service/plugin/Config.dhall
@@ -1,9 +1,8 @@
1< CorrelationId : 1< CorrelationId :
2 { header_name : Text, echo_downstream : Bool, generator : Text } 2 { header_name : Text, echo_downstream : Bool, generator : Text }
3| RequestTransformer : 3| RequestTransformer : { add : { headers : List Text } }
4 { add : { headers : List Text } }
5| RequestTermination : 4| RequestTermination :
6 { status_code : Natural, content_type : Text, body : Text } 5 { status_code : Natural, content_type : Text, body : Text }
7| IPRestriction : 6| IPRestriction : { whitelist : Text }
8 { whitelist : Text } 7| PreFunction : { functions : List Text }
9> 8>
diff --git a/dhall/server/service/plugin/functions.dhall b/dhall/server/service/plugin/functions.dhall
new file mode 100644
index 0000000..098fba7
--- /dev/null
+++ b/dhall/server/service/plugin/functions.dhall
@@ -0,0 +1,7 @@
1{ mkRequestTermination = ./mkRequestTermination.dhall
2, mkRequestTransformer = ./mkRequestTransformer.dhall
3, mkIPRestriction = ./mkIPRestriction.dhall
4, correlationId = ./correlationId.dhall
5, mkPreFunction = ./mkPreFunction.dhall
6, http2httpsRedirect = ./http2httpsRedirect.dhall
7}
diff --git a/dhall/server/service/plugin/http2httpsRedirect.dhall b/dhall/server/service/plugin/http2httpsRedirect.dhall
new file mode 100644
index 0000000..faa6d79
--- /dev/null
+++ b/dhall/server/service/plugin/http2httpsRedirect.dhall
@@ -0,0 +1,15 @@
1let mkPreFunction = ./mkPreFunction.dhall
2
3let luaRedirect =
4 ''
5 local scheme = kong.request.get_scheme()
6 if scheme == "http" then
7 local host = kong.request.get_host()
8 local query = kong.request.get_path_with_query()
9 local url = "https://" .. host ..query
10 kong.response.set_header("Location", url)
11 return kong.response.exit(301, url)
12 end
13 ''
14
15in mkPreFunction [ luaRedirect ]
diff --git a/dhall/server/service/plugin/mkPreFunction.dhall b/dhall/server/service/plugin/mkPreFunction.dhall
new file mode 100644
index 0000000..ff4f734
--- /dev/null
+++ b/dhall/server/service/plugin/mkPreFunction.dhall
@@ -0,0 +1,9 @@
1let Plugin = ./Plugin.dhall
2
3let config = ./Config.dhall
4
5in λ(functions : List Text)
6 → { name = "pre-function"
7 , config = config.PreFunction { functions = functions }
8 }
9 : Plugin
diff --git a/dhall/server/service/plugin/package.dhall b/dhall/server/service/plugin/package.dhall
index 872c53b..c231bc6 100644
--- a/dhall/server/service/plugin/package.dhall
+++ b/dhall/server/service/plugin/package.dhall
@@ -1,6 +1 @@
1{ Type = ./Plugin.dhall { Type = ./Plugin.dhall, functions = ./functions.dhall }
2, mkRequestTermination = ./mkRequestTermination.dhall
3, mkRequestTransformer = ./mkRequestTransformer.dhall
4, mkIPRestriction = ./mkIPRestriction.dhall
5, correlationId = ./correlationId.dhall
6}
diff --git a/dhall/types.dhall b/dhall/types.dhall
deleted file mode 100644
index 938dc74..0000000
--- a/dhall/types.dhall
+++ /dev/null
@@ -1,13 +0,0 @@
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/tests/kong.py b/tests/kong.py
new file mode 100755
index 0000000..32bafb2
--- /dev/null
+++ b/tests/kong.py
@@ -0,0 +1,22 @@
1#!/usr/bin/env python
2
3from http.server import HTTPServer, CGIHTTPRequestHandler
4
5class SimpleHTTPRequestHandler(CGIHTTPRequestHandler):
6 def do_GET(self):
7 if self.path == '/services/test':
8 self.send_response(404)
9 else:
10 self.send_response(200)
11 self.send_header('Content-Type', 'application/json')
12 self.end_headers()
13 self.wfile.write(b'{ "data": [] }')
14
15 def do_POST(self):
16 self.send_response(200)
17 self.end_headers()
18 self.wfile.write(b'Hello, world!')
19
20
21httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
22httpd.serve_forever()
diff --git a/tests/test.yml b/tests/test.yml
index 490c967..36c81a2 100644
--- a/tests/test.yml
+++ b/tests/test.yml
@@ -3,9 +3,10 @@
3 remote_user: root 3 remote_user: root
4 roles: 4 roles:
5 - role: ansible-kong-app 5 - role: ansible-kong-app
6 kong_servers: 6 vars:
7 - kong_app_admin_url: http://127.0.0.1:8000 7 kong_servers:
8 kong_app_admin_apikey: "" 8 - kong_app_admin_url: http://127.0.0.1:8000
9 services: 9 kong_app_admin_apikey: ""
10 - url: http://example.com 10 services:
11 name: test 11 - url: http://example.com
12 name: test