Skip to content

Commit 5951c62

Browse files
authored
Merge pull request #152 from dt3310321/s3
add delete policy
2 parents f3bf473 + b6085c4 commit 5951c62

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

qcloud_cos/cos_client.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,37 @@ def get_bucket_policy(self, Bucket, **kwargs):
22632263
data = {'Policy': json.dumps(rt.json())}
22642264
return data
22652265

2266+
def delete_bucket_policy(self, Bucket, **kwargs):
2267+
"""删除bucket policy
2268+
2269+
:param Bucket(string): 存储桶名称.
2270+
:param kwargs(dict): 设置请求headers.
2271+
:return: None.
2272+
2273+
.. code-block:: python
2274+
2275+
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
2276+
client = CosS3Client(config)
2277+
# 删除bucket policy服务配置
2278+
response = client.delete_bucket_policy(
2279+
Bucket=bucket
2280+
)
2281+
"""
2282+
headers = mapped(kwargs)
2283+
params = {'policy': ''}
2284+
url = self._conf.uri(bucket=Bucket)
2285+
logger.info("delete bucket policy, url=:{url} ,headers=:{headers}".format(
2286+
url=url,
2287+
headers=headers))
2288+
rt = self.send_request(
2289+
method='DELETE',
2290+
url=url,
2291+
bucket=Bucket,
2292+
auth=CosS3Auth(self._conf, params=params),
2293+
headers=headers,
2294+
params=params)
2295+
return None
2296+
22662297
def put_bucket_domain(self, Bucket, DomainConfiguration={}, **kwargs):
22672298
"""设置bucket的自定义域名
22682299

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.4'
2+
__version__ = '5.1.9.5'

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.4',
19+
version='1.9.5',
2020
url='https://www.qcloud.com/',
2121
license='MIT',
2222
author='tiedu, lewzylu, channingliu',

ut/test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,8 @@ def test_bucket_exists():
862862
assert status is True
863863

864864

865-
def test_put_get_bucket_policy():
866-
"""设置获取bucket的policy配置"""
865+
def test_put_get_delete_bucket_policy():
866+
"""设置获取删除bucket的policy配置"""
867867
resource = "qcs::cos:" + REGION + ":uid/" + APPID + ":" + test_bucket + "/*"
868868
resource_list = [resource]
869869
policy = {
@@ -891,6 +891,9 @@ def test_put_get_bucket_policy():
891891
response = client.get_bucket_policy(
892892
Bucket=test_bucket,
893893
)
894+
response = client.delete_bucket_policy(
895+
Bucket=test_bucket,
896+
)
894897

895898

896899
def test_put_file_like_object():

0 commit comments

Comments
 (0)