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 entity 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 dan memasukkannya ke dalam variabel. Anda mengidentifikasi entity yang akan diambil dengan menentukan jenis entity dan satu atau beberapa ID yang menentukan entity jenis tersebut yang Anda inginkan. Selanjutnya, di kebijakan lain, Anda dapat mengambil data profil entitas dengan kebijakan lain, seperti kebijakan ExtractVariables atau kebijakan AssignMessage.

Contoh

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

Mendapatkan email developer untuk digunakan dalam kebijakan lain

Siapkan kebijakan AccessEntity untuk menentukan profil entitas mana yang akan diambil dari Edge, serta tempat untuk menempatkan data profil.

Dalam contoh berikut, kebijakan mendapatkan profil entity developer, menggunakan kunci API yang diteruskan sebagai parameter kueri untuk mengidentifikasi developer. Profil ditempatkan dalam variabel yang namanya mengikuti bentuk AccessEntity.{policy_name}. Jadi, variabel yang ditetapkan oleh kebijakan ini adalah AccessEntity.GetDeveloperProfile.

<AccessEntity name="GetDeveloperProfile">
  <!-- This is the type entity whose profile we need to pull from the Edge datastore. -->
  <EntityType  value="developer"/>
  <!-- We tell the policy to use the API key (presented as query parameter) to identify the developer. -->
  <EntityIdentifier ref="request.queryparam.apikey" type="consumerkey"/> 
</AccessEntity>

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

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

Perhatikan bahwa nilai yang diambil ditentukan sebagai ekspresi XPath dalam elemen XMLPayload. Nilai yang diekstrak ditempatkan dalam variabel developer.email.

<ExtractVariables name="SetDeveloperProfile">
  <!-- The source element points to the variable populated by AccessEntity policy. 
  The format is <policy-type>.<policy-name>.
  In this case, the variable contains the whole developer profile. -->
  <Source>AccessEntity.GetDeveloperProfile</Source> 
  <VariablePrefix>developer</VariablePrefix>
  <XMLPayload>
    <Variable name="email" type="string"> 
        <!-- You parse elements from the developer profile using XPath. -->
      <XPath>/Developer/Email</XPath>
    </Variable>
  </XMLPayload>
</ExtractVariables>

Kebijakan AssignMessage 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="EchoVariables">
  <AssignTo createNew="false" type="response"></AssignTo>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <Set>
    <Headers>
      <Header name="X-Developer-email">{developer.email}</Header>
    </Headers>
  </Set>
</AssignMessage>

Referensi elemen

Struktur dasar kebijakan AccessEntity adalah:

<AccessEntity name="policy_name">
  <EntityType  value="entity_type"/>
  <EntityIdentifier ref="entity_identifier" type="identifier_type"/> 
  <SecondaryIdentifier ref="secondary_identifier" type="identifier_type"/>
</AccessEntity>

Anda dapat mengakses beberapa entity dengan jenis yang sama dengan mengelompokkannya dalam elemen Identifiers:

<AccessEntity name="name_of_the_policy">
  <EntityType  value="type_of_entity"/>
  <Identifiers>
    <Identifier>
      <EntityIdentifier ref="reference_to_entity_identifier" type*="identifier_type"/> 
      <SecondaryIdentifier ref="reference_to_secondary_entity_identifier" type="identifier_type"/><!-- optional -->
    </Identifier >
    <Identifier>
      <EntityIdentifier ref="reference_to_entity_identifier" type*="identifier_type"/> 
      <SecondaryIdentifier ref="reference_to_secondary_entity_identifier" type="identifier_type"/><!-- optional -->
    </Identifier >
  </Identifiers>
</AccessEntity>

Atribut <AccessEntity>

<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

Elemen <EntityIdentifier>

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

<EntityIdentifier ref="value_variable" type="identifier_type"/> 

Default

T/A

Kehadiran

Wajib

Jenis

String

Atribut

Atribut Deskripsi Default Ketersediaan Jenis
ref

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 Jenis dan ID entitas untuk daftar nilai. Wajib. String

Contoh

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="GetCompany">
    <DisplayName>GetCompanyProfile</DisplayName>
    <EntityType value="company"></EntityType>
    <EntityIdentifier ref="request.queryparam.apikey" type="consumerkey"/>
</AccessEntity>

Elemen <EntityType>

