---
language: nix
+nix: 2.3.1
+
# Use the new container infrastructure
sudo: false
install:
+ # Update nix channels
+ - nix-channel --add https://nixos.org/channels/nixpkgs-19.09-darwin nixpkgs
+ - nix-channel --remove nixpkgs-unstable
+ - nix-channel --update
+
# Install ansible
- - nix-env -i python2.7-ansible python2.7-ansible-lint
+ - nix-env -i python3 ansible ansible-lint
- nix-env -if ./dhall-1.26.1.nix
# Check ansible version
- ansible --version
+ - ansible-lint --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
+ # Basic webserver to fake a Kong
+ - |
+ ./tests/kong.py&
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
- ansible-lint .
- - ansible-playbook tests/test.yml -i tests/inventory -C -D
+ - ansible-playbook tests/test.yml -i tests/inventory -D
- scripts/dhall_check.sh
notifications:
+++ /dev/null
-{ Server = ./server/functions.dhall }
< CorrelationId :
- { header_name : Text, echo_downstream : Bool, generator : Text }
-| RequestTransformer :
- { add : { headers : List Text } }
+ { header_name : Text, echo_downstream : Bool, generator : Text }
+| RequestTransformer : { add : { headers : List Text } }
| RequestTermination :
- { status_code : Natural, content_type : Text, body : Text }
-| IPRestriction :
- { whitelist : Text }
+ { status_code : Natural, content_type : Text, body : Text }
+| IPRestriction : { whitelist : Text }
+| PreFunction : { functions : List Text }
>
--- /dev/null
+{ mkRequestTermination = ./mkRequestTermination.dhall
+, mkRequestTransformer = ./mkRequestTransformer.dhall
+, mkIPRestriction = ./mkIPRestriction.dhall
+, correlationId = ./correlationId.dhall
+, mkPreFunction = ./mkPreFunction.dhall
+, http2httpsRedirect = ./http2httpsRedirect.dhall
+}
--- /dev/null
+let mkPreFunction = ./mkPreFunction.dhall
+
+let luaRedirect =
+ ''
+ local scheme = kong.request.get_scheme()
+ if scheme == "http" then
+ local host = kong.request.get_host()
+ local query = kong.request.get_path_with_query()
+ local url = "https://" .. host ..query
+ kong.response.set_header("Location", url)
+ return kong.response.exit(301, url)
+ end
+ ''
+
+in mkPreFunction [ luaRedirect ]
--- /dev/null
+let Plugin = ./Plugin.dhall
+
+let config = ./Config.dhall
+
+in λ(functions : List Text)
+ → { name = "pre-function"
+ , config = config.PreFunction { functions = functions }
+ }
+ : Plugin
-{ Type = ./Plugin.dhall
-, mkRequestTermination = ./mkRequestTermination.dhall
-, mkRequestTransformer = ./mkRequestTransformer.dhall
-, mkIPRestriction = ./mkIPRestriction.dhall
-, correlationId = ./correlationId.dhall
-}
+{ Type = ./Plugin.dhall, functions = ./functions.dhall }
+++ /dev/null
-{ 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
-}
--- /dev/null
+#!/usr/bin/env python
+
+from http.server import HTTPServer, CGIHTTPRequestHandler
+
+class SimpleHTTPRequestHandler(CGIHTTPRequestHandler):
+ def do_GET(self):
+ if self.path == '/services/test':
+ self.send_response(404)
+ else:
+ self.send_response(200)
+ self.send_header('Content-Type', 'application/json')
+ self.end_headers()
+ self.wfile.write(b'{ "data": [] }')
+
+ def do_POST(self):
+ self.send_response(200)
+ self.end_headers()
+ self.wfile.write(b'Hello, world!')
+
+
+httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler)
+httpd.serve_forever()
remote_user: root
roles:
- role: ansible-kong-app
- kong_servers:
- - kong_app_admin_url: http://127.0.0.1:8000
- kong_app_admin_apikey: ""
- services:
- - url: http://example.com
- name: test
+ vars:
+ kong_servers:
+ - kong_app_admin_url: http://127.0.0.1:8000
+ kong_app_admin_apikey: ""
+ services:
+ - url: http://example.com
+ name: test