https://github.com/eyolas/kong-plugin-middleman-advanced
PLUGIN KONG: A Kong plugin that enables you to make multiple extra HTTP POST request before calling an API.
https://github.com/eyolas/kong-plugin-middleman-advanced
Last synced: about 1 year ago
JSON representation
PLUGIN KONG: A Kong plugin that enables you to make multiple extra HTTP POST request before calling an API.
- Host: GitHub
- URL: https://github.com/eyolas/kong-plugin-middleman-advanced
- Owner: eyolas
- Created: 2020-05-07T09:37:54.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-23T14:14:19.000Z (over 5 years ago)
- Last Synced: 2025-03-24T17:01:54.140Z (over 1 year ago)
- Language: Lua
- Homepage:
- Size: 43 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Kong Middleman advanced
A Kong plugin that enables an extra HTTP POST requests before proxying the original.
based on https://github.com/pantsel/kong-middleman-plugin and https://github.com/mdemou/kong-middleman
## Description
In some cases, you may need to validate a request to a separate server or service using custom logic before Kong proxies it to your API.
Middleman enables you to do that by allowing you to make an extra HTTP requests before calling an API endpoint.
## Change from the original plugin
list of change :
- Update for kong v2
- move json.lua to https://github.com/rxi/json.lua
- Update schema for v2
- add config for include certificate (default false)
- add config for include credential (default false)
- add config for include route (default false)
- add config for include consumer (default false)
- change payload :
- add certificate (resty_kong_tls.get_full_client_certificate_chain())
- add credential (kong.client.get_credential())
- add route (kong.router.get_route() and kong.router.get_service())
- add consumer (kong.client.get_consumer())
- rename uri_args to params
- rename body data to body
- no json.encode if headers["content-type"] == 'application/json'
- move body, headers and params in request field
payload :
```lua
local payload = {
['certificate'] = certificate,
['consumer'] = consumer,
['credential'] = credential,
['kong_routing'] = kong_routing,
['request'] = {
['headers'] = headers,
['params'] = params,
['body'] = json_body,
}
}
```
## Installation
WIP
## Configuration
You can add the plugin on top of an API by executing the following request on your Kong server:
```sh
$ http POST :8001/services/{api}/plugins name=middleman-advanced config:='{ "services": [{"url": "http://myserver.io/validate", "response": "table", "timeout": 10000, "keepalive": 60000}]}'
```
form parameter
default
description
name
The name of the plugin to use, in this case: middleman
config.services
required
The list of services witch the plugin make a JSON POST
### Service config
form parameter
default
description
url
required
The URL to which the plugin will make a JSON POST request before proxying the original request.
response
required
table
The type of response the middleman service is going to respond with
timeout
10000
Timeout (miliseconds) for the request to the URL specified above. Default value is 10000.
keepalive
60000
Keepalive time (miliseconds) for the request to the URL specified above. Default value is 60000.
include_cert
false
Include the original certificate in JSON POST
include_credential
false
Include the credential in JSON POST
include_consumer
false
Include the consumer in JSON POST
include_route
false
Include the route in JSON POST
Middleman will execute a JSON POST request to the specified url with the following body:
JSON POST
Attribute
Description
certificate
The certificate of the original request if include_credential
see resty_kong_tls.get_full_client_certificate_chain()
consumer
The consumer of the original request
see kong.client.get_consumer()
credential
The consumer of the original request
see kong.client.get_credential()
kong_routing
The kong_routing of the original request
see kong.router.get_route() and kong.router.get_service()
request
The request of the original request
see the next table : request
Request
Attribute
Description
body
The body of the original request
params
The url arguments of the original request
headers
The headers of the original request
In the scope of your own endpoint, you may validate any of these attributes and accept or reject the request according to your needs. If an HTTP response code of 299 or less is returned, the request is accepted. Any response code above 299 will cause the request to be rejected.
## Author
David TOUZET
## License
The MIT License (MIT)
=====================
Copyright (c) 2020 David TOUZET
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.