I'm trying to configure corporate proxy for go kong plugin https://github.com/Kong/go-pdk
here is my code:
package main
import (
"github.com/Kong/go-pdk"
)
type Config struct {
Apikey string
}
func New() interface{} {
return &Config{}
}
func (conf Config) Access(kong *pdk.PDK) {
err := kong.Nginx.SetCtx("balancer_address.host", "127.0.0.1")
if err != nil {
kong.Log.Err(err.Error())
}
errC := kong.Nginx.SetCtx("balancer_address.port","8080")
if errC != nil {
kong.Log.Err(errC)
}
key, err := kong.Request.GetQueryArg("key")
apiKey := conf.Apikey
if err != nil {
kong.Log.Err(err.Error())
}
x := make(map[string][]string)
x["Content-Type"] = append(x["Content-Type"], "application/json")
if apiKey != key {
kong.Response.Exit(403, "Youu have no correct key", x)
}
}
of course i created test proxy server at my host: 127.0.0.1:8080
but it's not working
by plugin doc: kong.Nginx.SetCtx() sets a value in the ngx.ctx request context table
i made my go plugin by example https://github.com/tfabien/kong-forward-proxy/blob/master/src/access.lua where
ngx.ctx.balancer_address.host = plugin_conf.proxy_host
ngx.ctx.balancer_address.port = plugin_conf.proxy_port
are configuring proxy
so, anyway it's not working
my dockerfile is
FROM kong/go-plugin-tool:2.0.4-alpine-latest AS builder
RUN mkdir -p /tmp/key-checker/
COPY . /tmp/key-checker/
RUN cd /tmp/key-checker/ && \
go get github.com/Kong/go-pdk && \
go mod init kong-go-plugin && \
go get -d -v github.com/Kong/go-pluginserver && \
go build github.com/Kong/go-pluginserver && \
go build -buildmode plugin key-checker.go
FROM kong:2.3-alpine
RUN mkdir /tmp/go-plugins
COPY --from=builder /tmp/key-checker/go-pluginserver /usr/local/bin/go-pluginserver
COPY --from=builder /tmp/key-checker/key-checker.so /tmp/go-plugins
ENV KONG_PLUGINSERVER_NAMES="go"
ENV KONG_PLUGINSERVER_GO_SOCKET="/tmp/go-plugins/go_pluginserver.sock"
ENV KONG_PLUGINSERVER_GO_START_CMD="/usr/local/bin/go-pluginserver -kong-prefix /tmp/go-plugins/ -plugins-directory /tmp/go-plugins"
ENV KONG_PLUGINSERVER_GO_QUERY_CMD="/usr/local/bin/go-pluginserver -dump-all-plugins -plugins-directory /tmp/go-plugins"
COPY config.yml /tmp/config.yml
USER root
RUN chmod -R 777 /tmp
RUN /usr/local/bin/go-pluginserver -version && \
cd /tmp/go-plugins && \
/usr/local/bin/go-pluginserver -dump-plugin-info key-checker
USER kong
starting docker by:
docker run -ti --rm --name kong-go-plugins \
-e "KONG_DATABASE=off" \
-e "KONG_GO_PLUGINS_DIR=/tmp/go-plugins" \
-e "KONG_DECLARATIVE_CONFIG=/tmp/config.yml" \
-e "KONG_GO_PLUGINSERVER_EXE=/usr/local/bin/go-pluginserver" \
-e "KONG_PLUGINS=key-checker" \
-e "KONG_PROXY_LISTEN=0.0.0.0:8000" \
-p 8000:8000 \
kong-demo
how can i resolve it?