Kong / kong-python-pdk

Write Kong plugins in Python (Experimental)
Apache License 2.0
40 stars 14 forks source link

How to access information in custom plugins using python PDK ? #116

Open khangt1k25 opened 1 year ago

khangt1k25 commented 1 year ago

I am using Python PDK to write a custom Plugin for the Kong gateway. Everything setup is done and it's working with the py-hello example. But in the access phase, I want to retrieve all the context and information of the service, consumer. How can I do that. Most of the return value is Table type. Take a look to this example.

service = kong.router.get_service()

I want to get the service id for example. How can i do that. Thank you

fffonion commented 1 year ago

hi @khangt1k25 if you are uncertain of the return type, use print to debug

service = kong.router.get_service()
print("service is ", service)
khangt1k25 commented 1 year ago

hi @fffonion , As i said before, the return value is table type. I am using kong.log to debug the type. But if just return

table x0193d24adxa

But in python, i want to get information from this table. How can i parse this table to normal format or access property of that using other way? Thank you

fffonion commented 1 year ago

@khangt1k25 you can just use python's print, every thing on stdout will be inside kong's error log

khangt1k25 commented 1 year ago

I wont show any line. I am using docker to deploy the Kong. Is there any arg -v to add any command to start plugin?

fffonion commented 1 year ago

you may need to set kong's log_level to debug if you haven't do so.