Menentukan jenis entity yang akan diambil dari penyimpanan data.

<EntityType  value="entity_type"/>

Default

T/A

Kehadiran

Wajib

Jenis

String

Gunakan elemen EntityIdentifier untuk menentukan entitas jenis tertentu yang Anda inginkan. Untuk mengetahui referensi jenis entitas, lihat Jenis dan ID entitas.

Atribut

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

Elemen <SecondaryIdentifier>

Bersama dengan EntityIdentifier, menentukan nilai untuk mengidentifikasi instance yang diinginkan dari EntityType tertentu.

<SecondaryIdentifier ref="value_variable" type="identifier_type"/>

Default

T/A

Kehadiran

Opsional

Jenis

String

Penggunaan SecondaryIdentifier saat hanya menentukan EntityIdentifier tidak akan menjamin bahwa Anda mendapatkan satu entitas. Lihat Mempersempit hasil dengan ID sekunder untuk mengetahui informasi selengkapnya.

Penggunaan beberapa elemen SecondaryIdentifier tidak didukung.

Atribut

Atribut Deskripsi Default Ketersediaan Jenis
ref

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 Jenis dan ID entitas untuk daftar nilai. Wajib. String

Contoh

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="GetAPIProduct">
    <DisplayName>GetAPIProduct</DisplayName>
    <EntityType value="apiproduct"></EntityType>
    <EntityIdentifier ref="developer.app.name" 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 yang Anda inginkan. Dalam kasus tersebut, Anda dapat menggunakan ID sekunder untuk mempersempit hasil.

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

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="GetApp">
    <DisplayName>GetAppProfile</DisplayName>
    <EntityType value="apiproduct"></EntityType>
    <EntityIdentifier ref="request.queryparam.apikey" type="consumerkey"/>
</AccessEntity>

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

Sebagai gantinya, untuk mendapatkan hasil yang lebih tepat, Anda dapat menggunakan SecondaryIdentifier. Misalnya, Anda mungkin memiliki variabel appname dan developerid dalam alur karena variabel ini diisi secara default selama pertukaran OAuth 2.0. Anda dapat menggunakan nilai variabel tersebut dalam kebijakan AccessEntity untuk mendapatkan detail profil di aplikasi yang meminta.

Konfigurasi kebijakan yang lebih spesifik mungkin terlihat seperti ini:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AccessEntity async="false" continueOnError="false" enabled="true" name="GetApp">
    <DisplayName>GetAppProfile</DisplayName>
    <EntityType value="apiproduct"></EntityType>
    <EntityIdentifier ref="developer.app.name" type="appname"/> 
    <SecondaryIdentifier ref="developer.id" type="developerid"/> 
</AccessEntity>

Jenis dan ID entity yang didukung

AccessEntity mendukung jenis dan ID entitas 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 entitas

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

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

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 dalam Organisasi menurut ID Aplikasi dalam referensi Edge Management API.

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 di referensi API Edge Management.

Contoh profil:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<App name="thomas-app">
    <AccessType>read</AccessType>
    <ApiProducts/>
    <Credentials>
        <Credential>
            <Attributes/>
            <ConsumerKey>wrqOOOiPArFI0WRoB1gAJMRbOguekJ5w</ConsumerKey>
            <ConsumerSecret>WvOhDrJ8m6kzz7Ni</ConsumerSecret>
            <ApiProducts>
                <ApiProduct>
                    <Name>FreeProduct</Name>
                    <Status>approved</Status>
                </ApiProduct>
            </ApiProducts>
            <Scopes/>
            <Status>approved</Status>
        </Credential>
    </Credentials>
    <AppFamily>default</AppFamily>
    <AppId>ab308c13-bc99-4c50-8434-0e0ed1b86075</AppId>
    <Attributes>
        <Attribute>
            <Name>DisplayName</Name>
            <Value>Tom's Weather App</Value>
        </Attribute>
    </Attributes>
    <CallbackUrl>http://tom.app/login</CallbackUrl>
    <CreatedAt>1362502872727</CreatedAt>
    <CreatedBy>admin@apigee.com</CreatedBy>
    <DeveloperId>PFK8IwOeAOW01JKA</DeveloperId>
    <LastModifiedAt>1362502872727</LastModifiedAt>
    <LastModifiedBy>admin@apigee.com</LastModifiedBy>
    <Scopes/>
    <Status>approved</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 Produk API di 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()

