Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share Data between Plugins in Kong JS PDK #65

Closed
sinalkar opened this issue Oct 5, 2021 · 2 comments
Closed

Share Data between Plugins in Kong JS PDK #65

sinalkar opened this issue Oct 5, 2021 · 2 comments

Comments

@sinalkar
Copy link

sinalkar commented Oct 5, 2021

Hi team,
Consider Scenario in which let's consider

  1. Parent Plugin Holding All common Configurations and having Highest Priority
  2. Child Plugin will get those common configurations from Parent and do action as per business logic

I tried with Custom nginx directive environment concept too which is https://docs.konghq.com/enterprise/2.5.x/property-reference/#injecting-nginx-directives , but it is not working for me.

docker run -it --name jskong \ --network=kong-net \ -e "KONG_DATABASE=postgres" \ -e "KONG_PG_HOST=kong-database" \ -e "KONG_PG_USER=kong" \ -e "KONG_PG_PASSWORD=kong" \ -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \ -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \ -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \ -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \ -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \ -e "KONG_ADMIN_LISTEN=0.0.0.0:8001 reuseport backlog=16384, 0.0.0.0:8444 http2 ssl reuseport backlog=16384" \ -e "KONG_PLUGINSERVER_NAMES=js" \ -e "KONG_PLUGINSERVER_JS_SOCKET=/usr/local/kong/js_pluginserver.sock" \ -e "KONG_PLUGINSERVER_JS_START_CMD=/usr/local/bin/kong-js-pluginserver -v --plugins-directory /usr/local/kong/js-plugins" \ -e "KONG_PLUGINSERVER_JS_QUERY_CMD=/usr/local/bin/kong-js-pluginserver --plugins-directory /usr/local/kong/js-plugins --dump-all-plugins" \ -e "KONG_PLUGINS=bundled,global-config" \ -e "KONG_NGINX_MAIN_ENV=DATABASE_HOST; env DATABASE_PASSWORD; env DATABASE_USER; env DATABASE_NAME" \ -p 8000:8000 \ -p 8443:8443 \ -p 127.0.0.1:8001:8001 \ -p 127.0.0.1:8002:8002 \ -p 127.0.0.1:8444:8444 \ kong:1.0
but in my plugin with process.env it's not getting

It will be better if Parent => Child Plugin Data Shareable

Can you please guide how to do or access.

@fffonion
Copy link
Contributor

fffonion commented Oct 5, 2021

Hi @sinalkar you can use the kong.ctx.shared API

@sinalkar sinalkar changed the title How to get Parent Plugins Config to Child or Nested Plugins Share Data between Plugins in Kong JS PDK Oct 6, 2021
@sinalkar
Copy link
Author

sinalkar commented Oct 6, 2021

Thanks @fffonion .
I did
In parent plugin in access method : Priority 5000
await kong.ctx.shared.set('globalConfig',JSON.stringify(tmpConfig))

In Child Plugin i able to get in access method : Priority : 4000
await kong.ctx.shared.get('globalConfig')

and it's working

@sinalkar sinalkar closed this as completed Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants