Kebijakan AccessEntity

Anda sedang melihat dokumentasi Apigee Edge.
Buka Dokumentasi Apigee X.
info

Apa

Mengambil profil entity yang Anda tentukan dari penyimpanan data Apigee Edge. Kebijakan ini menempatkan profil dalam variabel yang namanya mengikuti format AccessEntity.{policy_name}. Anda dapat menggunakan AccessEntity untuk mengakses profil entitas berikut:

  • Aplikasi
  • Produk API
  • Perusahaan
  • Developer perusahaan
  • Kunci konsumen
  • Developer

Kebijakan AccessEntity berfungsi sebagai pencarian database runtime berbasis kebijakan. Anda dapat menggunakan informasi profil yang ditampilkan oleh kebijakan ini untuk mengaktifkan perilaku dinamis, seperti perutean endpoint bersyarat, eksekusi alur, penerapan kebijakan.

Anda menggunakan kebijakan AccessEntity untuk mendapatkan data profil entitas sebagai XML, lalu masukkan ke dalam variabel. Anda mengidentifikasi entity yang akan didapatkan dengan menentukan entity dan satu atau beberapa pengenal yang menentukan entitas mana dari jenis itu yang Anda inginkan. Nanti, di kebijakan lain, Anda dapat mengambil data profil entitas dengan kebijakan lain, seperti Kebijakan ExtractVariables atau kebijakan MenetapkanMessage.

Contoh

Contoh berikut menunjukkan AccessEntity yang digunakan bersama dengan Kebijakan ExtractVariables dan AssignMessage untuk mengekstrak kebijakan dan menambahkannya ke header HTTP.

Mendapatkan email developer untuk digunakan dalam kebijakan lain

Menyiapkan kebijakan AccessEntity untuk menentukan profil entitas yang akan diambil Edge, serta tempat untuk meletakkan data profil.

Pada contoh berikut, kebijakan mendapatkan profil entity developer, menggunakan Kunci API diteruskan sebagai parameter kueri untuk mengidentifikasi developer. Profil ditempatkan dalam variabel yang namanya mengikuti bentuk AccessEntity.{policy_name}. Jadi variabel yang disetel oleh kebijakan ini adalah 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

Gunakan kebijakan lain untuk mengambil nilai profil entitas dari variabel yang ditetapkan oleh AccessEntity.

Dalam contoh berikut, kebijakan ExtractVariables mengambil nilai dari variabel AccessEntity.GetDeveloperProfile yang ditetapkan sebelumnya dengan AccessEntity.

Perhatikan bahwa nilai yang diambil ditetapkan sebagai ekspresi XPath dalam Elemen XMLPayload. Nilai yang diekstrak ditempatkan dalam kolom Variabel 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

Kebijakan TetapkanMessage berikut mengambil email developer yang ditetapkan oleh Kebijakan 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

Referensi elemen

Dasar struktur kebijakan AccessEntity adalah:

<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

Anda dapat mengakses beberapa entitas yang jenisnya sama dengan mengelompokkannya dalam Elemen 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

&lt;AccessEntity&gt; atribut

<AccessEntity async="false" continueOnError="false" enabled=">;true" name="policy_name"

Tabel berikut menjelaskan atribut yang umum untuk semua elemen induk kebijakan:

Atribut Deskripsi Default Ketersediaan
name

Nama internal kebijakan. Nilai atribut name dapat berisi huruf, angka, spasi, tanda hubung, garis bawah, dan titik. Nilai ini tidak boleh melebihi 255 karakter.

Secara opsional, gunakan elemen <DisplayName> untuk memberi label kebijakan di editor proxy UI pengelolaan dengan nama natural language yang berbeda.

T/A Wajib
continueOnError

Tetapkan ke false untuk menampilkan error saat kebijakan gagal. Diharapkan untuk sebagian besar kebijakan.

Setel ke true agar eksekusi alur dapat dilanjutkan bahkan setelah kebijakan gagal.

salah Opsional
enabled

Setel ke true untuk menerapkan kebijakan.

Setel ke false untuk menonaktifkan kebijakan. Kebijakan ini tidak akan ditegakkan meskipun tetap terikat pada alur.

true Opsional
async

Atribut ini tidak digunakan lagi.

salah Tidak digunakan lagi

&lt;DisplayName&gt; elemen

Gunakan selain atribut name untuk memberi label kebijakan di editor proxy UI dengan nama natural language yang berbeda.

<DisplayName>Policy Display Name</DisplayName>
Default

T/A

Jika Anda menghapus elemen ini, nilai atribut name kebijakan akan menjadi data

Ketersediaan Opsional
Jenis String

&lt;EntityIdentifier&gt; elemen

Menentukan entity tertentu -- dari jenis yang diberikan dalam EntityType -- yang akan didapatkan.

<EntityIdentifier ref="value_variable" type="id>entifier_type"/ 

Default

T/A

Kehadiran

Wajib

Jenis

String

Atribut

Atribut Deskripsi Default Ketersediaan Jenis
referensi

Variabel yang menyediakan sumber ID, seperti request.queryparam.apikey.

T/A Wajib. String
jenis Jenis yang diisi oleh variabel dalam atribut ref. seperti consumerkey. Lihat ID dan jenis entitas untuk sebuah daftar nilai. Wajib. String

Contoh

<?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

&lt;EntityType&gt; elemen

Menentukan jenis entity yang akan diambil dari penyimpanan data.

<EntityType  value="entity_t>ype"/

Default

T/A

Kehadiran

Wajib

Jenis

String

Gunakan elemen EntityIdentifier untuk menentukan entitas mana dari jenis yang diberikan yang Anda inginkan. Untuk referensi tentang jenis entitas, lihat Jenis dan ID entitas.

Atribut

Atribut Deskripsi Default Ketersediaan Jenis
nilai Salah satu jenis entity yang didukung. Lihat Jenis entitas dan ID untuk sebuah daftar. Tidak ada. Wajib. String

&lt;SecondaryIdentifier&gt; elemen

Bersamaan dengan EntityIdentifier, tentukan nilai untuk mengidentifikasi nilai yang diinginkan instance dari EntityType yang diberikan.

<SecondaryIdentifier ref="value_variable" type="id>entifier_type"/

Default

T/A

Kehadiran

Opsional

Jenis

String

Gunakan SecondaryIdentifier saat menentukan EntityIdentifier saja tidak akan menjamin bahwa Anda mendapatkan satu entitas. Lihat Penyempitan hasil dengan ID sekunder untuk mengetahui informasi selengkapnya.

Penggunaan beberapa elemen SecondaryIdentifier tidak didukung.

Atribut

Atribut Deskripsi Default Ketersediaan Jenis
referensi

Variabel yang menyediakan sumber ID, seperti request.queryparam.apikey.

T/A Wajib. String
jenis Jenis yang diisi oleh variabel dalam atribut ref. seperti consumerkey. Lihat ID dan jenis entitas untuk sebuah daftar nilai. Wajib. String

Contoh

<?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

Catatan penggunaan

Mempersempit hasil dengan ID sekunder

Untuk beberapa entitas, memberikan satu ID mungkin tidak cukup spesifik untuk mendapatkan entitas kita inginkan. Dalam kasus tersebut, Anda dapat menggunakan ID sekunder untuk mempersempit hasil.

Konfigurasi kebijakan pertama Anda yang mungkin luas mungkin terlihat seperti ini:

<?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

Karena aplikasi dapat dikaitkan dengan beberapa produk API, menggunakan ID aplikasi saja mungkin tidak mengembalikan produk API yang Anda inginkan (Anda bisa mendapatkan yang pertama dari beberapa produk yang cocok).

Sebagai gantinya, untuk mendapatkan hasil yang lebih tepat, Anda dapat menggunakan SecondaryIdentifier. Sebagai Misalnya, Anda mungkin memiliki variabel appname dan developerid dalam flow karena ini diisi secara {i>default<i} selama pertukaran OAuth 2.0. Anda bisa menggunakan nilai-nilai variabel tersebut dalam kebijakan AccessEntity untuk mendapatkan detail profil tentang permintaan .

Konfigurasi kebijakan Anda yang lebih spesifik mungkin terlihat seperti ini:

<?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

Jenis dan ID entity yang didukung

AccessEntity mendukung jenis dan ID entity berikut.

