@@ -3468,7 +3468,7 @@ def put_bucket_intelligenttiering(self, Bucket, IntelligentTieringConfiguration=
34683468 """设置存储桶智能分层配置
34693469
34703470 :param Bucket(string): 存储桶名称.
3471- :param IntelligentTieringConfiguration(dict): 只能分层配置
3471+ :param IntelligentTieringConfiguration(dict): 智能分层配置
34723472 :param kwargs(dict): 设置请求headers.
34733473 :return: None.
34743474
@@ -3510,7 +3510,6 @@ def put_bucket_intelligenttiering(self, Bucket, IntelligentTieringConfiguration=
35103510 def get_bucket_intelligenttiering (self , Bucket , ** kwargs ):
35113511 """获取存储桶智能分层配置
35123512 :param Bucket(string): 存储桶名称.
3513- :param IntelligentTieringConfiguration(dict): 智能分层配置
35143513 :param kwargs(dict): 设置请求headers.
35153514 :return(dict): 智能分层配置.
35163515
@@ -3535,6 +3534,225 @@ def get_bucket_intelligenttiering(self, Bucket, **kwargs):
35353534 params = params )
35363535 data = xml_to_dict (rt .content )
35373536 return data
3537+
3538+ def put_bucket_object_lock (self , Bucket , ObjectLockConfiguration = {}, ** kwargs ):
3539+ """设置存储桶对象锁定配置
3540+
3541+ :param Bucket(string): 存储桶名称.
3542+ :param ObjectLockConfiguration(dict): 对象锁定配置.
3543+ :param kwargs(dict): 设置请求headers.
3544+ :return: None.
3545+
3546+ .. code-block:: python
3547+
3548+ config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
3549+ client = CosS3Client(config)
3550+
3551+ object_lock_conf = {
3552+ 'ObjectLockEnabled': 'Enabled',
3553+ }
3554+ client.put_bucket_object_lock(Bucket="bucket", ObjectLockConfiguration=objeck_lock_conf)
3555+ """
3556+
3557+ xml_config = format_xml (data = ObjectLockConfiguration , root = 'ObjectLockConfiguration' )
3558+ headers = mapped (kwargs )
3559+ headers ['Content-MD5' ] = get_md5 (xml_config )
3560+ headers ['Content-Type' ] = 'application/xml'
3561+ params = {'object-lock' : '' }
3562+ url = self ._conf .uri (bucket = Bucket )
3563+ logger .info ("put bucket object-lock, url=:{url} ,headers=:{headers}" .format (
3564+ url = url ,
3565+ headers = headers ))
3566+ rt = self .send_request (
3567+ method = 'PUT' ,
3568+ url = url ,
3569+ bucket = Bucket ,
3570+ data = xml_config ,
3571+ auth = CosS3Auth (self ._conf , params = params ),
3572+ headers = headers ,
3573+ params = params )
3574+ return rt .headers
3575+
3576+ def get_bucket_object_lock (self , Bucket , ** kwargs ):
3577+ """获取存储桶对象锁定配置
3578+
3579+ :param Bucket(string): 存储桶名称.
3580+ :param kwargs(dict): 设置请求headers.
3581+ :return(dict): 对象锁定配置.
3582+
3583+ .. code-block:: python
3584+
3585+ config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
3586+ client = CosS3Client(config)
3587+ client.get_bucket_object_lock(Bucket="bucket")
3588+ """
3589+ headers = mapped (kwargs )
3590+ params = {'object-lock' : '' }
3591+ url = self ._conf .uri (bucket = Bucket )
3592+ logger .info ("get bucket object-lock, url=:{url} ,headers=:{headers}" .format (
3593+ url = url ,
3594+ headers = headers ))
3595+ rt = self .send_request (
3596+ method = 'GET' ,
3597+ url = url ,
3598+ bucket = Bucket ,
3599+ auth = CosS3Auth (self ._conf , params = params ),
3600+ headers = headers ,
3601+ params = params )
3602+ data = xml_to_dict (rt .content )
3603+ return data
3604+
3605+ def get_bucket_meta (self , Bucket , ** kwargs ):
3606+ """获取存储桶各项配置
3607+
3608+ :param Bucket(string): 存储桶名称.
3609+ :param kwargs(dict): 设置请求headers.
3610+ :return(dict): 存储桶各项配置.
3611+
3612+ .. code-block:: python
3613+
3614+ config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
3615+ client = CosS3Client(config)
3616+ client.get_bucket_meta(Bucket="bucket")
3617+ """
3618+ data = {
3619+ 'BucketUrl' : None ,
3620+ 'OFS' : False ,
3621+ 'MAZ' : False ,
3622+ 'Encryption' : None ,
3623+ 'ACL' : None ,
3624+ 'Website' : None ,
3625+ 'Logging' : None ,
3626+ 'CORS' : None ,
3627+ 'Versioning' : None ,
3628+ 'IntelligentTiering' : None ,
3629+ 'Lifecycle' : None ,
3630+ 'Tagging' : None ,
3631+ 'ObjectLock' : None ,
3632+ 'Replication' : None ,
3633+ }
3634+ pool = SimpleThreadPool (num_threads = 10 )
3635+
3636+ # HeadBucket
3637+ def _head_bucket_wrapper (Bucket , ** kwargs ):
3638+ resp = self .head_bucket (Bucket , ** kwargs )
3639+ # x-cos-bucket-arch: 'OFS'
3640+ # x-cos-bucket-az-type: 'MAZ'
3641+ # x-cos-bucket-region: 'ap-beijing'
3642+ if 'x-cos-bucket-arch' in resp and resp ['x-cos-bucket-arch' ] == 'OFS' :
3643+ data .update ({'OFS' : True })
3644+ else :
3645+ data .update ({'OFS' : False })
3646+ if 'x-cos-bucket-az-type' in resp and resp ['x-cos-bucket-az-type' ] == 'MAZ' :
3647+ data .update ({'MAZ' : True })
3648+ else :
3649+ data .update ({'MAZ' : False })
3650+ data .update ({"Location" : resp ['x-cos-bucket-region' ]})
3651+ url = self ._conf .uri (bucket = Bucket )
3652+ data .update ({'BucketUrl' : url })
3653+ pool .add_task (_head_bucket_wrapper , Bucket , ** kwargs )
3654+
3655+ # Website
3656+ def _get_bucket_website_wrapper (Bucket , ** kwargs ):
3657+ try :
3658+ resp = self .get_bucket_website (Bucket , ** kwargs )
3659+ data .update ({'Website' : resp })
3660+ except CosServiceError as e :
3661+ logger .debug ("get_bucket_meta failed to get website conf:{}" .format (e ))
3662+ pool .add_task (_get_bucket_website_wrapper , Bucket , ** kwargs )
3663+
3664+ # ObjectLock
3665+ def _get_bucket_object_lock_wrapper (Bucket , ** kwargs ):
3666+ try :
3667+ resp = self .get_bucket_object_lock (Bucket , ** kwargs )
3668+ data .update ({'ObjectLock' : resp })
3669+ except CosServiceError as e :
3670+ logger .debug ("get_bucket_meta failed to get object_lock conf:{}" .format (e ))
3671+ pool .add_task (_get_bucket_object_lock_wrapper , Bucket , ** kwargs )
3672+
3673+ # ACL
3674+ def _get_bucket_acl_wrapper (Bucket , ** kwargs ):
3675+ try :
3676+ resp = self .get_bucket_acl (Bucket , ** kwargs )
3677+ data .update ({'ACL' : resp })
3678+ except CosServiceError as e :
3679+ logger .debug ("get_bucket_meta failed to get acl conf:{}" .format (e ))
3680+ pool .add_task (_get_bucket_acl_wrapper , Bucket , ** kwargs )
3681+
3682+ # Logging
3683+ def _get_bucket_logging_wrapper (Bucket , ** kwargs ):
3684+ try :
3685+ resp = self .get_bucket_logging (Bucket , ** kwargs )
3686+ data .update ({'Logging' : resp })
3687+ except CosServiceError as e :
3688+ logger .debug ("get_bucket_meta failed to get logging conf:{}" .format (e ))
3689+ pool .add_task (_get_bucket_logging_wrapper , Bucket , ** kwargs )
3690+
3691+ # Lifecycle
3692+ def _get_bucket_lifecycle_wrapper (Bucket , ** kwargs ):
3693+ try :
3694+ resp = self .get_bucket_lifecycle (Bucket , ** kwargs )
3695+ data .update ({'Lifecycle' : resp })
3696+ except CosServiceError as e :
3697+ logger .debug ("get_bucket_meta failed to get lifecycle conf:{}" .format (e ))
3698+ pool .add_task (_get_bucket_lifecycle_wrapper , Bucket , ** kwargs )
3699+
3700+ # Replication
3701+ def _get_bucket_replication_wrapper (Bucket , ** kwargs ):
3702+ try :
3703+ resp = self .get_bucket_replication (Bucket , ** kwargs )
3704+ data .update ({'Replication' : resp })
3705+ except CosServiceError as e :
3706+ logger .debug ("get_bucket_meta failed to get replication conf:{}" .format (e ))
3707+ pool .add_task (_get_bucket_replication_wrapper , Bucket , ** kwargs )
3708+
3709+ # Replication
3710+ def _get_bucket_encryption_wrapper (Bucket , ** kwargs ):
3711+ try :
3712+ resp = self .get_bucket_encryption (Bucket , ** kwargs )
3713+ data .update ({'Encryption' : resp })
3714+ except CosServiceError as e :
3715+ logger .debug ("get_bucket_meta failed to get encryption conf:{}" .format (e ))
3716+ pool .add_task (_get_bucket_encryption_wrapper , Bucket , ** kwargs )
3717+
3718+ # CORS
3719+ def _get_bucket_cors_wrapper (Bucket , ** kwargs ):
3720+ try :
3721+ resp = self .get_bucket_cors (Bucket , ** kwargs )
3722+ data .update ({'CORS' : resp })
3723+ except CosServiceError as e :
3724+ logger .debug ("get_bucket_meta failed to get cors conf:{}" .format (e ))
3725+ pool .add_task (_get_bucket_cors_wrapper , Bucket , ** kwargs )
3726+
3727+ # Versioning
3728+ def _get_bucket_versioning_wrapper (Bucket , ** kwargs ):
3729+ try :
3730+ resp = self .get_bucket_versioning (Bucket , ** kwargs )
3731+ data .update ({'Versioning' : resp })
3732+ except CosServiceError as e :
3733+ logger .debug ("get_bucket_meta failed to get versioning conf:{}" .format (e ))
3734+ pool .add_task (_get_bucket_versioning_wrapper , Bucket , ** kwargs )
3735+
3736+ # IntelligentTiering
3737+ def _get_bucket_intelligenttiering_wrapper (Bucket , ** kwargs ):
3738+ try :
3739+ resp = self .get_bucket_intelligenttiering (Bucket , ** kwargs )
3740+ data .update ({'IntelligentTiering' : resp })
3741+ except CosServiceError as e :
3742+ logger .debug ("get_bucket_meta failed to get intelligenttiering conf:{}" .format (e ))
3743+ pool .add_task (_get_bucket_intelligenttiering_wrapper , Bucket , ** kwargs )
3744+
3745+ # Tagging
3746+ def _get_bucket_tagging_wrapper (Bucket , ** kwargs ):
3747+ try :
3748+ resp = self .get_bucket_tagging (Bucket , ** kwargs )
3749+ data .update ({'Tagging' : resp })
3750+ except CosServiceError as e :
3751+ logger .debug ("get_bucket_meta failed to get tagging conf:{}" .format (e ))
3752+ pool .add_task (_get_bucket_tagging_wrapper , Bucket , ** kwargs )
3753+
3754+ pool .wait_completion ()
3755+ return data
35383756
35393757 # service interface begin
35403758 def list_buckets (self , TagKey = None , TagValue = None , Region = None , CreateTime = None , Range = None , Marker = "" , MaxKeys = 2000 , ** kwargs ):
0 commit comments