更新时间:2023-11-08 GMT+08:00
分享

查看桶日志配置

开发过程中,您有任何问题可以在github上提交issue,或者在华为云对象存储服务论坛中发帖求助。接口参考文档详细介绍了每个接口的参数和使用方法。

您可以通过ObsClient.getBucketLogging查看桶日志配置。以下代码展示了如何查看桶日志配置:

// 引入obs库
// 使用npm安装
var ObsClient = require('esdk-obs-nodejs');
// 使用源码安装
// var ObsClient = require('./lib/obs');

// 创建ObsClient实例
const obsClient = new ObsClient({
    //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。
    //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html
    access_key_id: process.env.ACCESS_KEY_ID,
    secret_access_key: process.env.SECRET_ACCESS_KEY,
    //这里以华北-北京四为例,其他地区请按实际情况填写
    server: 'https://obs.cn-north-4.myhuaweicloud.com'
    
});

obsClient.getBucketLogging({
       Bucket:'bucketname'
}, (err, result) => {
       if(err){
              console.log('Error-->' + err);
       }else{
              console.log('Status-->' + result.CommonMsg.Status);
              if(result.CommonMsg.Status < 300 && result.InterfaceResult){
                     if(result.InterfaceResult.LoggingEnabled){
                           console.log('TargetBucket-->' + result.InterfaceResult.LoggingEnabled.TargetBucket);
                           console.log('TargetPrefix-->' + result.InterfaceResult.LoggingEnabled.TargetPrefix);
                     }
                     for(let i=0;i<result.InterfaceResult.LoggingEnabled.TargetGrants.length;i++){
                           console.log('Grant[' + i + ']:');
                           console.log('Grantee[ID]-->' + result.InterfaceResult.LoggingEnabled.TargetGrants[i]['Grantee']['ID']);
                           console.log('Grantee[URI]-->' + result.InterfaceResult.LoggingEnabled.TargetGrants[i]['Grantee']['URI']);
                           console.log('Permission-->' + result.InterfaceResult.LoggingEnabled.TargetGrants[i]['Permission']);
                     }
              }
       }
});
分享:

    相关文档

    相关产品