Variable is disorder in different routing plugins

BUG: data_dict variable is disorder in different routing plugins

kong version>=0.14.1

kong service: www.foo.com
kong route:
├ path: /mypath1 plugin: my-plugin( different config data)
├ path: /mypath2 plugin: my-plugin( different config data)

plugin code example:

local data_dict = {}
local plugin = require("kong.plugins.base_plugin"):extend()

function plugin:new()
    plugin.super.new(self, "myplugin")
end

function plugin:access(conf)
    plugin.super.access(self)

      
      --init conf.identify_values array to data_dict 
      --conf.identify_values : A=1 , B=2
      --data_dict                  :  {A=1,B=2}
      init_data(conf.identify_values)

      --print data
      dump(data_dict) 
      dump(conf.identify_values) 

      --print table address
      kong.log.err(tostring(data_dict)) 
      kong.log.err(tostring(conf.identify_values))

end

plugin.PRIORITY = 12

return plugin

Plugin config:
path: /mypath1 plugin: my-plugin( conf.identify_values : A=1 , B=2 )
path: /mypath2 plugin: my-plugin( conf.identify_values : C=3 , D=4)

The request for many times:

http://www.foo.com/mypath1
http://www.foo.com/mypath2

Expect DUMP
path: /mypath1 plugin: my-plugin( data_dict : A=1 , B=2 )
path: /mypath2 plugin: my-plugin( data_dict : C=3 , D=4)

Actual DUMP:
path: /mypath1 plugin: my-plugin( data_dict : A=1 , B=2 )
path: /mypath2 plugin: my-plugin( data_dict : A=1 , B=2)

@thibaultcha,@hbagdi

Resolved

local data_dict = {}
local plugin = require("kong.plugins.base_plugin"):extend()

function plugin:new()
    plugin.super.new(self, "myplugin")
end

function plugin:access(conf)
    plugin.super.access(self)

     local cache_id = conf.route_id or conf.service_id
     
     data_dict[cache_id] = init_data(conf.identify_values)

      dump(data_dict[cache_id]) 

      dump(conf.identify_values) 

end

plugin.PRIORITY = 12

return plugin

© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