From 80320193527d24c33ce67da99521a4cdd6631edc Mon Sep 17 00:00:00 2001 From: Hussein Ait-Lahcen Date: Wed, 24 Apr 2019 15:28:10 +0200 Subject: add(dhall): introduce pre-function plugin --- dhall/server/service/plugin/Config.dhall | 11 +++++------ dhall/server/service/plugin/functions.dhall | 6 ++++++ dhall/server/service/plugin/mkPreFunction.dhall | 9 +++++++++ dhall/server/service/plugin/package.dhall | 7 +------ 4 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 dhall/server/service/plugin/functions.dhall create mode 100644 dhall/server/service/plugin/mkPreFunction.dhall (limited to '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 @@ < 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 } > diff --git a/dhall/server/service/plugin/functions.dhall b/dhall/server/service/plugin/functions.dhall new file mode 100644 index 0000000..a7b1295 --- /dev/null +++ b/dhall/server/service/plugin/functions.dhall @@ -0,0 +1,6 @@ +{ mkRequestTermination = ./mkRequestTermination.dhall +, mkRequestTransformer = ./mkRequestTransformer.dhall +, mkIPRestriction = ./mkIPRestriction.dhall +, correlationId = ./correlationId.dhall +, mkPreFunction = ./mkPreFunction.dhall +} 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 @@ +let Plugin = ./Plugin.dhall + +let config = ./Config.dhall + +in λ(functions : List Text) + → { name = "pre-function" + , config = config.PreFunction { functions = functions } + } + : 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 @@ -{ Type = ./Plugin.dhall -, mkRequestTermination = ./mkRequestTermination.dhall -, mkRequestTransformer = ./mkRequestTransformer.dhall -, mkIPRestriction = ./mkIPRestriction.dhall -, correlationId = ./correlationId.dhall -} +{ Type = ./Plugin.dhall, functions = ./functions.dhall } -- cgit v1.2.3 From 5f23d5909f18ecc5d0af12cdbb1aee44dccf89ca Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Thu, 2 Jan 2020 13:44:05 +0100 Subject: config(dhall): add a pre-function lua definition for HTTPS redirects This PR fixes #12 and takes precedence over #13 (cherry-picked one of #13's commit) --- dhall/functions.dhall | 1 - dhall/server/service/plugin/functions.dhall | 1 + dhall/server/service/plugin/http2httpsRedirect.dhall | 15 +++++++++++++++ dhall/types.dhall | 13 ------------- 4 files changed, 16 insertions(+), 14 deletions(-) delete mode 100644 dhall/functions.dhall create mode 100644 dhall/server/service/plugin/http2httpsRedirect.dhall delete mode 100644 dhall/types.dhall (limited to 'dhall') 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 @@ -{ Server = ./server/functions.dhall } diff --git a/dhall/server/service/plugin/functions.dhall b/dhall/server/service/plugin/functions.dhall index a7b1295..098fba7 100644 --- a/dhall/server/service/plugin/functions.dhall +++ b/dhall/server/service/plugin/functions.dhall @@ -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 index 0000000..faa6d79 --- /dev/null +++ b/dhall/server/service/plugin/http2httpsRedirect.dhall @@ -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 index 938dc74..0000000 --- a/dhall/types.dhall +++ /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 -} -- cgit v1.2.3