|
|
package com.monitor.other.worksystem.dock.qq;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.tencentcloudapi.common.Credential;
|
|
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
|
import com.tencentcloudapi.common.profile.ClientProfile;
|
|
|
import com.tencentcloudapi.common.profile.HttpProfile;
|
|
|
import com.tencentcloudapi.tcr.v20190924.TcrClient;
|
|
|
import com.tencentcloudapi.tcr.v20190924.models.DescribeImagePersonalRequest;
|
|
|
import com.tencentcloudapi.tcr.v20190924.models.DescribeImagePersonalResponse;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
/**
|
|
|
* @author xutao.liu@yoho.cn 2022/8/17 17:19
|
|
|
*/
|
|
|
public class TrcClientUtil {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(TrcClientUtil.class);
|
|
|
|
|
|
private static final String SECRET_ID = "AKIDIMBl59hWpsgFYel7YljRu89wUmpchUYO";
|
|
|
private static final String SECRET_KEY = "kGXYKq8evxkI0VmpfGcjbEckdHgqlRr3";
|
|
|
private static final String REGION = "ap-guangzhou";
|
|
|
private static final String ENDPOINT = "tcr.tencentcloudapi.com";
|
|
|
|
|
|
private static TcrClient tcrClient = null;
|
|
|
|
|
|
private TrcClientUtil() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取个人版镜像仓库tag列表
|
|
|
*
|
|
|
* @author xutao.liu@yoho.cn
|
|
|
* 2022/8/17 18:26
|
|
|
*/
|
|
|
static JSONObject getImageTagList(String repoName, long offset) {
|
|
|
if (StringUtils.isBlank(repoName)) {
|
|
|
logger.warn("getImageTagList param repoName is blank");
|
|
|
return null;
|
|
|
}
|
|
|
// 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
DescribeImagePersonalRequest req = new DescribeImagePersonalRequest();
|
|
|
req.setRepoName(repoName);
|
|
|
req.setOffset(offset);
|
|
|
// 返回的resp是一个DescribeImagePersonalResponse的实例,与请求对象对应
|
|
|
DescribeImagePersonalResponse resp;
|
|
|
try {
|
|
|
resp = getTcrClient().DescribeImagePersonal(req);
|
|
|
} catch (TencentCloudSDKException e) {
|
|
|
logger.error("getImageTagList cause exception repoName:{}", repoName, e);
|
|
|
return null;
|
|
|
}
|
|
|
// 输出json格式的字符串回包
|
|
|
String resultStr = DescribeImagePersonalResponse.toJsonString(resp);
|
|
|
logger.info("DescribeImagePersonalResponse result:{}", resultStr);
|
|
|
|
|
|
return JSONObject.parseObject(resultStr);
|
|
|
}
|
|
|
|
|
|
private static TcrClient getTcrClient() {
|
|
|
if (tcrClient == null) {
|
|
|
synchronized (TrcClientUtil.class) {
|
|
|
if (tcrClient == null) {
|
|
|
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
|
|
|
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
|
|
|
Credential cred = new Credential(SECRET_ID, SECRET_KEY);
|
|
|
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
HttpProfile httpProfile = new HttpProfile();
|
|
|
httpProfile.setConnTimeout(2); // 请求连接超时时间,单位为秒(默认60秒)
|
|
|
httpProfile.setReadTimeout(1); // 设置读取超时时间,单位为秒(默认0秒)
|
|
|
|
|
|
httpProfile.setEndpoint(ENDPOINT);
|
|
|
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
|
|
ClientProfile clientProfile = new ClientProfile();
|
|
|
clientProfile.setHttpProfile(httpProfile);
|
|
|
|
|
|
tcrClient = new TcrClient(cred, REGION, clientProfile);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return tcrClient;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
JSONObject resultStr = getImageTagList("yoho-online/yohobuywap-node-activity", 0);
|
|
|
System.out.println(resultStr);
|
|
|
}
|
|
|
} |
...
|
...
|
|