#!/usr/bin/env python
# coding=utf-8

from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.client import AcsClient

from aliyunsdkcr.request.v20160607 import GetAuthorizationTokenRequest

# 示例执行异常时建议升级aliyun-python-sdk-core到最新版本

from BaseDataMaintenance.dataSource.setttings import ots_AccessKeyId,ots_AccessKeySecret

# 设置Client
apiClient = AcsClient(ots_AccessKeyId, ots_AccessKeySecret, 'cn-hangzhou')

# 构造请求
request = GetAuthorizationTokenRequest.GetAuthorizationTokenRequest()

# 设置参数
# request.set_RepoNamespace("bxkc")
# request.set_RepoName("moose-zuul")
# # request.set_Tag("GetAuthorizationToken")
# # request.set_Tag()
# # request.set_action_name("token")
# print(request.get_url("tokens"))


# 根据文档获取资源所在区域对应的RegionId
# 请求地址格式为cr.{regionId}.aliyuncs.com
request.set_endpoint("cr.cn-hangzhou.aliyuncs.com")

# 发起请求
try:
    response = apiClient.do_action_with_exception(request)
    print(response)
except ServerException as e:
    print(e)
except ClientException as e:
    print(e)