• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Python SDK)
  4. Bucket-Related APIs
  5. PUT Bucket acl

PUT Bucket acl

API Description

You can use this API to set the ACL for a bucket.

Method Definition

ObsClient.setBucketAcl(bucketName, acl, aclControl)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

acl

ACL

Optional

Bucket ACL

aclControl

str

Optional

Pre-defined access policy. Possible values are:

  • private
  • public-read
  • public-read-write
  • authenticated-read
  • bucket-owner-read
  • bucket-owner-full-control
  • log-delivery-write
NOTE:

acl is mutually exclusive with aclControl.

Returned Result

Type

Description

GetResult

SDK common result object

Sample Code

try:
    from com.obs.models.acl import ACL 
    from com.obs.models.owner import Owner 
    from com.obs.models.grantee import Grantee 
    from com.obs.models.grant import Grant 
     
    owner = Owner(owner_id='onwerid', owner_name='ownername') 
     
    grantee1 = Grantee(grantee_id='userid', grantee_name='username') 
    grantee2 = Grantee(group='http://acs.amazonaws.com/groups/s3/LogDelivery') 
     
    grant1 = Grant(grantee=grantee1, permission='READ') 
    grant2 = Grant(grantee=grantee1, permission='WRITE') 
    grant3 = Grant(grantee=grantee2, permission='WRITE') 
    grant4 = Grant(grantee=grantee2, permission='READ_ACP') 
     
    acl = ACL(owner=owner, grants=[grant1, grant2, grant3, grant4]) 
     
    resp = obsClient.setBucketAcl('bucketname', acl) 
     
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())