6

I'm using Krakend as API-Gateway, and my configuration looks like this :

{
  "plugin": {
    "folder": "/etc/krakend/plugins/authenticator/",
    "pattern":".so"
  },
  "port": 8080,
  "extra_config": {
    "github_com/devopsfaith/krakend/transport/http/server/handler": {
      "name": "authenticator"
    }
  },

  "endpoints": [
    {
      "output_encoding": "no-op",
      "backend": [
        {
          "encoding": "no-op",
          "host": [
            "127.0.0.1:8080"
          ],
          "url_pattern": "/api/v1/address/{id}",
          "method": "GET"
        }
      ],
      "endpoint": "/api/v1/addresses/{id}",
      "method": "GET"
    }
  ],

  "name": "gateway",
  "timeout": "30s",
  "version": 2
}

I want to pass some metadata per end point and access it in my predefined plugin . In this case authenticator plugin.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
slifer2015
  • 682
  • 6
  • 12

1 Answers1

-1

What you are trying to achieve is perfectly possible, and is the way all components work in KrakenD. Your plugin can access the KrakenD configuration using the namespace you define. For instance, you could set your metadata like this (I am assuming you have in your Go code a pluginName = "slifer2015-authenticator" ):

{
    "endpoints": [
        {
            "output_encoding": "no-op",
            "backend": [
                {
                    "encoding": "no-op",
                    "host": [
                        "127.0.0.1:8080"
                    ],
                    "url_pattern": "/api/v1/address/{id}"
                }
            ],
            "endpoint": "/api/v1/addresses/{id}",
            "extra_config": {
                "github_com/devopsfaith/krakend/transport/http/server/handler": {
                    "name": [
                        "slifer2015-authenticator",
                        "some-other-plugin-here"
                    ],
                    "slifer2015-authenticator": {
                        "Metadata1": "value1",
                        "Metadata2": {
                            "Some": 10,
                            "Thing": 100,
                            "Here": "60s"
                        }
                    }
                }
            }
        }
    ]
}

Then your metada is available in the extra parameter when the registerer kicks in, inside the key you have chosen.

func (r registerer) registerHandlers(ctx context.Context, extra map[string]interface{}, h http.Handler) (http.Handler, error) {
``
alo
  • 1,229
  • 11
  • 9
  • I tried this , unfortunately It doesn't work . It only apply the plugin when I put `extra_config` in the root of configuration not per endpoint :( – slifer2015 Jan 09 '22 at 09:02