

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

# 管理核准規則範本
<a name="how-to-manage-templates"></a>

您可以在 中管理核准規則範本 AWS 區域 ，以協助了解它們的使用方式及其用途。例如，您可以編輯核准規則範本的名稱和描述，以協助其他人瞭解其用途。您可以在 中列出所有核准規則範本 AWS 區域，並取得範本內容和結構的相關資訊。您可以檢閱哪些範本與儲存庫相關聯，以及哪些儲存庫與範本相關聯。

如需 受管政策和核准規則範本許可的詳細資訊，請參閱 [核准規則範本上動作的許可](auth-and-access-control-permissions-reference.md#aa-art)和 [AWS CodeCommit 的 受管政策](security-iam-awsmanpol.md)。

## 管理核准規則範本 （主控台）
<a name="how-to-manage-template-console"></a>

您可以在 CodeCommit 主控台中檢視和管理核准規則範本。<a name="manage-template-console"></a>

## 管理核准規則範本
<a name="manage-template-console"></a>

1. 在 https：//[https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home) 開啟 CodeCommit 主控台。

1. 選擇**核准規則範本**，以檢視您登入 AWS 區域 所在 中的核准規則範本清單。
**注意**  
核准規則範本只能在建立它們 AWS 區域 的 中使用。

1. 如果您要變更範本，請從清單中選擇範本，然後選擇 **Edit (編輯)**。

1. 進行變更，然後選擇 **Save ** (儲存變更)。

## 管理核准規則範本 (AWS CLI)
<a name="how-to-manage-template-cli"></a>

您可以使用下列 AWS CLI 命令來管理核准規則範本：
+ [**list-approval-rule-templates**](#list-templates)，檢視 中所有核准規則範本的清單 AWS 區域
+ [**get-approval-rule-template**](#get-template)，檢視核准規則範本的內容
+ [**update-approval-rule-template-content**](#update-template-content)，變更核准規則範本的內容
+ [**update-approval-rule-template-name**](#update-template-name)，變更核准規則範本的名稱
+ [**update-approval-rule-template-description**](#update-template-description)，變更核准規則範本的描述
+ [**list-repositories-for-approval-rule-template**](#list-associated-repositories)，檢視與核准規則範本相關聯的所有儲存庫
+ [**list-associated-approval-rule-templates-for-repository**](#list-associated-templates)，檢視與儲存庫相關聯的所有核准規則範本<a name="list-templates"></a>

## 若要列出 中的所有核准規則範本 AWS 區域
<a name="list-templates"></a>

1. 在終端機或命令列上執行 **list-approval-rule-templates** 命令。例如，若要列出美國東部 （俄亥俄） 區域中的所有核准規則範本：

   ```
   aws codecommit list-approval-rule-templates --region us-east-2
   ```

1. 如果此命令成功執行，您會看到類似如下的輸出傳回：

   ```
   {
       "approvalRuleTemplateNames": [
           "2-approver-rule-for-main",
           "1-approver-rule-for-all-pull-requests"
       ]
   }
   ```<a name="get-template"></a>

## 取得核准規則範本的內容
<a name="get-template"></a>

1. 在終端機或命令列，執行 **get-approval-rule-template** 命令，並指定核准規則範本的名稱：

   ```
   aws codecommit get-approval-rule-template --approval-rule-template-name 1-approver-rule-for-all-pull-requests
   ```

1. 如果此命令成功執行，您會看到類似如下的輸出傳回：

   ```
   {
       "approvalRuleTemplate": {
           "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
           "ruleContentSha256": "621181bbEXAMPLE",
           "lastModifiedDate": 1571356106.936,
           "creationDate": 1571356106.936,
           "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests",
           "lastModifiedUser": "arn:aws:iam::123456789012:user/Li_Juan",
           "approvalRuleTemplateId": "a29abb15-EXAMPLE",
           "approvalRuleTemplateDescription": "All pull requests must be approved by one developer on the team."
       }
   }
   ```<a name="update-template-content"></a>

## 更新核准規則範本的內容
<a name="update-template-content"></a>

1. 在終端機或命令提示字元下，執行 **update-approval-rule-template-content** 命令，並指定範本的名稱和變更的內容。例如，變更名為 **1-approver-rule** 的核准規則範本的內容，以將核准集區重新定義為擔任角色 **CodeCommitReview** 的使用者：

   ```
   aws codecommit update-approval-rule-template-content --approval-rule-template-name 1-approver-rule --new-rule-content "{\"Version\": \"2018-11-08\",\"DestinationReferences\": [\"refs/heads/main\"],\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 2,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}"
   ```

1. 如果此命令成功執行，您會看到類似如下的輸出傳回：

   ```
   {
       "approvalRuleTemplate": {
           "creationDate": 1571352720.773,
           "approvalRuleTemplateDescription": "Requires 1 approval for all pull requests from the CodeCommitReview pool",
           "lastModifiedDate": 1571358728.41,
           "approvalRuleTemplateId": "41de97b7-EXAMPLE",
           "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
           "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests",
           "ruleContentSha256": "2f6c21a5EXAMPLE",
           "lastModifiedUser": "arn:aws:iam::123456789012:user/Li_Juan"
       }
   }
   ```<a name="update-template-name"></a>

## 更新核准規則範本的名稱
<a name="update-template-name"></a>

1. 在終端機或命令提示字元下，執行 **update-approval-rule-template-name** 命令，並指定目前名稱和要變成的名稱。例如，將核准規則範本的名稱從 **1-approver-rule** 變更為 **1-approver-rule-for-all-pull-requests**：

   ```
   aws codecommit update-approval-rule-template-name --old-approval-rule-template-name "1-approver-rule" --new-approval-rule-template-name "1-approver-rule-for-all-pull-requests"
   ```

1. 如果此命令成功執行，您會看到類似如下的輸出傳回：

   ```
   {
       "approvalRuleTemplate": {
           "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests",
           "lastModifiedDate": 1571358241.619,
           "approvalRuleTemplateId": "41de97b7-EXAMPLE",
           "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
           "creationDate": 1571352720.773,
           "lastModifiedUser": "arn:aws:iam::123456789012:user/Mary_Major",
           "approvalRuleTemplateDescription": "All pull requests must be approved by one developer on the team.",
           "ruleContentSha256": "2f6c21a5cEXAMPLE"
       }
   }
   ```<a name="update-template-description"></a>

## 更新核准規則範本的描述
<a name="update-template-description"></a>

1. 在終端機或命令列，執行 **update-approval-rule-template-description** 命令，並指定核准規則範本的名稱和新描述：

   ```
   aws codecommit update-approval-rule-template-description --approval-rule-template-name "1-approver-rule-for-all-pull-requests" --approval-rule-template-description "Requires 1 approval for all pull requests from the CodeCommitReview pool" 
   ```

1. 如果此命令成功執行，您會看到類似如下的輸出產生：

   ```
   {
       "approvalRuleTemplate": {
           "creationDate": 1571352720.773,
           "approvalRuleTemplateDescription": "Requires 1 approval for all pull requests from the CodeCommitReview pool",
           "lastModifiedDate": 1571358728.41,
           "approvalRuleTemplateId": "41de97b7-EXAMPLE",
           "approvalRuleTemplateContent": "{\"Version\": \"2018-11-08\",\"Statements\": [{\"Type\": \"Approvers\",\"NumberOfApprovalsNeeded\": 1,\"ApprovalPoolMembers\": [\"arn:aws:sts::123456789012:assumed-role/CodeCommitReview/*\"]}]}",
           "approvalRuleTemplateName": "1-approver-rule-for-all-pull-requests",
           "ruleContentSha256": "2f6c21a5EXAMPLE",
           "lastModifiedUser": "arn:aws:iam::123456789012:user/Li_Juan"
       }
   }
   ```<a name="list-associated-repositories"></a>

## 列出與範本相關聯的所有儲存庫
<a name="list-associated-repositories"></a>

1. 在命令列或終端機，執行 **list-repositories-for-approval-rule-template** 命令，並指定範本的名稱：

   ```
   aws codecommit list-repositories-for-approval-rule-template --approval-rule-template-name 2-approver-rule-for-main
   ```

1. 如果此命令成功執行，您會看到類似如下的輸出傳回：

   ```
   {
       "repositoryNames": [
           "MyDemoRepo",
           "MyClonedRepo"
       ]
   }
   ```<a name="list-associated-templates"></a>

## 列出與儲存庫相關聯的所有範本
<a name="list-associated-templates"></a>

1. 在命令列或終端機，執行 **list-associated-approval-rule-templates-for-repository** 命令，並指定儲存庫的名稱：

   ```
   aws codecommit list-associated-approval-rule-templates-for-repository --repository-name MyDemoRepo
   ```

1. 如果此命令成功執行，您會看到類似如下的輸出傳回：

   ```
   {
       "approvalRuleTemplateNames": [
           "2-approver-rule-for-main",
           "1-approver-rule-for-all-pull-requests"
       ]
   }
   ```