Skip to content

Commit

Permalink
Merge pull request #148 from dt3310321/s3
Browse files Browse the repository at this point in the history
parse canned acl
  • Loading branch information
dt3310321 authored Jan 21, 2021
2 parents d7d513c + 3e32376 commit 23a6336
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions qcloud_cos/cos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ def get_object_acl(self, Bucket, Key, **kwargs):
lst = []
lst.append(data['AccessControlList']['Grant'])
data['AccessControlList']['Grant'] = lst
data['CannedACL'] = parse_object_canned_acl(data, rt.headers)
return data

def restore_object(self, Bucket, Key, RestoreRequest={}, **kwargs):
Expand Down Expand Up @@ -1497,6 +1498,7 @@ def get_bucket_acl(self, Bucket, **kwargs):
lst = []
lst.append(data['AccessControlList']['Grant'])
data['AccessControlList']['Grant'] = lst
data['CannedACL'] = parse_bucket_canned_acl(data)
return data

def put_bucket_cors(self, Bucket, CORSConfiguration={}, **kwargs):
Expand Down
23 changes: 23 additions & 0 deletions qcloud_cos/cos_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,29 @@ def get_date(yy, mm, dd):
return final_date_str


def parse_object_canned_acl(result_acl, rsp_headers):
"""根据ACL返回的body信息,以及default头部来判断CannedACL"""
if "x-cos-acl" in rsp_headers and rsp_headers["x-cos-acl"] == "default":
return "default"
public_read = {'Grantee': {'Type': 'Group', 'URI': 'http://cam.qcloud.com/groups/global/AllUsers'}, 'Permission': 'READ'}
if 'AccessControlList' in result_acl and 'Grant' in result_acl['AccessControlList']:
if public_read in result_acl['AccessControlList']['Grant']:
return "public-read"
return "private"


def parse_bucket_canned_acl(result_acl):
"""根据ACL返回的body信息来判断Bucket CannedACL"""
public_read = {'Grantee': {'Type': 'Group', 'URI': 'http://cam.qcloud.com/groups/global/AllUsers'}, 'Permission': 'READ'}
public_write = {'Grantee': {'Type': 'Group', 'URI': 'http://cam.qcloud.com/groups/global/AllUsers'}, 'Permission': 'WRITE'}
if 'AccessControlList' in result_acl and 'Grant' in result_acl['AccessControlList']:
if public_read in result_acl['AccessControlList']['Grant']:
if public_write in result_acl['AccessControlList']['Grant']:
return "public-read-write"
return "public-read"
return "private"


class CiDetectType():
"""ci内容设备的类型设置,可与操作设多个"""
PORN = 1
Expand Down
2 changes: 1 addition & 1 deletion qcloud_cos/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

__version__ = '5.1.9.1'
__version__ = '5.1.9.2'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def long_description():

setup(
name='cos-python-sdk-v5',
version='1.9.1',
version='1.9.2',
url='https://www.qcloud.com/',
license='MIT',
author='tiedu, lewzylu, channingliu',
Expand Down

0 comments on commit 23a6336

Please sign in to comment.