kboss/kgadget/src/iam_sample_conf.py
2025-07-16 14:27:17 +08:00

34 lines
885 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#引入标准日志模块
import logging
#引入配置管理模块以及安全认证模块
from baidubce.bce_client_configuration import BceClientConfiguration
from baidubce.auth.bce_credentials import BceCredentials
#设置HostAccess Key ID和Secret Access Key
HOST = 'iam.bj.baidubce.com'
AK = 'ALTAKPk92fX9cgGDax83yNL8mP'
SK = '9b16b8efd4dc463d8bbd5462db1db8a5'
#设置日志文件的句柄和日志级别
logger = logging.getLogger('baidubce.services.iam.iamclient')
fh = logging.FileHandler('sample.log')
fh.setLevel(logging.DEBUG)
#设置日志文件输出的顺序、结构和内容
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.setLevel(logging.DEBUG)
logger.addHandler(fh)
#创建BceClientConfiguration
config = BceClientConfiguration(credentials=BceCredentials(AK, SK), endpoint=HOST)