Nilai EntityType Jenis EntityIdentifier Jenis SecondaryIdentifier
apiproduct appid apiresource
apiproductname
appname apiresource
developeremail
developerid
companyname
consumerkey apiresource
app appid
appname developeremail
developerid
companyname
consumerkey
authorizationcode authorizationcode
company appid
company
consumerkey
companydeveloper companyname
consumerkey consumerkey
consumerkey_scope consumerkey
developer appid
consumerkey
developeremail
developerid
requesttoken requesttoken consumerkey
verifier verifier

Contoh XML profil entity

Untuk mengambil nilai profil entitas yang Anda inginkan dengan XPath, Anda harus mengetahui struktur XML profil. Untuk contoh struktur, gunakan panggilan API pengelolaan untuk mendapatkan XML untuk entitas yang Anda inginkan. Untuk mengetahui detailnya, lihat management API .

Bagian berikut menyertakan kode untuk panggilan API, beserta contoh XML dari panggilan tersebut.

Aplikasi

$ curl -H "Accept:text/xml" -X GET \
https://api.enterprise.apigee.com/v1/o/{org_name}/apps/{app_id} \
-u email:password

Lihat juga Mendapatkan Aplikasi di Pengaturan berdasarkan ID Aplikasi dalam referensi API pengelolaan Edge.

Atau:

$ 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

Lihat juga Mendapatkan Detail Aplikasi Developer dalam referensi API pengelolaan Edge.

Contoh profil:

<?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

Produk API

$ curl  -H "Accept:text/xml" -X GET \
https://api.enterprise.apigee.com/v1/o/{org_name}/apiproducts/{apiproduct_name} \
-u email:password

Lihat juga Mendapatkan API Produk dalam referensi API pengelolaan Edge.

Contoh XPath, mengambil resource API (URI) kedua dari produk API bernama weather_free:

/ApiProduct['@name=weather_free']/ApiResources/ApiResource[1]/text()

Profil contoh yang ditampilkan dalam bentuk 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

Perusahaan

$ curl   -H "Accept:text/xml" -X GET \
https://api.enterprise.apigee.com/v1/o/{org_name}/companies/{company_name} \
-u email:password

Lihat juga Mendapatkan Detail Perusahaan dalam referensi API pengelolaan Edge.

Contoh profil:

<?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

Developer perusahaan

$ 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

Contoh profil:

<?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

Kunci konsumen

$ 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

Lihat juga Mendapatkan Detail Kunci untuk Aplikasi Developer dalam referensi API pengelolaan Edge.

Contoh XPath:

/Credential/ApiProducts/ApiProduct[Name='weather_free']/Status/text()

Contoh profil:

<?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

Developer

$ curl -H "Accept:text/xml" -X GET \
https://api.enterprise.apigee.com/v1/o/{org_name}/developers/{developer_email} \
-u email:password

Lihat juga Dapatkan Developer di referensi API pengelolaan Edge.

Contoh XPath:

/Developer/Attributes/Attribute[Name='my_custom_attribute']/Value/text()
/Developer/Email/text()

Contoh profil:

<?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

Variabel flow

Saat profil entity yang ditentukan dalam kebijakan AccessEntity diambil, file berformat XML objek profil ditambahkan ke konteks pesan sebagai variabel. Data ini dapat diakses seperti variabel, dengan referensi ke nama variabel. Nama kebijakan AccessEntity yang diberikan pengguna ditetapkan sebagai awalan variabel dari nama variabel.

Misalnya, jika kebijakan AccessEntity dengan nama GetDeveloper dijalankan, maka profil berformat XML disimpan dalam variabel bernama AccessEntity.GetDeveloper. Profil berformat XML kemudian dapat diurai menggunakan atribut XPath yang ditentukan dalam kebijakan ExtractVariables yang menentukan AccessEntity.GetDeveloper sebagai sumbernya.

Referensi error

Untuk informasi terkait, lihat Yang perlu Anda ketahui tentang error kebijakan dan Menangani error.

Error runtime

Tidak ada.

Error saat deployment

Nama error String error Status HTTP Terjadi saat
InvalidEntityType Invalid type [entity_type] in ACCESSENTITYStepDefinition [policy_name] T/A Jenis entitas yang digunakan harus berupa salah satu jenis yang didukung.

Topik terkait