是否可以将计算键与KeyValueMaps一起使用?

时间:2014-06-02 19:07:04

标签: apigee

我想使用KeyValueMaps来存储一些简单的值,但我需要使用的键将在运行时计算。例如,在我的初始入门'我想做这样的事情:

<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Sandbox-Read-Count">
    <DisplayName>Sandbox - Read Count</DisplayName>
    <FaultRules/>
    <Properties/>
    <ExclusiveCache>false</ExclusiveCache>
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
    <InitialEntries>
        <Entry>
            <Key>
                <Parameter>{variable}.sandbox.calls</Parameter>
            </Key>
            <Value>0</Value>
        </Entry>
    </InitialEntries>
    <Scope>apiproxy</Scope>
</KeyValueMapOperations>

但是,在执行此操作时,我尝试保存策略时出错:

Error while Uploading file for API Test.
messaging.config.beans.InvalidBundle. Errors:[Entity : policy-Sandbox-Read-Count, Invalid Key Names For Entries: [{apikey}.sandbox.calls];]

是否可以在KeyValueMap策略中使用计算值?我应该使用不同的语法吗?

1 个答案:

答案 0 :(得分:1)

我已对此进行了调查。当您使用InitialEntries在apiproxy范围的KVM中保存代理时,会立即使用初始条目创建KVM。因此,没有办法使用运行时变量,因为KVM的启动已经发生在代理运行之前。

您没有使用KeyValueMapOperations元素中的mapIdentifier字段(请查看Apigee文档中的KeyValueMap PUT Sample),因此您创建的KVM将命名为kvmap

您可以使用以下management API call获取给定apiproxy的KVM及其内容列表:

GET https://api.enterprise.apigee.com/v1/o/{org}/apis/{apiname}/keyvaluemaps?expand=true

Authorization: Basic {base64 username:password}

由于InitialEntries部分仅在代理首次成功加载时使用(即使您更改了InitialEntries部分并重新部署,如果该名称的KVM已经存在,也不会进行任何更改),我认为InitialEntries部分的用处相当有限。我建议您使用management API to initialize the KVM手动启动KVM:

PUT https://api.enterprise.apigee.com/v1/o/{org}/apis/{apiname}/keyvaluemaps

Authorization: Basic {base64 username:password}
Content-Type: application/json

{
  "entry" : [ {
    "name" : "key",
    "value" : "0"
  } ],
  "name" : "{kvmName}"
}
相关问题