更新时间:2024-12-03 GMT+08:00
查看生命周期规则
您可以通过ObsClient.getBucketLifecycle查看桶的生命周期规则。
本示例用于查看桶名为“bucketname”的生命周期规则。
代码示例如下所示:
// 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;本示例以ak和sk保存在环境变量中为例,运行本示例前请先在本地环境中设置环境变量ACCESS_KEY_ID和SECRET_ACCESS_KEY_ID。 // 您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/intl/zh-cn/usermanual-ca/ca_01_0003.html String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); String endPoint = "https://your-endpoint"; // 创建ObsClient实例 ObsClient obsClient = new ObsClient(ak, sk, endPoint); LifecycleConfiguration config = obsClient.getBucketLifecycle("bucketname"); for (LifecycleConfiguration.Rule rule : config.getRules()) { Log.i("GetBucketLifecycleConfiguration",rule.getId()); Log.i("GetBucketLifecycleConfiguration",rule.getPrefix()); for(LifecycleConfiguration.Transition transition : rule.getTransitions()){ Log.i("GetBucketLifecycleConfiguration",String.valueOf(transition.getDays())); Log.i("GetBucketLifecycleConfiguration",transition.getStorageClass()); } Log.i("GetBucketLifecycleConfiguration",rule.getExpiration() != null ? String.valueOf(rule.getExpiration().getDays()) : ""); for(LifecycleConfiguration.NoncurrentVersionTransition noncurrentVersionTransition : rule.getNoncurrentVersionTransitions()){ Log.i("GetBucketLifecycleConfiguration",String.valueOf(noncurrentVersionTransition.getDays())); Log.i("GetBucketLifecycleConfiguration",noncurrentVersionTransition.getStorageClass()); } Log.i("GetBucketLifecycleConfiguration",rule.getNoncurrentVersionExpiration() != null ?String.valueOf(rule.getNoncurrentVersionExpiration().getDays()) : ""); }
- 查看生命周期规则过程中返回的错误码含义、问题原因及处理措施可参考OBS服务端错误码。
父主题: 生命周期管理