consumer key as parameter - definitions.yaml

Hi, according to https://docs.apigee.com/api-platform/istio-adapter/examples#api_key_as_query_parameter documentation, we can overwrite part of definitions.yaml configuration in httpapispec.yaml. My question is: I want to accept consumer key via parameter, not header. I know we can do it in httpapispec.yaml. But I would like to do it in definitions.yaml and make it global. Probably I will need to change this line: api_key: request.api_key | request.headers["x-api-key"] | "" but I do not know the syntax. Could someone help me? Best regards

1 6 333
6 REPLIES 6

Hi @Nicolas Cage , I guess it depends on the Istio version being used. In request.headers["x-api-key"], the request.headers is an Istio Attribute. Now let's discuss Query Parameters,

In Istio 1.0, we have request.path attribute but no attribute for getting only/specific QueryParams,

request.pathstringThe HTTP URL path including query string
In Istio Prelim 1.1 , we have request.query_params attributes,
request.query_paramsmap[string, string]A map of query parameters extracted from the HTTP URL.

I have not tried this yet, but I guess we can use request.query_params["apikey"] in definitions.yaml.

I know I am guessing a lot of things, so let's wait for @scott@ganyo.com @theganyo @srinandans to comment on this, maybe some changes are required for the adapter as well.

@Siddharth Barahalikar thank you for the fast reply. Unfortunately, both request.path and request.query_params do not work.

Ideally, request.path should not work as it considers the entire URL.

What is your Istio version? The attribute , request.query_params is part of Istio Prelim 1.1

istio version = 1.0.5

Unfortunately, since Istio 1.x doesn't have the request.query_params attribute available yet, you cannot do this in definitions.yaml, you need to do it in the httpapispec.yaml.

That said, by default Istio populates request.api_key from:

- query: key

- query: api_key

- header: x-api-key

So if you use `key` or `api_key` as your parameter, you should be good to go without specifying anything.

that is not true, by default it accepts consumer key only in header. Passing it as query parameter requires additional configuration in httpapispec.yaml file.

Please do not post solutions that are based only on your beliefs (check it first).