]> git.immae.eu Git - github/fretlink/ansible-kong-app.git/commitdiff
config(dhall): add a pre-function lua definition for HTTPS redirects
authorPaul Bonaud <paul.bonaud@fretlink.com>
Thu, 2 Jan 2020 12:44:05 +0000 (13:44 +0100)
committerPaul Bonaud <paul.bonaud@fretlink.com>
Thu, 2 Jan 2020 14:41:41 +0000 (15:41 +0100)
This PR fixes #12 and takes precedence over #13 (cherry-picked one of
 #13's commit)

dhall/functions.dhall [deleted file]
dhall/server/service/plugin/functions.dhall
dhall/server/service/plugin/http2httpsRedirect.dhall [new file with mode: 0644]
dhall/types.dhall [deleted file]

diff --git a/dhall/functions.dhall b/dhall/functions.dhall
deleted file mode 100644 (file)
index 6465760..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{ Server = ./server/functions.dhall }
index a7b1295ff52492b5a4d271af6631ec2da23e7439..098fba736a73af94a0e2c5af3d3d98501e403f15 100644 (file)
@@ -3,4 +3,5 @@
 , mkIPRestriction = ./mkIPRestriction.dhall
 , correlationId = ./correlationId.dhall
 , mkPreFunction = ./mkPreFunction.dhall
+, http2httpsRedirect = ./http2httpsRedirect.dhall
 }
diff --git a/dhall/server/service/plugin/http2httpsRedirect.dhall b/dhall/server/service/plugin/http2httpsRedirect.dhall
new file mode 100644 (file)
index 0000000..faa6d79
--- /dev/null
@@ -0,0 +1,15 @@
+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 ]
diff --git a/dhall/types.dhall b/dhall/types.dhall
deleted file mode 100644 (file)
index 938dc74..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-{ 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
-}