Skip to content

Commit 23a6336

Browse files
authored
Merge pull request #148 from dt3310321/s3
parse canned acl
2 parents d7d513c + 3e32376 commit 23a6336

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

qcloud_cos/cos_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ def get_object_acl(self, Bucket, Key, **kwargs):
10471047
lst = []
10481048
lst.append(data['AccessControlList']['Grant'])
10491049
data['AccessControlList']['Grant'] = lst
1050+
data['CannedACL'] = parse_object_canned_acl(data, rt.headers)
10501051
return data
10511052

10521053
def restore_object(self, Bucket, Key, RestoreRequest={}, **kwargs):
@@ -1497,6 +1498,7 @@ def get_bucket_acl(self, Bucket, **kwargs):
14971498
lst = []
14981499
lst.append(data['AccessControlList']['Grant'])
14991500
data['AccessControlList']['Grant'] = lst
1501+
data['CannedACL'] = parse_bucket_canned_acl(data)
15001502
return data
15011503

15021504
def put_bucket_cors(self, Bucket, CORSConfiguration={}, **kwargs):

qcloud_cos/cos_comm.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,29 @@ def get_date(yy, mm, dd):
414414
return final_date_str
415415

416416

417+
def parse_object_canned_acl(result_acl, rsp_headers):
418+
"""根据ACL返回的body信息,以及default头部来判断CannedACL"""
419+
if "x-cos-acl" in rsp_headers and rsp_headers["x-cos-acl"] == "default":
420+
return "default"
421+
public_read = {'Grantee': {'Type': 'Group', 'URI': 'http://cam.qcloud.com/groups/global/AllUsers'}, 'Permission': 'READ'}
422+
if 'AccessControlList' in result_acl and 'Grant' in result_acl['AccessControlList']:
423+
if public_read in result_acl['AccessControlList']['Grant']:
424+
return "public-read"
425+
return "private"
426+
427+
428+
def parse_bucket_canned_acl(result_acl):
429+
"""根据ACL返回的body信息来判断Bucket CannedACL"""
430+
public_read = {'Grantee': {'Type': 'Group', 'URI': 'http://cam.qcloud.com/groups/global/AllUsers'}, 'Permission': 'READ'}
431+
public_write = {'Grantee': {'Type': 'Group', 'URI': 'http://cam.qcloud.com/groups/global/AllUsers'}, 'Permission': 'WRITE'}
432+
if 'AccessControlList' in result_acl and 'Grant' in result_acl['AccessControlList']:
433+
if public_read in result_acl['AccessControlList']['Grant']:
434+
if public_write in result_acl['AccessControlList']['Grant']:
435+
return "public-read-write"
436+
return "public-read"
437+
return "private"
438+
439+
417440
class CiDetectType():
418441
"""ci内容设备的类型设置,可与操作设多个"""
419442
PORN = 1

qcloud_cos/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
__version__ = '5.1.9.1'
2+
__version__ = '5.1.9.2'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def long_description():
1616

1717
setup(
1818
name='cos-python-sdk-v5',
19-
version='1.9.1',
19+
version='1.9.2',
2020
url='https://www.qcloud.com/',
2121
license='MIT',
2222
author='tiedu, lewzylu, channingliu',

0 commit comments

Comments
 (0)