

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Amazon Verified Permissions 政策存放區結構描述
<a name="schema"></a>

*[結構描述](https://docs.cedarpolicy.com/overview/terminology.html#schema)*是應用程式所支援實體類型的結構宣告，以及應用程式在授權請求中可能提供的動作。若要查看 Verified Permissions 和 Cedar 如何處理結構描述之間的差異，請參閱 [結構描述支援](terminology-differences-avp-cedar.md#differences-templates)。

如需詳細資訊，請參閱[《 Cedar 政策語言參考指南》中的 Cedar 結構描述格式](https://docs.cedarpolicy.com/schema/schema.html)。

**注意**  
在 Verified Permissions 中使用結構描述是選用的，但強烈建議用於生產軟體。當您建立新的政策時，Verified Permissions 可以使用結構描述來驗證範圍和條件中參考的實體和屬性，以避免可能導致混淆系統行為的政策錯誤。如果您啟用[政策驗證](policy-validation-mode.md)，則所有新政策必須符合結構描述。

------
#### [ AWS 管理主控台 ]

**建立結構描述**

1. 開啟 [Verified Permissions 主控台](https://console.aws.amazon.com/verifiedpermissions/)。選擇您的政策存放區。

1. 在左側導覽窗格中，選擇**結構描述**。

1. 選擇**建立結構描述**。

------
#### [ AWS CLI ]

**若要提交新的結構描述，或使用 覆寫現有的結構描述 AWS CLI。**  
您可以執行類似下列範例的 AWS CLI 命令來建立政策存放區。

請考慮包含下列 Cedar 內容的結構描述：

```
{
    "MySampleNamespace": {
        "actions": {
            "remoteAccess": {
                "appliesTo": {
                    "principalTypes": [ "Employee" ]
                }
            }
        },
        "entityTypes": {
            "Employee": {
                "shape": {
                    "type": "Record",
                    "attributes": {
                        "jobLevel": {"type": "Long"},
                        "name": {"type": "String"}
                    }
                }
            }
        }
    }
}
```

您必須先將 JSON 逸出至單一行字串，並在 JSON 前面加上其資料類型的宣告：`cedarJson`。下列範例使用下列`schema.json`檔案內容，其中包含 JSON 結構描述的逸出版本。

**注意**  
此處的範例為可讀性換行。您必須在單行中擁有整個檔案，命令才能接受它。

```
{"cedarJson": "{\"MySampleNamespace\": {\"actions\": {\"remoteAccess\": {\"appliesTo\": 
{\"principalTypes\": [\"Employee\"]}}},\"entityTypes\": {\"Employee\": {\"shape\": 
{\"attributes\": {\"jobLevel\": {\"type\": \"Long\"},\"name\": {\"type\": \"String\"}},
\"type\": \"Record\"}}}}}"}
```

```
$ aws verifiedpermissions put-schema \
    --definition file://schema.json \
    --policy-store PSEXAMPLEabcdefg111111
{
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "namespaces": [
        "MySampleNamespace"
    ],
    "createdDate": "2023-07-17T21:07:43.659196+00:00",
    "lastUpdatedDate": "2023-08-16T17:03:53.081839+00:00"
}
```

------
#### [ AWS SDKs ]

您可以使用 `PutSchema` API 建立政策存放區。如需詳細資訊，請參閱《Amazon Verified Permissions API 參考指南》中的 [PutSchema](https://docs.aws.amazon.com/verifiedpermissions/latest/apireference/API_PutSchema.html)。

------