
# 设置桶ACL
#### 功能说明
设置桶的访问权限。
#### 方法定义
```
1. ObsClient->setBucketAcl(array $parameter)
2. ObsClient->setBucketAclAsync(array $parameter, callable $callback)
```
#### 请求参数
| **字段名**    ||| **类型**            | **约束**                           | **说明**                                                                               |
|:--|---|---|:---|:---|:---|
| Bucket     ||| string            | 必选                               | 桶名。                                                                                  |
| ACL        ||| string            | 可选                               | [预定义访问策略](https://support.huaweicloud.com/api-obs_php_sdk_api_zh/obs_38_0204.html)。  |
| Owner      ||| associative array | 可选                               | 桶的所有者。                                                                               |
| - | ID      || string            | 必选                               | 桶所有者的DomainId。                                                                       |
| - | DisplayName || string            | 可选                               | 桶所有者的名字。                                                                             |
| Grants     ||| indexed array     | 可选                               | 被授权用户权限信息列表。                                                                         |
| - | Grantee || associative array | 必选                               | 被授权用户。                                                                               |
| - | - | Type | string            | 必选                               | 被授权的[用户类型](https://support.huaweicloud.com/api-obs_php_sdk_api_zh/obs_38_0203.html)。 |
| - | - | ID   | string            | 如果Type为"CanonicalUser"则必选，否则必须为空 | 被授权用户的DomainId。                                                                      |
| - | - | URI  | string            | 如果Type为"Group"则必选，否则必须为空         | 被授权的[用户组](https://support.huaweicloud.com/api-obs_php_sdk_api_zh/obs_38_0202.html)。  |
| - | Permission || string            | 必选                               | 被授予的[权限](https://support.huaweicloud.com/api-obs_php_sdk_api_zh/obs_38_0201.html)。   |
| - | Delivered || boolean           | 可选                               | 桶内对象ACL是否继承桶的ACL。                                                                    |
   
![](https://support.huaweicloud.com/api-obs_php_sdk_api_zh/public_sys-resources/note_3.0-zh-cn.png)
- Owner和Grants必须配套使用，且与ACL互斥。当设置了这两个字段时，不能设置ACL；反之，当设置了ACL时，不能设置Owner和Grants。
- Owner、Grants与ACL不能全为空。
 
#### 返回结果
| **字段名**        | **类型**  | **说明**         |
|:---|:---|:---|
| HttpStatusCode | integer | HTTP状态码。       |
| Reason         | string  | HTTP文本描述。      |
| RequestId      | string  | OBS服务端返回的请求ID。 |
   
#### 代码样例
```
try{
       $resp = $obsClient -> setBucketAcl([
              'Bucket' => 'bucketname',
              'Owner' => ['ID' => 'ownerid', 'DisplayName' => 'ownername'],
              'Grants' => [
                     ['Grantee' => ['Type' => 'CanonicalUser', 'ID' => 'userid'], 'Permission' => ObsClient::PermissionRead],
                     ['Grantee' => ['Type' => 'CanonicalUser', 'ID' => 'userid'], 'Permission' => ObsClient::PermissionWrite],
                     ['Grantee' => ['Type' => 'Group', 'URI' => ObsClient::GroupLogDelivery], 'Permission' => ObsClient::PermissionWrite],
                     ['Grantee' => ['Type' => 'Group', 'URI' => ObsClient::GroupLogDelivery], 'Permission' => ObsClient::PermissionReadAcp],
              ]
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
}catch (Obs\Common\ObsException $obsException){
       printf("ExceptionCode:%s\n", $obsException->getExceptionCode());              
       printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
}
```
