Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Konga plugin config removes newline from config values #189

Closed
florian-besser opened this issue Mar 8, 2018 · 4 comments
Closed

Konga plugin config removes newline from config values #189

florian-besser opened this issue Mar 8, 2018 · 4 comments

Comments

@florian-besser
Copy link

florian-besser commented Mar 8, 2018

This is in regard to the following comment:

#17 (comment)

We try to configure a custom plugin by adding a public key. But Konga will strip away any newline characters and replace them with spaces instead, which makes the public key invalid.

Version used: latest Docker tag for pantsel/konga
kong version: 0.12.2

Calling kong directly works. When tracing the AJAX call in Browser tools we can see the newlines being stripped away by Konga before sending the plugin config to the server.

@pantsel
Copy link
Owner

pantsel commented Mar 8, 2018

@florian-besser ,

What is the plugin's configuration (as stated in your .lua files)?

This is def an issue with custom plugins and we have to discuss on how to solve it.

Here's what happens.

In order to create the plugin form dynamicaly, I get it's schema from Kongs API
/plugins/schema/{plugin name}.

The response is something like this

{
    "fields": {
        "hide_credentials": {
            "default": false,
            "type": "boolean"
        },
        "key_names": {
            "default": "function",
            "required": true,
            "type": "array"
        }
    }
}

If a field type is string, I translate it to a text input which by definition cannot accept new lines.

I need a way to know, that the specific input must be a textarea and frankly, I have no idea if or how this can be done.

One solution would be to translate all string fields to textareas instead of text inputs so it can work with non standard plugins (that i cannot monkey patch).

@florian-besser
Copy link
Author

florian-besser commented Mar 8, 2018

This was our schema.lua

return {
   no_consumer = true,
   fields = {
    pub_key = { type = "string", default = [[-----BEGIN PUBLIC KEY-----
ADD YOUR KEY!!!
-----END PUBLIC KEY-----]]
     }
   }
 }

AFAIK Kong config types have no "textfield" equivalent.

In the end we were able to configure Kong directly using:

curl -X POST http://localhost:8001/apis/<ApiName>/plugins -F "name=<pluginName>" -F "config.pub_key=@/home/florian/.ssh/public.pem"

I also have no idea how to differentiate whether config "string" should accept newlines or not. But since Kong accepts newlines for "string" my first suggestion would be to use HTML "textfield"s for every "string" config value. Then at least the GUI is consistent with the raw API.

@pantsel
Copy link
Owner

pantsel commented Mar 8, 2018

@florian-besser ,

pull thel atest commit from master and check out if things work as expected

@florian-besser
Copy link
Author

Verified working @pantsel . Thanks a lot for the speedy fix.

For others: I did have to clear my browser cache to see the changes, as Konga was still cached!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants