custom_fields_by_lua not handled properly by UI
answerquest opened this issue · comments
Hello, thank you so much to Konga's authors and contributors for making this amazing program.
I've found one potential frontend-side bug that might need just a simple tweak to fix, documenting it here.
Steps to replicate:
- Add "File log" plugin
- Try to pass a valid custom_fields_by_lua value in the custom_fields_by_lua field.
In the UI for File log plugin (I can't confirm if same issue is there for other plugins too which use the same field), the custom_fields_by_lua
input doesn't accept any kind of input, even if it's valid in the actual plugin add/update api call to Kong.
This is a valid api call to Kong, made for updating a plugin on a service:
curl -X PATCH http://localhost:8001/services/REDACTED/plugins/REDACTED \
--header "Content-Type: application/json" \
--data '{
"name": "file-log",
"config": {
"path": "/data/log.log",
"reopen": true,
"custom_fields_by_lua": {
"client_ip": "return nil",
"route": "return nil"
}
}
}'
But if I tried to put anything like the above json in the custom_fields_by_lua field in UI, I get an error response: "schema violation (config.custom_fields_by_lua: expected a map)"
Full CURL of the failed plugin update api call (with irrelevant parts removed / redacted):
curl 'http://REDACTED/kong/plugins/REDACTED' \
-X 'PATCH' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{"instance_name":null,"name":"file-log","consumer":null,"route":null,"tags":null,"updated_at":1686822097,"service":{"id":"REDACTED"},"protocols":["grpc","grpcs","http","https"],"id":"REDACTED","created_at":1686822097,"enabled":true,"config":{"path":"/data/log.log","reopen":true,"custom_fields_by_lua":"{ \"client_ip\": \"return nil\", \"route\": \"return nil\" }"},"token":"REDACTED"}'
Relevant parts of response:
{
"statusCode": 400,
"body": {
"code": 2,
"name": "schema violation",
"fields": {
"config": {
"custom_fields_by_lua": "expected a map"
}
},
"message": "schema violation (config.custom_fields_by_lua: expected a map)"
}
On the other hand, when there is an existing plugin having a proper custom_fields_by_lua configuration loaded, when the Konga GUI reads it, backend is sending the data properly, but GUI is failing to render the same.
Response of /plugins GET api is having:
"config": {
"custom_fields_by_lua": {
"request.headers.postman-token": "return nil",
"authenticated_entity": "return nil",
proper. But UI is showing "[object Object]" in the form field. Screenshot:
My inference:
- backend is sending data correctly; frontend needs to stringify the custom_fields_by_lua json before populating in field
- when updating, frontend needs to parse the custom_fields_by_lua json value to JSON before sending, which presently it is sending stringified/quoted. Or, backend needs to parse the same into JSON before validating / proceeding to hit Kong api.
I have not run the source code of Konga to properly troubleshoot this - am just using the dockerized end product. Hoping someone can look into this and fix.
Thanks again for making this amazing program.