Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

KVM entries are updated to same value for all the keys of a kvm when creating it using policy

Hello,

We are trying to create multiple KVM entries using the apigee policy on apigee x (scoped at environment level) but when populating the values for each key it is duplicating and copying the last value to all the keys in the KVM. Below is the sample policy we are using:

 

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations continueOnError="false" enabled="true" name="KVM-keyvaluemap" mapIdentifier="test-KVM">
    <DisplayName>KVM-keyvaluemap</DisplayName>
    <Properties/>
    <Put override="true">
        <Key>
            <Parameter>
                <Name>pathparam</Name>
            </Parameter>
        </Key>
        <Value>/v1/user</Value>
    </Put>
    <Put override="true">
        <Key>
            <Parameter>
                <Name>serviceId</Name>
            </Parameter>
        </Key>
        <Value>1</Value>
    </Put>
    <Scope>environment</Scope>
</KeyValueMapOperations>

 

 

 

when we fetch the kvm for the above we get for both pathparam = 1 and serviceId=1. We tried setting the overide option to false and that also has similar behavior.

We also tried two different policies to update and add the entries to the same kvm but it has same behavior. Can someone tell what we are doing wrong or is it a known issue?

 

1 1 105
1 REPLY 1

Yes your policy is incorrect. 

You want this: 

<KeyValueMapOperations name="KVM-keyvaluemap" mapIdentifier="test-KVM">
  <Put>
    <Key>
      <!-- no
       <Parameter>
           <Name>pathparam</Name>
       </Parameter>
      -->
      <!-- yes -->
      <Parameter>pathparam</Parameter>
    </Key>
    <Value>/v1/user</Value>
  </Put>
  <Put override="true">
    ...
  </Put>
  <Scope>environment</Scope>
</KeyValueMapOperations>

Really, the validation of the policy should catch this. 

I'll get an update in apigeelint to make sure in the future this error gets flagged. 

With the policy configuration you used, Both "Put" operations used the same empty key.  And likewise the Get operation you used also probably used an empty key.  So you were getting "the last thing written".