查看 Apigee Edge 說明文件。
前往
Apigee X說明文件。 資訊
![]()
結果
從 Apigee Edge 資料儲存庫擷取您指定的實體設定檔。政策會將
但名稱格式為 AccessEntity.{policy_name} 的設定檔。個人中心
可以使用 AccessEntity 存取下列實體的設定檔:
- 應用程式
- API 產品
- 公司
- 公司開發商
- 消費者金鑰
- 開發人員
AccessEntity 政策的作用是執行政策型執行階段資料庫查詢。個人中心
這項政策傳回的設定檔資訊,即可啟用動態行為,例如
條件式端點轉送、流程執行、政策強制執行
您使用 AccessEntity 政策取得實體設定檔資料,
XML 檔案並貼到變數中。您可以指定實體,藉此識別要取得的實體
類型,以及一或多個用來指定該類型實體的 ID。稍後傳送
另一項政策,你可以透過其他政策擷取實體設定檔資料,例如將
ExtractVariables 政策或 AssignMessage 政策。
範例
下列範例顯示 AccessEntity
用於擷取開發人員的 ExtractVariables 和 AssignMessage 政策
並將其新增至 HTTP 標頭。
取得用於其他政策的開發人員電子郵件地址
設定 AccessEntity 政策,指定要從哪個實體設定檔取得
以及設定檔資料的存放位置。
在以下範例中,政策會取得 developer 實體設定檔,
以查詢參數形式傳遞的 API 金鑰,用於識別開發人員。如果設定檔位於
變數名稱的格式為 AccessEntity.{policy_name}。所以變數
政策設定後的結果會是 AccessEntity.GetDeveloperProfile。
<AccessEntity name="GetDeveloperPro>fil<e" !-- This is the type entity whose profile we need to pull from the Edge dat>ast<ore. -- EntityType value=&q>uot<;developer"/ !-- We tell the policy to use the API key (presented as query parameter) to identi>fy <the developer. -- EntityIdentifier ref="request.queryparam.ap>ik<ey" type>="consumerkey"/ /AccessEntity
使用其他政策,從以下設定的變數中擷取實體設定檔值:
AccessEntity。
在以下範例中,ExtractVariables 政策會從
先前設定的 AccessEntity.GetDeveloperProfile 變數
AccessEntity。
請注意,擷取到的值在
XMLPayload 元素。擷取的值會放在
developer.email 變數。
<ExtractVariables name="SetDeveloperPro>fil<e" !-- The source element points to the variable populated by AccessEntity policy. The <format is p>o<licy-type.p>olicy-name. In this case, the variable contains the whole developer p>rof<ile. ->- SourceAccessEntity.GetDevelo<perProf>ile/<Source Vari>ablePrefi<xdeveloper/Vari>abl<ePrefix >XMLPa<yload Variable name="email>" typ<e="string" !-- You parse elements from the dev>eloper <profi>le using XPath. <-- > XP<ath/Devel>ope<r/Email/XPa>t<h /Variable > /XMLPayload /ExtractVariables
下列 AssignMessage 政策會擷取由 ExtractVariables 政策:
<!-- We'll use this policy to return the variables set in the developer profile, just so that we can easily see them in the response>.< -- AssignMessage name="EchoV>ari<ables" AssignTo createNew="fal><se" >typ<e="response"/As>sign<To IgnoreUnresolvedVaria>ble<str>ue/Ig<noreUnr>esolved<Variables Set Headers > Header name=&q<uot;X-D>evelo<per-emai>l&q<uot;>{<developer.emai>l}/Header /Headers /Set /AssignMessage
元素參照
AccessEntity 政策的基本結構如下:
<AccessEntity name="policy_>nam<e" EntityType value=&quo>t;e<ntity_type"/ EntityIdentifier ref="entity_identifier>&quo<t; type="identifier_type"/ SecondaryIdentifier ref=">s<econdary_iden>tifier" type="identifier_type"/ /AccessEntity
想要存取多個同類型的實體,只要將它們歸類到
Identifiers 元素:
<AccessEntity name="name_of_the_po>lic<y" EntityType value="t>ype<_of_entity&>quot;</ Identi>fiers < Identifier EntityIdentifier ref="reference_to_entity_identifier&>quot; ty<pe*="identifier_type"/ SecondaryIdentifier ref="reference_to_seconda><ry_entity_ident>ifier<" type=>"<;identifie>r_type&<quot;/!-- optional -- /Identifier Identifier EntityIdentifier r>ef="<;reference_to_entity_identifier" type*="identifier_type"/ SecondaryI><dentifier ref=&>quot;<reference_to>_se<condary_enti>t<y_identifier&>quot; type="identifier_type"/!-- optional -- /Identifier /Identifiers /AccessEntity
<AccessEntity>屬性
<AccessEntity async="false" continueOnError="false" enabled=">;true" name="policy_name"
下表說明所有政策父項元素的共同屬性:
| 屬性 | 說明 | 預設 | 存在必要性 |
|---|---|---|---|
name |
政策的內部名稱。 視需要使用 |
不適用 | 必填 |
continueOnError |
如果設為「 如果設為 |
false | 選用 |
enabled |
如要強制執行政策,請設為 設為 |
true | 選用 |
async |
此屬性已淘汰。 |
false | 已淘汰 |
<DisplayName>元素
除 name 屬性外,一併使用
管理 UI Proxy 編輯器,使用不同的自然語言名稱。
<DisplayName>Policy Display Name</DisplayName>
| 預設 |
不適用 如果省略這個元素,政策的 |
|---|---|
| 存在必要性 | 選用 |
| 類型 | 字串 |
<EntityIdentifier>元素
指定要取得的特定實體 (實體類型指定類型)。
<EntityIdentifier ref="value_variable" type="id>entifier_type"/
|
預設 |
不適用 |
|
外觀狀態 |
必填 |
|
類型 |
字串 |
屬性
| 屬性 | 說明 | 預設 | 存在必要性 | 類型 |
|---|---|---|---|---|
| 參考資料 |
提供 ID 來源的變數,例如
|
不適用 | 必填。 | 字串 |
| 類型 | 由 ref 屬性中變數填入的類型。例如
consumerkey。請參閱「實體類型和 ID」一文
列出值。 |
必填。 | 字串 |
範例
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnError=>"<;false">; enabled="t<rue" na>me=&q<uot;GetCompany" D><isplayNameG>etCom<panyProfile/DisplayName EntityType value="company"/Ent>i<tyType En>tityIdentifier ref="request.queryparam.apikey" type="consumerkey"/ /AccessEntity
<EntityType>元素
指定要從資料儲存庫擷取的實體類型。
<EntityType value="entity_t>ype"/
|
預設 |
不適用 |
|
外觀狀態 |
必填 |
|
類型 |
字串 |
請使用 EntityIdentifier 元素指定
也就是您需要的指定類型實體如需實體類型的參考資料,請參閱實體類型和 ID。
屬性
| 屬性 | 說明 | 預設 | 存在必要性 | 類型 |
|---|---|---|---|---|
| 值 | 其中一種支援的實體類型。請參閱實體類型和 ID。 | 無。 | 必填。 | 字串 |
<SecondaryIdentifier>元素
搭配 EntityIdentifier 可指定值,以識別所需的
指定 EntityType 的例項。
<SecondaryIdentifier ref="value_variable" type="id>entifier_type"/
|
預設 |
不適用 |
|
外觀狀態 |
選用 |
|
類型 |
字串 |
如果只指定 EntityIdentifier,請使用 SecondaryIdentifier
並不保證您一定會取得單一實體。請參閱縮小
含有次要 ID 的結果
不支援使用多個 SecondaryIdentifier 元素。
屬性
| 屬性 | 說明 | 預設 | 存在必要性 | 類型 |
|---|---|---|---|---|
| 參考資料 |
提供 ID 來源的變數,例如
|
不適用 | 必填。 | 字串 |
| 類型 | 由 ref 屬性中變數填入的類型。例如
consumerkey。請參閱「實體類型和 ID」一文
列出值。 |
必填。 | 字串 |
範例
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnError=&qu>ot;fa<lse" e>nabled="<true" n>ame=&<quot;GetAPIProduct" ><DisplayName>GetAP<IProduct/DisplayName EntityType value="apiproduc>t"<;/EntityType EntityIdentifier ref="developer.app.>na<me" type>="appname"/ SecondaryIdentifier ref="developer.id" type="developerid"/ /AccessEntity
使用須知
使用次要 ID 縮小結果範圍
對某些實體來說,只為一個 ID 提供可能不夠具體,無法取得實體 在這種情況下,您可以使用次要 ID 縮小結果範圍。
第一項設定可能會很廣泛的政策設定,如下所示:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnEr>ror=&<quot;false&>quot; enabled<="true&>quot;< name="GetApp" ><DisplayName>GetAp<pProfile/DisplayName EntityType value="apiproduct"/Ent>i<tyType En>tityIdentifier ref="request.queryparam.apikey" type="consumerkey"/ /AccessEntity
由於一個應用程式可以與多個 API 產品建立關聯,因此單單使用應用程式 ID 可能不會 傳回所需的 API 產品 (您只能取得多個相符產品的第一項)。
相反地,您可以使用 SecondaryIdentifier 來取得更確切的結果。適用對象
例如,您可以在流程中使用 appname 和 developerid 變數
因為在 OAuth 2.0 交換庫期間,系統預設會填入這些資料。您可以使用
這些變數都能透過 AccessEntity 政策取得
應用程式。
具體的政策設定可能如下所示:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnEr>ror=&<quot;false&>quot; enabled<="true&>quot;< name="GetApp" ><DisplayName>GetAp<pProfile/DisplayName EntityType value="apiproduc>t"<;/EntityType EntityIdentifier ref="developer.app.>na<me" type>="appname"/ SecondaryIdentifier ref="developer.id" type="developerid"/ /AccessEntity
支援的實體類型和 ID
AccessEntity 支援下列實體類型和 ID。
| 實體類型值 | 實體識別碼類型 | 次要 ID 類型 |
|---|---|---|
apiproduct |
appid |
apiresource |
apiproductname |
||
appname |
apiresourcedeveloperemaildeveloperidcompanyname |
|
consumerkey |
apiresource |
|
app |
appid |
|
appname |
developeremaildeveloperidcompanyname |
|
consumerkey |
||
authorizationcode |
authorizationcode |
|
company |
appid |
|
company |
||
consumerkey |
||
companydeveloper |
companyname |
|
consumerkey |
consumerkey |
|
consumerkey_scope |
consumerkey |
|
developer |
appid |
|
consumerkey |
||
developeremail |
||
developerid |
||
requesttoken |
requesttoken |
consumerkey |
verifier |
verifier |
實體個人資料 XML 範例
若要使用 XPath 擷取想要的實體設定檔值,您必須知道 設定檔 XML 的結構舉例來說,如要舉例說明結構,請用 Management API 呼叫 所使用實體的 XML。詳情請參閱 management API 參考資料。
以下各節包含 API 呼叫的程式碼,以及呼叫中的 XML 範例。
應用程式
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/apps/{app_id} \ -u email:password
另請參閱在 「依應用程式 ID 進行機構」,請參閱 Edge Management API 參考資料中的說明。
或:
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/developers/{developer_email}/apps/{app_name} \ -u email:password
另請參閱取得 Edge Management API 參考資料中的開發人員應用程式詳細資料。
個人資料範例:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="ye>s&quo<t;? App na>me=&<quot;thomas>-app&<quot; Ac>cessT<yperead/Acc>essType < ApiProd>ucts/ Cre<dentials > Credent<ial > Attributes/ Con<sumerKeywrqO>OOiPArFI0WRoB<1gAJMRbOguekJ5>w/ConsumerKey < Consu>merSecretWvOh<DrJ8m6kzz7N>i/ConsumerSecret < > ApiProducts < > ApiPro<duct<>/span> N<ameFre>eProduct</Name > < Statusapp>roved/Status < > /ApiProdu<ct > /ApiP<roduct>s < S>copes/ < S>tatus<approved/Sta>tus < /C>redenti<al /Cr>edent<ials<>/span> AppFamilydefault/AppFamily A<ppIdab>308c1<3-bc99-4c5>0-8434-0e<0ed1b8607>5/AppId A<ttri>butes < At>tribute < > NameDisplayName</Name > < ValueTo>m'<;s Weather >App/V<alue > /Attribute /At<tributes > Call<backUrlht>tp://tom.app/<login/Call>backU<rl Cr>eatedAt136250287<2727/Creat>edAt < Created>Byadmin@apigee.c<om/CreatedBy> <DeveloperIdPFK>8IwOeAOW01JKA</DeveloperId > Las<tModifiedAt136>2502872727/LastM<odifiedAt L>astMo<difiedB>yadmi<n@apig>ee.com/L<astModi>f<iedB>y Scopes/ Statusapproved/Status /App
API 產品
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/apiproducts/{apiproduct_name} \ -u email:password
另請參閱取得 API 產品。
XPath 範例,會從名為
weather_free:
/ApiProduct['@name=weather_free']/ApiResources/ApiResource[1]/text()
以 XML 格式傳回的設定檔範例:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? >ApiPr<oduct name=&>quot;weat<her_free&qu>ot; ApiResources < ApiRe>sourc<e/forecastrss>, /re<ports/ApiRes>ourc<e /ApiRes>ource<s Appr>ovalTypea<uto/Appro>valType A<ttri>butes < At>tribute < > Namedescription/Name < > Valu<eIntroduct>ory API P<roduct/Va>lue /<Attr>ibute Attribute < > Namede<velop>e<r.quot>a.interva<l/Name > <Value1/Va>lue /<Attr>ibute Attribu<te > Nam<edeve>l<oper.q>uota.limi<t/Name > <Value1/Va>lue /<Attr>ibute Attribute < > Namede<velop>er.quo<ta.tim>eunit/Nam<e > Value<minute/Va>lue /<Attr>ibute < At>tribute < > Nameservic<ePlan/>Name < Va>lueIn<troductory/>Value< >/Attribute < /Attribu>tes < Create>dAt1355847839224/<CreatedAt > C<reatedByand>rew@apigee.com/C<reatedBy > Desc<riptionFree> API Product/Des<cription > Disp<layNameFree A>PI Pr<oduct/DisplayN>ame Envir<onments/ La>stMod<ifiedAt1355847>839224/LastModifi<edAt LastMo>difie<dByandre>w@api<gee.com>/<LastModifie>dBy Proxies/ Scopes/ /ApiProduct
公司
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/companies/{company_name} \ -u email:password
另請參閱取得 Edge Management API 參考資料中的公司詳細資料。
個人資料範例:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes&>quot;<? Com>pany <name=">theramin" A<pps/ Dis>playN<ameTheramin >Corporati<on/DisplayNam>e < Organ>izatio<napigee>-pm/O<rganizatio>n Sta<tusactive>/Status A<ttri>butes < Att>ribute < > Namebil<ling_c>ode/Name < > Val<ue13648765/>Value< >/Attribute < /Attribu>tes < Create>dAt1349208631291/<CreatedAt > C<reatedByandrew>@apigee.com/C<reatedBy La>stMod<ifiedAt1349208>631291/LastModifi<edAt LastMo>d<ifiedBya>ndrew@apigee.com/LastModifiedBy /Company
公司開發商
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/companies/{company_name}/developers/{developer_name} \ -u email:password
個人資料範例:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalo>ne=&q<uot;yes&q>uot;? Dev<elope>rs Developer < >Emailntes<la@t>heramin.c<om/Em>ail < Rol>e<developer/R>ole /Developer /Developers
消費者金鑰
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/developers/{developer_email}/apps/{app_name}/keys/{consumer_key} \ -u email:password
另請參閱 取得 Edge Management API 參考資料中的開發人員應用程式金鑰詳細資料。
XPath 範例:
/Credential/ApiProducts/ApiProduct[Name='weather_free']/Status/text()
個人資料範例:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalo>ne=&q<uot;yes&quo>t;?
C<redential
> Attributes/
ConsumerKeyXL<otL3PRxNkUGX>hGAFD<POr6fqtvAhuZe/>ConsumerKey
<ConsumerSecreti>NUyEa<OOh96KR3YL/>ConsumerS<ecret
>ApiProducts
< > ApiProduc<t
> Name<weathe>r_free/N<ame
> <Statusappro>ved/S<tatus
> /Ap<iProduc>t
< /ApiP>roducts
< Sco>p<es/
Sta>tusapproved/Status
/Credential開發人員
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/developers/{developer_email} \ -u email:password
另請參閱取得開發人員: Edge Management API 參考資料
XPath 範例:
/Developer/Attributes/Attribute[Name='my_custom_attribute']/Value/text()
/Developer/Email/text()
個人資料範例:
<?xml version="1.0" encoding="UTF-8&quo>t<; standal>one=&<quot>;yes"<;? >Developer < A>pps < >Appweather<appx>/App < > Ap<pweat>herapp/App /App<s >Email<ntesla@ther>amin.com/Email < Developer>Id4Y4<xd0KRZ1wm>HJqu/D<eveloperId> <FirstNam>eNiko<la/FirstN>ame < LastN>ameTesla</LastName> <UserNametheramin>/UserName< Organization>Namea<pigee->pm/Org<anizati>onNam<e Stat>usactive/<Status > Attributes < > Attribut<e > Name<proje>ct_typ<e/Name> < Valuep>ublic</Value > /<Attribute> /Attribu<tes Cr>eated<At1349797>040634/CreatedAt< Creat>edByr<saha@apigee.co>m/CreatedBy < LastModified>At134<9797040634/Las>tModifiedAt <LastModifiedByr>s<aha@apigee>.com/LastModifiedBy /Developer
流程變數
擷取 AccessEntity 政策中指定的實體設定檔時,採用 XML 格式 設定檔物件會以變數的形式加入訊息結構定義中。使用方法與任何其他應用程式相同 變數,並參照變數名稱。使用者提供的 AccessEntity 政策名稱 設為變數名稱的變數前置字串
舉例來說,如果執行名稱為 GetDeveloper 的 AccessEntity 政策,
XML 格式設定檔會儲存在名為
AccessEntity.GetDeveloper。XML 格式設定檔接著可使用
在指定 AccessEntity.GetDeveloper 的 ExtractVariables 政策中定義的 XPath
做為來源
錯誤參考資料
執行階段錯誤
無。
部署錯誤
| 錯誤名稱 | 錯誤字串 | HTTP 狀態 | 發生時機 |
|---|---|---|---|
InvalidEntityType |
Invalid type [entity_type] in ACCESSENTITYStepDefinition
[policy_name] |
不適用 | 使用的實體類型必須是支援的類型之一。 |
相關主題
ExtractVariables:ExtractVariables 政策AssignMessage:AssignMessage 政策