I’m working on a custom plugin in Kong Enterprise 0.33-1 and am trying to access kong.db
and kong.dao
, but both are nil
. Out of curiosity, I just tried a simple kong.version
and that even comes back as nil
.
There are some fields available from the kong
variable, which I was able to see by printing out all the keys of the table. Here’s all the fields I do see:
body_filter
balancer
log
serve_portal-api
serve_admin_api
init
access
handle_error
ssl_certificate
init_worker
header_filter
rewrite
Where are all the PDK fields?
Here’s my code for handler.lua
–any glaring issues?
local access = require "kong.plugins.validator.access"
local base_plugin = require "kong.plugins.base_plugin"
local validator = base_plugin:extend()
function validator()
validator.super.new(self, "validator")
end
function validator:access()
validator.super.access(self)
for k, _ in pairs(kong) do
print(k)
end
print(kong.version) -- returns "nil"
access.execute()
end
validator.PRIORITY = 799
return validator
Hi,
The PDK was released in Kong 0.14. Kong Enterprise is still based on Kong 0.13 as of today (October 2018). A next release of Kong Enterprise will see a bump in the Kong core version and will get support for the PDK.
Got it.
In the meantime, is there a different way I can read from the datastore/cache without the PDK?
I was able to successfully write a daos.lua
and cassandra.lua
and migrate my custom table to the database, and I also wrote an api.lua
to expose endpoints to create/delete data in that table. That all works, so it seems like I should have some level of connectivity to the DB within my plugin.
Thanks
Hi again,
First, make sure that you browse the 0.13 documentation, as your Enterprise version is based on it, and not 0.14 (the current default on the docs website).
In there, you can see there are are no mentions of the PDK (see the right-hand sidebar), because the PDK does not exist yet in 0.13, as previously mentioned. However, you’ll notice the Plugins Development Guide. This guide has a section on how to access the database from plugins (as of 0.13), and how to store custom entities as well (which you seem to have succeeded with already).
Reading from the cache is also documented on this guide, here.