本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Amazon Verified Permissions 中的实体格式设置
Amazon Verified Permissions 使用 Cedar 策略语言来创建策略。策略的语法和支持的数据类型与《Cedar 策略语言参考指南》Cedar 中的基本策略构造
Verified Permissions 中实体的 JSON 格式与 Cedar 有以下不同:
-
在 Verified Permissions 中,JSON 对象必须将其所有键值对包装在名为
Record
的 JSON 对象中。 -
Verified Permissions 中的 JSON 列表必须包装在 JSON 键值对中,其中,键名称为
Set
,值为来自 Cedar 的原始 JSON 列表。 -
对于
String
、Long
和Boolean
类型名称,在 Verified Permissions 中,Cedar 中的每个键值对都会被替换为 JSON 对象。该对象的名称是原始键名称。在 JSON 对象中,有一个键值对,其中键名称是标量值(String
、Long
或Boolean
)的类型名称,值是来自 Cedar 实体的值。 -
Cedar 实体和 Verified Permissions 实体的语法格式存在以下不同:
Cedar 格式 Verified Permissions 格式 uid
Identifier
type
EntityType
id
EntityId
attrs
Attributes
parents
Parents
以下示例显示了如何使用 Cedar 设置列表中实体的格式。
[ { "number": 1 }, { "sentence": "Here is an example sentence" }, { "Question": false } ]
以下示例显示了前面 Cedar 列表示例中的相同实体在 Verified Permissions 中的格式。
{ "Set": [ { "Record": { "number": { "Long": 1 } } }, { "Record": { "sentence": { "String": "Here is an example sentence" } } }, { "Record": { "question": { "Boolean": false } } } ] }
以下示例显示了在授权请求中评估策略时,如何设置 Cedar 实体的格式。
[ { "uid": { "type": "PhotoApp::User", "id": "alice" }, "attrs": { "age": 25, "name": "alice", "userId": "123456789012" }, "parents": [ { "type": "PhotoApp::UserGroup", "id": "alice_friends" }, { "type": "PhotoApp::UserGroup", "id": "AVTeam" } ] }, { "uid": { "type": "PhotoApp::Photo", "id": "vacationPhoto.jpg" }, "attrs": { "private": false, "account": { "__entity": { "type": "PhotoApp::Account", "id": "ahmad" } } }, "parents": [] }, { "uid": { "type": "PhotoApp::UserGroup", "id": "alice_friends" }, "attrs": {}, "parents": [] }, { "uid": { "type": "PhotoApp::UserGroup", "id": "AVTeam" }, "attrs": {}, "parents": [] } ]
以下示例显示了前面 Cedar 示例中的相同实体在 Verified Permissions 中的格式。
[ { "Identifier": { "EntityType": "PhotoApp::User", "EntityId": "alice" }, "Attributes": { "age": { "Long": 25 }, "name": { "String": "alice" }, "userId": { "String": "123456789012" } }, "Parents": [ { "EntityType": "PhotoApp::UserGroup", "EntityId": "alice_friends" }, { "EntityType": "PhotoApp::UserGroup", "EntityId": "AVTeam" } ] }, { "Identifier": { "EntityType": "PhotoApp::Photo", "EntityId": "vacationPhoto.jpg" }, "Attributes": { "private": { "Boolean": false }, "account": { "EntityIdentifier": { "EntityType": "PhotoApp::Account", "EntityId": "ahmad" } } }, "Parents": [] }, { "Identifier": { "EntityType": "PhotoApp::UserGroup", "EntityId": "alice_friends" }, "Parents": [] }, { "Identifier": { "EntityType": "PhotoApp::UserGroup", "EntityId": "AVTeam" }, "Parents": [] } ]