Contoh profil yang ditampilkan sebagai XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ApiProduct name="weather_free">
    <ApiResources>
        <ApiResource>/forecastrss, /reports</ApiResource>
    </ApiResources>
    <ApprovalType>auto</ApprovalType>
    <Attributes>
        <Attribute>
            <Name>description</Name>
            <Value>Introductory API Product</Value>
        </Attribute>
        <Attribute>
            <Name>developer.quota.interval</Name>
            <Value>1</Value>
        </Attribute>
        <Attribute>
            <Name>developer.quota.limit</Name>
            <Value>1</Value>
        </Attribute>
        <Attribute>
            <Name>developer.quota.timeunit</Name>
            <Value>minute</Value>
        </Attribute>
        <Attribute>
            <Name>servicePlan</Name>
            <Value>Introductory</Value>
        </Attribute>
    </Attributes>
    <CreatedAt>1355847839224</CreatedAt>
    <CreatedBy>andrew@apigee.com</CreatedBy>
    <Description>Free API Product</Description>
    <DisplayName>Free API Product</DisplayName>
    <Environments/>
    <LastModifiedAt>1355847839224</LastModifiedAt>
    <LastModifiedBy>andrew@apigee.com</LastModifiedBy>
    <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 di referensi Edge Management API.

Contoh profil:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Company name="theramin">
    <Apps/>
    <DisplayName>Theramin Corporation</DisplayName>
    <Organization>apigee-pm</Organization>
    <Status>active</Status>
    <Attributes>
        <Attribute>
            <Name>billing_code</Name>
            <Value>13648765</Value>
        </Attribute>
    </Attributes>
    <CreatedAt>1349208631291</CreatedAt>
    <CreatedBy>andrew@apigee.com</CreatedBy>
    <LastModifiedAt>1349208631291</LastModifiedAt>
    <LastModifiedBy>andrew@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" standalone="yes"?>
<Developers>
    <Developer>
        <Email>ntesla@theramin.com</Email>
        <Role>developer</Role>
    </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 di referensi Edge Management API.

Contoh XPath:

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

Contoh profil:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Credential>
    <Attributes/>
    <ConsumerKey>XLotL3PRxNkUGXhGAFDPOr6fqtvAhuZe</ConsumerKey>
    <ConsumerSecret>iNUyEaOOh96KR3YL</ConsumerSecret>
    <ApiProducts>
        <ApiProduct>
            <Name>weather_free</Name>
            <Status>approved</Status>
        </ApiProduct>
    </ApiProducts>
    <Scopes/>
    <Status>approved</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 Get Developer di referensi API Edge Management.

Contoh XPath:

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

Contoh profil:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Developer>
    <Apps>
        <App>weatherappx</App>
        <App>weatherapp</App>
    </Apps>
    <Email>ntesla@theramin.com</Email>
    <DeveloperId>4Y4xd0KRZ1wmHJqu</DeveloperId>
    <FirstName>Nikola</FirstName>
    <LastName>Tesla</LastName>
    <UserName>theramin</UserName>
    <OrganizationName>apigee-pm</OrganizationName>
    <Status>active</Status>
    <Attributes>
        <Attribute>
            <Name>project_type</Name>
            <Value>public</Value>
        </Attribute>
    </Attributes>
    <CreatedAt>1349797040634</CreatedAt>
    <CreatedBy>rsaha@apigee.com</CreatedBy>
    <LastModifiedAt>1349797040634</LastModifiedAt>
    <LastModifiedBy>rsaha@apigee.com</LastModifiedBy>
</Developer>

Variabel alur

Saat profil entitas yang ditentukan dalam kebijakan AccessEntity diambil, objek profil berformat XML ditambahkan ke konteks pesan sebagai variabel. Variabel ini dapat diakses seperti variabel lainnya, dengan merujuk ke nama variabel. Nama kebijakan AccessEntity yang diberikan pengguna ditetapkan sebagai awalan variabel dari nama variabel.

Misalnya, jika kebijakan AccessEntity dengan nama GetDeveloper dijalankan, profil berformat XML akan disimpan dalam variabel bernama AccessEntity.GetDeveloper. Profil berformat XML kemudian dapat diuraikan menggunakan 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