diff --git a/qcloud_cos/cos_client.py b/qcloud_cos/cos_client.py index 3a83243a..070d52d2 100644 --- a/qcloud_cos/cos_client.py +++ b/qcloud_cos/cos_client.py @@ -2798,6 +2798,38 @@ def get_bucket_referer(self, Bucket, **kwargs): format_dict(data['DomainList'], ['Domain']) return data + def delete_bucket_referer(self, Bucket, **kwargs): + """获取bucket防盗链规则 + + :param Bucket(string): 存储桶名称. + :param kwargs(dict): 设置请求headers. + :return(dict): None. + + .. code-block:: python + + config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象 + client = CosS3Client(config) + # 获取bucket标签 + response = client.delete_bucket_referer( + Bucket='bucket' + ) + """ + xml_config='' + headers = mapped(kwargs) + headers['Content-MD5'] = get_md5(xml_config) + headers['Content-Type'] = 'application/xml' + params = {'referer': ''} + url = self._conf.uri(bucket=Bucket) + rt = self.send_request( + method='PUT', + url=url, + bucket=Bucket, + data=xml_config, + auth=CosS3Auth(self._conf, params=params), + headers=headers, + params=params) + return None + # service interface begin def list_buckets(self, **kwargs): """列出所有bucket diff --git a/ut/test.py b/ut/test.py index a14ac0b7..477810a5 100644 --- a/ut/test.py +++ b/ut/test.py @@ -1078,7 +1078,7 @@ def _test_put_get_delete_bucket_origin(): ) -def test_put_get_bucket_referer(): +def test_put_get_delete_bucket_referer(): """测试设置获取bucket防盗链规则""" referer_config = { 'Status': 'Enabled', @@ -1099,6 +1099,14 @@ def test_put_get_bucket_referer(): response = client.get_bucket_referer( Bucket=test_bucket, ) + response = client.delete_bucket_referer( + Bucket=test_bucker, + ) + time.sleep(4) + response = client.get_bucker_referer( + Bucket=test_bucker, + ) + assert len(response)==0 def test_put_get_traffic_limit():