"config_data" more complex values?

It seems the config_data for an API only supports a simple flat object structure with only string values?

Is there any plan to support something like the below? Submitting such a thing causes errors, also on read of it

{
  "prop": true,
  "prop2" : { "test1" : "val" }
}

It should work - will take a look.

How did you try to add that config_data to the gateway? Could you provide reproduction steps?

Also, I assume this is on 2.3.7?

I’ve been unable to reproduce this on master.

Via dashboard on 1.3.7, gateway 2.3.7

this config updated OK via dashboard:

{
  "debug_mode": "true",
  "my_auth_host": "http://192.168.0.148:9080",
  "prop": true,
  "prop2": {
    "test1": "val"
  },
  "protected_system_host": "tyk-my-auth",
  "requested_resource_tag": "xxx",
  "requesting_system": "xxx",
  "session_expires_seconds": "60"
}

this error on gateway when API is invoked:

2017-07-26T17:49:07.872887318Z time="Jul 26 17:49:07" level=info msg="Checking security policy: Token" api_name="MY Auth"
2017-07-26T17:49:08.874017354Z time="Jul 26 17:49:08" level=info msg="Processed and listening on: /portal-assets/{rest:.*}"
2017-07-26T17:49:08.874108845Z time="Jul 26 17:49:08" level=info msg="Processed and listening on: /portal-api/{rest:.*}"
2017-07-26T17:49:08.874125126Z time="Jul 26 17:49:08" level=info msg="Processed and listening on: /my/auth/10{rest:.*}"
2017-07-26T17:49:08.874318397Z time="Jul 26 17:49:08" level=info msg="Processed and listening on: /portal/{rest:.*}"
2017-07-26T17:49:08.874803324Z time="Jul 26 17:49:08" level=info msg="Loading uptime tests..."
2017-07-26T17:49:08.874848071Z time="Jul 26 17:49:08" level=info msg="Initialised API Definitions"
2017-07-26T17:49:08.874870744Z time="Jul 26 17:49:08" level=info msg="API reload complete"
2017-07-26T17:49:08.874888623Z time="Jul 26 17:49:08" level=info msg="Initiating coprocess reload"
2017-07-26T17:49:11.318601267Z time="Jul 26 17:49:11" level=error msg="Failed to parse configuration data: 2 error(s) decoding:\n\n* 'config_data[prop2]' expected type 'string', got unconvertible type 'map[string]interface {}'\n* 'config_data[prop]' expected type 'string', got unconvertible type 'bool'"
2017-07-26T17:49:11.323054896Z time="Jul 26 17:49:11" level=error msg="Failed to decode middleware request data on return from VM: invalid character 'u' looking for beginning of value"
2017-07-26T17:49:11.323109931Z time="Jul 26 17:49:11" level=info msg="Attempted access with malformed header, no auth header found." origin=172.18.0.1 path="/my/auth/10"
2017-07-26T17:49:11.323175853Z time="Jul 26 17:49:11" level=error msg="request error: Authorization field missing" api_id=4c9611ea2ed148d24b1822e85648dc89 org_id=5976507eb46f2e00016bb4a1 path="/" server_name="http://192.168.0.148:9080/service/xxx" user_id= user_ip=172.18.0.1
2017-07-26T17:49:15.614719923Z time="Jul 26 17:49:15" level=error msg="Failed to parse configuration data: 2 error(s) decoding:\n\n* 'config_data[prop2]' expected type 'string', got unconvertible type 'map[string]interface {}'\n* 'config_data[prop]' expected type 'string', got unconvertible type 'bool'"
2017-07-26T17:49:15.614784846Z time="Jul 26 17:49:15" level=error msg="Failed to decode middleware request data on return from VM: invalid character 'u' looking for beginning of value"
2017-07-26T17:49:15.614807919Z time="Jul 26 17:49:15" level=info msg="Attempted access with malformed header, no auth header found." origin=172.18.0.1 path="/my/auth/10"
2017-07-26T17:49:15.614823900Z time="Jul 26 17:49:15" level=error msg="request error: Authorization field missing" api_id=4c9611ea2ed148d24b1822e85648dc89 org_id=5976507eb46f2e00016bb4a1 path="/" server_name="http://192.168.0.148:9080/service/xxx" user_id= user_ip=172.18.0.1

How did you upload the API definition to the dashboard, exactly? Could you provide the entire API definition?

pasted it into the Config Data section on the Advanced Options tab in the dashboard for the affected API

When I export the API def, the config_data looks like this in the export

...
    "tags": [],
    "enable_context_vars": false,
    "config_data": {
        "debug_mode": "true",
        "ocd_auth_host": "http://192.168.0.148:9080",
        "prop": true,
        "prop2": {
            "test1": "val"
        },
        "protected_system_host": "tyk-my-auth",
        "requested_resource_tag": "xxx",
        "requesting_system": "xxx",
        "session_expires_seconds": "60"
    }
}

I overlooked something in the stable version - the code is indeed buggy. I’ll open an issue on GitHub shortly once I’ve figured out what the right fix for this is. Will keep you posted.

1 Like

Great, yeah I will definitely have a need to have an N deep complex object structure w/ more support than just string data-types (ints, booleans etc) to configure some middleware.

Here’s the issue: config_data is restricted to map[string]string on stable · Issue #951 · TykTechnologies/tyk · GitHub

We’ll ship a fix for this with 2.3.8, which should come out within the next two weeks. See the milestone for the other fixes that will be included.

Thanks for reporting!