文档首页 > > SDK参考> .NET> 生命周期管理> 查看生命周期规则

查看生命周期规则

分享
更新时间: 2019/04/22 GMT+08:00

您可以通过ObsClient.GetBucketLifecycle查看桶的生命周期规则。以下代码展示了如何查看桶的生命周期规则:

// 创建ObsClient实例
ObsClient client = new ObsClient("*** Provide your Access Key ***", "*** Provide your Secret Key ***", "https://your-endpoint");
// 查看桶的生命周期
try
{
    GetBucketLifecycleRequest request = new GetBucketLifecycleRequest();
    request.BucketName = "bucketname";
    GetBucketLifecycleResponse response = client.GetBucketLifecycle(request);
    foreach (LifecycleRule lifecycleRule in response.Configuration.Rules)
    {
        Console.WriteLine("Lifecycle rule id: {0}", lifecycleRule.Id);
        Console.WriteLine("Lifecycle rule prefix: {0}", lifecycleRule.Prefix);
        Console.WriteLine("Lifecycle rule status: {0}", lifecycleRule.Status);
        if (null != lifecycleRule.Expiration)
        {
            Console.WriteLine("expiration days: {0}", lifecycleRule.Expiration.Days);
        }
        if (null != lifecycleRule.NoncurrentVersionExpiration)
        {
            Console.WriteLine("NoncurrentVersionExpiration NoncurrentDays: {0}", lifecycleRule.NoncurrentVersionExpiration.NoncurrentDays);
        }
        foreach (Transition transition in lifecycleRule.Transitions)
        {
            Console.WriteLine("Transition Days : {0}", transition.Days);
            Console.WriteLine("Transition StorageClass : {0}", transition.StorageClass);
        }
        foreach (NonCurrentVersionTransition noncurrentVersionTransition in lifecycleRule.NoncurrentVersionTransitions)
        {
            Console.WriteLine("NoncurrentVersionTransition NoncurrentDays: {0}", noncurrentVersionTransition.NoncurrentDays);
            Console.WriteLine("NoncurrentVersionTransition StorageClass : {0}", noncurrentVersionTransition.StorageClass);
        }
        Console.WriteLine("Get bucket lifecycle response: {0}", response.StatusCode);
    }
}
catch (ObsException ex)
{
    Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
    Console.WriteLine("ErrorMessage: {0}", ex.ErrorMessage);
}
分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!

非常感谢您的反馈,我们会继续努力做到更好!

反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

跳转到云社区