create kvm through a variable using policy

Hello.

I am trying to create a KVM through input variables by header or by body, but in no case it is creating this variable, it only lets me if I put mapIdentifier and it always saves the same value,

I have created a JS and an AM to set the values, but even so it does not set them as name to create the KVM.

what I do first I extract the variables in two steps so that we can set it up

EV-ParseRequestBody

<ExtractVariables name="EV-ParseRequestBody">
<JSONPayload>
<Variable name="private.kvm-entry.value" type="string">
<JSONPath>$.value</JSONPath>
</Variable>
<Variable name="kvm-entry.key" type="string">
<JSONPath>$.key</JSONPath>
</Variable>
</JSONPayload>
</ExtractVariables>

other EV-ParseRequestFormBody

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ExtractVariables name="EV-ParseRequestFormBody">
<FormParam name="name">
<Pattern>{kvm-entry.name}</Pattern>
</FormParam>
<FormParam name="value">
<Pattern>{private.kvm-entry.value}</Pattern>
</FormParam>
</ExtractVariables>

the next steep is the config KVM,

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations continueOnError="false" enabled="true" name="KV-CreateNewKVM" >
<DisplayName>KV-CreateNewKVM</DisplayName>
<Properties/>
<ExclusiveCache>false</ExclusiveCache>
<ExpiryTimeInSecs>300</ExpiryTimeInSecs>
<Put override="true">
<Key>
<Parameter ref="kvm-entry.key"/>
</Key>
<Value ref="private.kvm-entry.value"/>
</Put>
<Scope>environment</Scope>
</KeyValueMapOperations>

this not working, then I try with other config of KVM

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations continueOnError="false" enabled="true" name="KV-CreateNewKVM">
<mapIdentifier>{kvm}</mapIdentifier>
<DisplayName>KV-CreateNewKVM</DisplayName>
<Properties/>
<ExclusiveCache>false</ExclusiveCache>
<ExpiryTimeInSecs>300</ExpiryTimeInSecs>
<Put override="true">
<Key>
<Parameter ref="kvm-entry.key"/>
</Key>
<Value ref="private.kvm-entry.value"/>
</Put>
<Scope>environment</Scope>
</KeyValueMapOperations>

the curl

 
curl --location --request POST 'https://{{host}}/kvm-admin/v1/organizations/{{org}}/environments/{{env}}' \
--header 'Content-Type: application/json' \
--header 'kvm: test2222' \
--data-raw '
{ "key" : "ed24e12820f2f900ae383b7cc4f2b31c402db1be",
"value" : "http://tinyurl.com/38lwmlr,http://apigee.com"
}'
but the result is the same, it does not create anything.
 
 

and I have also tried this KVM and the following curl

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations continueOnError="false" enabled="true" name="KV-CreateNewKVM">
<MapName ref="mapname"/>
<DisplayName>KV-CreateNewKVM</DisplayName>
<Properties/>
<ExclusiveCache>false</ExclusiveCache>
<ExpiryTimeInSecs>300</ExpiryTimeInSecs>
<Get assignTo="kvmData" index="1">
<Key>
<Parameter ref="request.header.kvm"/>
</Key>
</Get>
<Scope>environment</Scope>
</KeyValueMapOperations>

the curls

curl --location --request PUT 'https://{{api}}/kvm-admin/v1/organizations/{{org}}/environments/{{env}}' \
--header 'Content-Type: application/json' \
--header 'kvm: poc' \
--data-raw '{
  "entry" : [ {
    "key" : "key",
    "value" : "0"
  } ],
  "name" : "kvm-poc"
}'
 
but, not create nothing... 😞

Any help?

thanks 🙂😀

 
Solved Solved
0 5 511
1 ACCEPTED SOLUTION

Regarding the error you're seeing, when using the policy with MapName, as per the docs, your map must already be created - https://cloud.google.com/apigee/docs/api-platform/reference/policies/key-value-map-operations-policy...

You should either use mapidentifier with a static KVM as previously suggested or you need to create your KVM up front (Via UI or Management API)

View solution in original post

5 REPLIES 5

1. How are you setting the "mapname" variable that you're using in the KVM policy MapName tag? Also, do you really need to use a variable for this? If you could provide more example on your use case, it would better help understand what you're trying to do

2. RE The MapIdentifier example, the mapIdentifier is an attribute of the KeyValueMapOperations tag, not its own tag ie

<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="CreateFooKVM" mapIdentifier="FooKVM">

 

Hello 

 

Hello,
I'm initializing with the header entry the map name.

we are trying to use the KVM api of daniel strevel without having to go through the GCP, but directly to the runtime, and this api has creation, modification and deletion of field & value, but not a creation of a KVM, and we are trying to create this KVM dynamically, that comes in the header and is able to create it, however the failure that is giving me to put the KVM as I expose, is that this KVM does not exist (obviously, because I am trying to create it).

The kvm

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations continueOnError="false" enabled="true" name="KV-CreateNewKVM">
<MapName ref="request.header.kvm"/>
<Scope>enviroment</Scope>
<Put override="false">
<Key>
<Parameter ref="request.header.kvm"/>
</Key>
<Key>
<Parameter ref="kvm-entry.key"/>
</Key>
<Value ref="private.kvm-entry.value"/>
</Put>
<Scope>environment</Scope>
</KeyValueMapOperations>

 

Regards

1. Do you have a more detailed example of what you use from the request to determine the kvm name/identifier, as well as the key and value pair/s that you then create.

2. Also, are you inserting a single key value pair into separate KVMs each time? If this is the case, you may find it better to have a single key value map, using unique keys in your key value pairs as needed 

Sure

I am using daniel strevel's API, but with the modification to create a KVM from the runtime directly.

If in the EV-body I am putting and get the variable and set it

<Header name="kvm">
<Pattern ignoreCase="false">{mapname}</Pattern>
</Header>

 

Captura.JPG

these is the curl

--header 'Content-Type: application/json' \
--header 'kvm: test123' \
--data-raw '
{ "key""joseluis", "value""mondongo" }'
 
and the kvm
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMapOperations continueOnError="false" enabled="true" name="KV-CreateNewKVM">
<MapName ref="mapname"/>
<DisplayName>KV-CreateNewKVM</DisplayName>
<Properties/>
<ExclusiveCache>false</ExclusiveCache>
<ExpiryTimeInSecs>300</ExpiryTimeInSecs>
<Put override="false">
<Key>
<Parameter ref="kvm-entry.key"/>
</Key>
<Value ref="private.kvm-entry.value"/>
</Put>
<Scope>environment</Scope>
</KeyValueMapOperations>
 
2º question:
I am trying to put a key-value, next to the name of the KVM that I put in the header, I understand that in case it does not exist I should create it, however the failure I get is as follows
error KeyValueMap test123 does not exist
error.class com.apigee.kernel.exceptions.spi.UncheckedException
Identifier fault
state PROXY_RESP_FLOW
type ErrorPoint

Captura2.JPG

 

 

 
 
I don`t if explain better now...

 


 

Regarding the error you're seeing, when using the policy with MapName, as per the docs, your map must already be created - https://cloud.google.com/apigee/docs/api-platform/reference/policies/key-value-map-operations-policy...

You should either use mapidentifier with a static KVM as previously suggested or you need to create your KVM up front (Via UI or Management API)