更新时间:2024-04-26 GMT+08:00
查看生命周期规则
您可以通过ObsClient.getBucketLifecycle查看桶的生命周期规则。以下代码展示了如何查看桶的生命周期规则:
// 创建ObsClient实例 var obsClient = new ObsClient({ // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;本示例以ak和sk保存在环境变量中为例,运行本示例前请先在本地环境中设置环境变量AccessKeyID和SecretAccessKey。 // 前端本身没有process对象,可以使用webpack类打包工具定义环境变量,就可以在代码中运行了。 // 您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/intl/zh-cn/usermanual-ca/ca_01_0003.html access_key_id: process.env.AccessKeyID, secret_access_key: process.env.SecretAccessKey, // 这里以中国-香港为例,其他地区请按实际情况填写 server: 'https://obs.ap-southeast-1.myhuaweicloud.com' }); obsClient.getBucketLifecycle({ Bucket: 'bucketname' }, function (err, result) { if(err){ console.log('Error-->' + err); }else{ console.log('Status-->' + result.CommonMsg.Status); if(result.CommonMsg.Status < 300 && result.InterfaceResult){ for(var i=0;i<result.InterfaceResult.Rules.length;i++){ console.log('Rule[' + i + ']:'); console.log('ID-->' + result.InterfaceResult.Rules[i]['ID']); console.log('Prefix-->' + result.InterfaceResult.Rules[i]['Prefix']); console.log('Status-->' + result.InterfaceResult.Rules[i]['Status']); for(var j=0;j<result.InterfaceResult.Rules[i]['Transitions'].length;j++){ console.log('Transition[' + j + ']:'); console.log('Transition[StorageClass]-->' + result.InterfaceResult.Rules[i]['Transitions'][j]['StorageClass']); console.log('Transition[Date]-->' + result.InterfaceResult.Rules[i]['Transitions'][j]['Date']); console.log('Transition[Days]-->' + result.InterfaceResult.Rules[i]['Transitions'][j]['Days']); } console.log('Expiration[Date]-->' + result.InterfaceResult.Rules[i]['Expiration']['Date']); console.log('Expiration[Days]-->' + result.InterfaceResult.Rules[i]['Expiration']['Days']); for(var k=0;k<result.InterfaceResult.Rules[i]['NoncurrentVersionTransitions'].length;k++){ console.log('NoncurrentVersionTransition[' + k + ']:'); console.log('NoncurrentVersionTransition[StorageClass]-->' + result.InterfaceResult.Rules[i]['NoncurrentVersionTransitions'][k]['StorageClass']); console.log('NoncurrentVersionTransition[NoncurrentDays]-->' + result.InterfaceResult.Rules[i]['NoncurrentVersionTransitions'][k]['NoncurrentDays']); } console.log('NoncurrentVersionExpiration[NoncurrentDays]-->' + result.InterfaceResult.Rules[i]['NoncurrentVersionExpiration']['NoncurrentDays']); } } } });
父主题: 生命周期管理