Can we concatenate two vars in <parameter> of KVM Get policy

https://cloud.google.com/apigee/docs/api-platform/reference/policies/key-value-map-operations-policy...

Above doc states :

  • A combination of literals and variable references

     
    <Key>
     
    <Parameter>targeturl</Parameter>
     
    <Parameter ref="apiproxy.name"/>
     
    <Parameter>weight</Parameter>
    </Key>

When the <Key> element includes multiple <Parameter> elements, the effective key string is the concatenation of the values of each parameter, joined with a double underscore. For example, in the above example, if the apiproxy.name variable has the value abc1, then the effective key will be targeturl__abc1__weight.

Can we join above three vars/literals without double underscore?

In my use case, i want to use two query params combined as a key of KVM.

like: 

<Parameter ref="request.queryparam.input1/>

<Parameter ref="request.queryparam.input2"/>

I don't want to keep value KVM keys like input1__input2, is there any way we can pass key <parameter> as input1+input2?

 

Solved Solved
0 1 97
1 ACCEPTED SOLUTION

No, you cannot do that directly. Is there a good reason you care about the eventual KVM key that is generated? Normally that is an implementation detail and you wouldn't care about it. It would "just work".

A possible workaround is to precede the KVM policy with an AssignMessage policy which creates a new variable containing the desired concatenation.

 

<AssignMessage name='AM-Generate-KVM-Parameter'>
  <AssignVariable>
    <Name>consolidated_parameter</Name>
    <!-- look Ma, no underscores! -->
    <Template>{request.queryparam.input1}{request.queryparam.input2}</Template>
  </AssignVariable>
</AssignMessage>

...and then the specification of the Key in the KVM policy would look like this: 

<Key>
  <Parameter ref="consolidated_parameter"/>
</Key>

I don't understand your motivation for removing the underscores; without a good reason, this workaround seems like a bunch of extra work to remove two underscores that would usually be insignificant to the behavior of the proxy. 

 

View solution in original post

1 REPLY 1

No, you cannot do that directly. Is there a good reason you care about the eventual KVM key that is generated? Normally that is an implementation detail and you wouldn't care about it. It would "just work".

A possible workaround is to precede the KVM policy with an AssignMessage policy which creates a new variable containing the desired concatenation.

 

<AssignMessage name='AM-Generate-KVM-Parameter'>
  <AssignVariable>
    <Name>consolidated_parameter</Name>
    <!-- look Ma, no underscores! -->
    <Template>{request.queryparam.input1}{request.queryparam.input2}</Template>
  </AssignVariable>
</AssignMessage>

...and then the specification of the Key in the KVM policy would look like this: 

<Key>
  <Parameter ref="consolidated_parameter"/>
</Key>

I don't understand your motivation for removing the underscores; without a good reason, this workaround seems like a bunch of extra work to remove two underscores that would usually be insignificant to the behavior of the proxy.