@@ -2097,6 +2097,233 @@ def get_bucket_policy(self, Bucket, **kwargs):
2097
2097
data = {'Policy' : json .dumps (rt .json ())}
2098
2098
return data
2099
2099
2100
+ def put_bucket_domain (self , Bucket , DomainConfiguration = {}, ** kwargs ):
2101
+ """设置bucket的自定义域名
2102
+
2103
+ :param Bucket(string): 存储桶名称.
2104
+ :param ReplicationConfiguration(dict): 设置Bucket的自定义域名规则.
2105
+ :param kwargs(dict): 设置请求headers.
2106
+ :return: None.
2107
+
2108
+ .. code-block:: python
2109
+
2110
+ config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
2111
+ client = CosS3Client(config)
2112
+ # 设置bucket自定义域名配置
2113
+ domain_config = {
2114
+ 'DomainRule': [
2115
+ {
2116
+ 'Name': 'www.abc.com',
2117
+ 'Type': 'REST',
2118
+ 'Status': 'ENABLED',
2119
+ 'ForcedReplacement': 'CNAME'
2120
+ },
2121
+ ]
2122
+ }
2123
+ response = client.put_bucket_domain(
2124
+ Bucket='bucket',
2125
+ DomainConfiguration=domain_config
2126
+ )
2127
+ """
2128
+ lst = ['<DomainRule>' , '</DomainRule>' ] # 类型为list的标签
2129
+ xml_config = format_xml (data = DomainConfiguration , root = 'DomainConfiguration' , lst = lst )
2130
+ headers = mapped (kwargs )
2131
+ headers ['Content-MD5' ] = get_md5 (xml_config )
2132
+ headers ['Content-Type' ] = 'application/xml'
2133
+ params = {'domain' : '' }
2134
+ url = self ._conf .uri (bucket = Bucket )
2135
+ logger .info ("put bucket domain, url=:{url} ,headers=:{headers}" .format (
2136
+ url = url ,
2137
+ headers = headers ))
2138
+ rt = self .send_request (
2139
+ method = 'PUT' ,
2140
+ url = url ,
2141
+ bucket = Bucket ,
2142
+ data = xml_config ,
2143
+ auth = CosS3Auth (self ._conf , params = params ),
2144
+ headers = headers ,
2145
+ params = params )
2146
+ return None
2147
+
2148
+ def get_bucket_domain (self , Bucket , ** kwargs ):
2149
+ """获取bucket 自定义域名配置
2150
+
2151
+ :param Bucket(string): 存储桶名称.
2152
+ :param kwargs(dict): 设置请求headers.
2153
+ :return(dict): Bucket对应的自定义域名配置.
2154
+
2155
+ .. code-block:: python
2156
+
2157
+ config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
2158
+ client = CosS3Client(config)
2159
+ # 获取bucket自定义域名配置
2160
+ response = client.get_bucket_domain(
2161
+ Bucket='bucket'
2162
+ )
2163
+ """
2164
+ headers = mapped (kwargs )
2165
+ params = {'domain' : '' }
2166
+ url = self ._conf .uri (bucket = Bucket )
2167
+ logger .info ("get bucket domain, url=:{url} ,headers=:{headers}" .format (
2168
+ url = url ,
2169
+ headers = headers ))
2170
+ rt = self .send_request (
2171
+ method = 'GET' ,
2172
+ url = url ,
2173
+ bucket = Bucket ,
2174
+ auth = CosS3Auth (self ._conf , params = params ),
2175
+ headers = headers ,
2176
+ params = params )
2177
+ data = xml_to_dict (rt .content )
2178
+ format_dict (data , ['DomainRule' ])
2179
+ if 'x-cos-domain-txt-verification' in rt .headers :
2180
+ data ['x-cos-domain-txt-verification' ] = rt .headers ['x-cos-domain-txt-verification' ]
2181
+ return data
2182
+
2183
+ def delete_bucket_domain (self , Bucket , ** kwargs ):
2184
+ """删除bucket 自定义域名配置
2185
+
2186
+ :param Bucket(string): 存储桶名称.
2187
+ :param kwargs(dict): 设置请求headers.
2188
+ :return(dict): None.
2189
+
2190
+ .. code-block:: python
2191
+
2192
+ config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
2193
+ client = CosS3Client(config)
2194
+ # 获取bucket自定义域名配置
2195
+ response = client.delete_bucket_domain(
2196
+ Bucket='bucket'
2197
+ )
2198
+ """
2199
+ headers = mapped (kwargs )
2200
+ params = {'domain' : '' }
2201
+ url = self ._conf .uri (bucket = Bucket )
2202
+ logger .info ("get bucket domain, url=:{url} ,headers=:{headers}" .format (
2203
+ url = url ,
2204
+ headers = headers ))
2205
+ rt = self .send_request (
2206
+ method = 'DELETE' ,
2207
+ url = url ,
2208
+ bucket = Bucket ,
2209
+ auth = CosS3Auth (self ._conf , params = params ),
2210
+ headers = headers ,
2211
+ params = params )
2212
+ return None
2213
+
2214
+ def put_bucket_origin (self , Bucket , OriginConfiguration = {}, ** kwargs ):
2215
+ """设置bucket的回源
2216
+
2217
+ :param Bucket(string): 存储桶名称.
2218
+ :param ReplicationConfiguration(dict): 设置Bucket的回源规则.
2219
+ :param kwargs(dict): 设置请求headers.
2220
+ :return: None.
2221
+
2222
+ .. code-block:: python
2223
+
2224
+ config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
2225
+ client = CosS3Client(config)
2226
+ # 设置bucket自定义域名配置
2227
+ origin_config = {
2228
+ 'OriginRule': [
2229
+ {
2230
+ 'OriginType': 'Redirect',
2231
+ 'OriginInfo': {
2232
+ 'HostName': 'www.abc.com',
2233
+ 'Protocol': 'HTTP'
2234
+ }
2235
+ },
2236
+ ]
2237
+ }
2238
+ response = client.put_bucket_origin(
2239
+ Bucket='bucket',
2240
+ OriginConfiguration=origin_config
2241
+ )
2242
+ """
2243
+ lst = ['<OriginRule>' , '</OriginRule>' ] # 类型为list的标签
2244
+ xml_config = format_xml (data = OriginConfiguration , root = 'OriginConfiguration' , lst = lst )
2245
+ headers = mapped (kwargs )
2246
+ headers ['Content-MD5' ] = get_md5 (xml_config )
2247
+ headers ['Content-Type' ] = 'application/xml'
2248
+ params = {'origin' : '' }
2249
+ url = self ._conf .uri (bucket = Bucket )
2250
+ logger .info ("put bucket origin, url=:{url} ,headers=:{headers}" .format (
2251
+ url = url ,
2252
+ headers = headers ))
2253
+ rt = self .send_request (
2254
+ method = 'PUT' ,
2255
+ url = url ,
2256
+ bucket = Bucket ,
2257
+ data = xml_config ,
2258
+ auth = CosS3Auth (self ._conf , params = params ),
2259
+ headers = headers ,
2260
+ params = params )
2261
+ return None
2262
+
2263
+ def get_bucket_origin (self , Bucket , ** kwargs ):
2264
+ """获取bucket 回源配置
2265
+
2266
+ :param Bucket(string): 存储桶名称.
2267
+ :param kwargs(dict): 设置请求headers.
2268
+ :return(dict): Bucket对应的自定义域名配置.
2269
+
2270
+ .. code-block:: python
2271
+
2272
+ config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
2273
+ client = CosS3Client(config)
2274
+ # 获取bucket自定义域名配置
2275
+ response = client.get_bucket_origin(
2276
+ Bucket='bucket'
2277
+ )
2278
+ """
2279
+ headers = mapped (kwargs )
2280
+ params = {'origin' : '' }
2281
+ url = self ._conf .uri (bucket = Bucket )
2282
+ logger .info ("get bucket origin, url=:{url} ,headers=:{headers}" .format (
2283
+ url = url ,
2284
+ headers = headers ))
2285
+ rt = self .send_request (
2286
+ method = 'GET' ,
2287
+ url = url ,
2288
+ bucket = Bucket ,
2289
+ auth = CosS3Auth (self ._conf , params = params ),
2290
+ headers = headers ,
2291
+ params = params )
2292
+ data = xml_to_dict (rt .content )
2293
+ format_dict (data , ['OriginRule' ])
2294
+ return data
2295
+
2296
+ def delete_bucket_origin (self , Bucket , ** kwargs ):
2297
+ """删除bucket 回源配置
2298
+
2299
+ :param Bucket(string): 存储桶名称.
2300
+ :param kwargs(dict): 设置请求headers.
2301
+ :return(dict): None.
2302
+
2303
+ .. code-block:: python
2304
+
2305
+ config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
2306
+ client = CosS3Client(config)
2307
+ # 获取bucket自定义域名配置
2308
+ response = client.delete_bucket_origin(
2309
+ Bucket='bucket'
2310
+ )
2311
+ """
2312
+ headers = mapped (kwargs )
2313
+ params = {'origin' : '' }
2314
+ url = self ._conf .uri (bucket = Bucket )
2315
+ logger .info ("get bucket origin, url=:{url} ,headers=:{headers}" .format (
2316
+ url = url ,
2317
+ headers = headers ))
2318
+ rt = self .send_request (
2319
+ method = 'DELETE' ,
2320
+ url = url ,
2321
+ bucket = Bucket ,
2322
+ auth = CosS3Auth (self ._conf , params = params ),
2323
+ headers = headers ,
2324
+ params = params )
2325
+ return None
2326
+
2100
2327
# service interface begin
2101
2328
def list_buckets (self , ** kwargs ):
2102
2329
"""列出所有bucket
0 commit comments