mirror of
https://github.com/certd/certd.git
synced 2026-04-03 14:10:54 +08:00
chore: 补充其他access的测试按钮
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
||||
import { AccessInput, BaseAccess, IsAccess, PageSearch } from "@certd/pipeline";
|
||||
import { QiniuClient } from "./lib/sdk.js";
|
||||
|
||||
@IsAccess({
|
||||
name: "qiniu",
|
||||
@@ -21,6 +22,34 @@ export class QiniuAccess extends BaseAccess {
|
||||
helper: "SK",
|
||||
})
|
||||
secretKey!: string;
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "onTestRequest",
|
||||
},
|
||||
helper: "点击测试接口看是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getDomainList();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
||||
|
||||
async getDomainList(req: PageSearch = {}) {
|
||||
const qiniuClient = new QiniuClient({
|
||||
http: this.ctx.http,
|
||||
access:this,
|
||||
logger: this.ctx.logger,
|
||||
});
|
||||
const url = `https://api.qiniu.com/domain?limit=${req.pageSize || 1000}`;
|
||||
const res = await qiniuClient.doRequest(url, 'get');
|
||||
return res.domains||[]
|
||||
}
|
||||
}
|
||||
|
||||
new QiniuAccess();
|
||||
|
||||
@@ -57,6 +57,24 @@ export class TencentAccess extends BaseAccess {
|
||||
})
|
||||
closeExpiresNotify: boolean = true;
|
||||
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "onTestRequest",
|
||||
},
|
||||
helper: "点击测试接口看是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getCallerIdentity();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
||||
isIntl() {
|
||||
return this.accountType === "intl";
|
||||
}
|
||||
@@ -68,4 +86,44 @@ export class TencentAccess extends BaseAccess {
|
||||
buildEndpoint(endpoint: string) {
|
||||
return `${this.intlDomain()}${endpoint}`;
|
||||
}
|
||||
|
||||
async getCallerIdentity(){
|
||||
const client = await this.getStsClient();
|
||||
|
||||
// 调用 GetCallerIdentity 接口
|
||||
const result = await client.GetCallerIdentity();
|
||||
|
||||
this.ctx.logger.info("✅ 密钥有效!");
|
||||
this.ctx.logger.info(` 账户ID: ${result.AccountId}`);
|
||||
this.ctx.logger.info(` ARN: ${result.Arn}`);
|
||||
this.ctx.logger.info(` 用户ID: ${result.UserId}`);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
accountId: result.AccountId,
|
||||
arn: result.Arn,
|
||||
userId: result.UserId
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async getStsClient(){
|
||||
const sdk = await import('tencentcloud-sdk-nodejs/tencentcloud/services/sts/v20180813/index.js');
|
||||
const StsClient = sdk.v20180813.Client;
|
||||
|
||||
const clientConfig = {
|
||||
credential: {
|
||||
secretId: this.secretId,
|
||||
secretKey: this.secretKey,
|
||||
},
|
||||
region: 'ap-shanghai',
|
||||
profile: {
|
||||
httpProfile: {
|
||||
endpoint: `sts.${this.intlDomain()}tencentcloudapi.com`,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return new StsClient(clientConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ export class SynologyKeepAlivePlugin extends AbstractPlusTaskPlugin {
|
||||
this.logger.info(`下一次刷新时间${lastTime.add(this.intervalDays, "day").format("YYYY-MM-DD")}`);
|
||||
return "skip";
|
||||
}else{
|
||||
this.logger.info(`超过${this.intervalDays}天,需要刷新`);
|
||||
this.logger.info(`超过${this.intervalDays}天,需要刷新`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { IsAccess, AccessInput, BaseAccess } from "@certd/pipeline";
|
||||
import { UniCloudClient } from "@certd/plugin-plus";
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -30,6 +31,27 @@ export class UniCloudAccess extends BaseAccess {
|
||||
})
|
||||
password = "";
|
||||
|
||||
// await this.getToken();
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "onTestRequest",
|
||||
},
|
||||
helper: "点击测试接口看是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
const client = new UniCloudClient({
|
||||
access: this,
|
||||
logger: this.ctx.logger,
|
||||
http: this.ctx.http,
|
||||
});
|
||||
await client.getToken();
|
||||
return "ok";
|
||||
}
|
||||
}
|
||||
|
||||
new UniCloudAccess();
|
||||
|
||||
@@ -30,6 +30,85 @@ export class YidunRcdnAccess extends BaseAccess {
|
||||
encrypt: true,
|
||||
})
|
||||
password = "";
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "onTestRequest",
|
||||
},
|
||||
helper: "点击测试接口看是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
const token = await this.getLoginToken();
|
||||
await this.getDomainList(token);
|
||||
return "ok";
|
||||
}
|
||||
|
||||
async getDomainList(loginRes: any) {
|
||||
const url = "https://rhcdn.yiduncdn.com/CdnDomain/queryForDatatables";
|
||||
const data = {
|
||||
draw: 1,
|
||||
start: 0,
|
||||
length: 1000,
|
||||
search: {
|
||||
value: "",
|
||||
regex: false,
|
||||
},
|
||||
};
|
||||
|
||||
const res = await this.doRequest(url, loginRes, data);
|
||||
return res.data?.data;
|
||||
}
|
||||
|
||||
async doRequest(url: string, loginRes: any, data: any) {
|
||||
const http = this.ctx.http;
|
||||
const res: any = await http.request({
|
||||
url,
|
||||
method: "POST",
|
||||
headers: {
|
||||
Cookie: `JSESSIONID=${loginRes.jsessionId};kuocai_cdn_token=${loginRes.token}`,
|
||||
},
|
||||
data,
|
||||
});
|
||||
if (!res.success) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
async getLoginToken() {
|
||||
const access: YidunRcdnAccess = this
|
||||
const url = "https://rhcdn.yiduncdn.com/login/loginUser";
|
||||
const data = {
|
||||
userAccount: access.username,
|
||||
userPwd: access.password,
|
||||
remember: true,
|
||||
};
|
||||
const http = this.ctx.http;
|
||||
const res: any = await http.request({
|
||||
url,
|
||||
method: "POST",
|
||||
data,
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
returnOriginRes: true,
|
||||
});
|
||||
if (!res.data?.success) {
|
||||
throw new Error(res.data?.message);
|
||||
}
|
||||
|
||||
const jsessionId = this.ctx.utils.request.getCookie(res, "JSESSIONID");
|
||||
const token = res.data?.data;
|
||||
return {
|
||||
jsessionId,
|
||||
token,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
new YidunRcdnAccess();
|
||||
|
||||
@@ -32,6 +32,47 @@ export class YidunAccess extends BaseAccess {
|
||||
encrypt: true,
|
||||
})
|
||||
apiSecret = "";
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "onTestRequest",
|
||||
},
|
||||
helper: "点击测试接口看是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getDomainList();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
async getDomainList(){
|
||||
const siteUrl = "http://user.yiduncdn.com/v1/sites";
|
||||
const res = await this.doRequest(siteUrl, "GET", { });
|
||||
return res.data
|
||||
}
|
||||
|
||||
async doRequest(url: string, method: string, data: any) {
|
||||
const access = this
|
||||
const { apiKey, apiSecret } = access;
|
||||
const http = this.ctx.http;
|
||||
const res: any = await http.request({
|
||||
url,
|
||||
method,
|
||||
headers: {
|
||||
"api-key": apiKey,
|
||||
"api-secret": apiSecret,
|
||||
},
|
||||
data,
|
||||
});
|
||||
if (res.code != 0) {
|
||||
throw new Error(res.msg);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new YidunAccess();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
|
||||
import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
|
||||
import { YidunAccess } from "../access.js";
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: "YidunDeployToCDN",
|
||||
@@ -60,7 +61,11 @@ export class YidunDeployToCDNPlugin extends AbstractTaskPlugin {
|
||||
})
|
||||
accessId!: string;
|
||||
|
||||
async onInstance() {}
|
||||
access!: YidunAccess;
|
||||
|
||||
async onInstance() {
|
||||
this.access = await this.getAccess<YidunAccess>(this.accessId);
|
||||
}
|
||||
async execute(): Promise<void> {
|
||||
const { domain, certId, cert } = this;
|
||||
if (!domain && !certId) {
|
||||
@@ -77,35 +82,21 @@ export class YidunDeployToCDNPlugin extends AbstractTaskPlugin {
|
||||
private async updateByCertId(cert: CertInfo, certId: number) {
|
||||
this.logger.info(`更新证书,证书ID:${certId}`);
|
||||
const url = `http://user.yiduncdn.com/v1/certs/${certId}`;
|
||||
await this.doRequest(url, "PUT", {
|
||||
|
||||
const access = await this.getAccess<YidunAccess>(this.accessId);
|
||||
|
||||
await access.doRequest(url, "PUT", {
|
||||
cert: cert.crt,
|
||||
key: cert.key,
|
||||
});
|
||||
}
|
||||
|
||||
async doRequest(url: string, method: string, data: any) {
|
||||
const access = await this.getAccess(this.accessId);
|
||||
const { apiKey, apiSecret } = access;
|
||||
const http = this.ctx.http;
|
||||
const res: any = await http.request({
|
||||
url,
|
||||
method,
|
||||
headers: {
|
||||
"api-key": apiKey,
|
||||
"api-secret": apiSecret,
|
||||
},
|
||||
data,
|
||||
});
|
||||
if (res.code != 0) {
|
||||
throw new Error(res.msg);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
private async updateByDomain(cert: CertInfo) {
|
||||
//查询站点
|
||||
const siteUrl = "http://user.yiduncdn.com/v1/sites";
|
||||
const res = await this.doRequest(siteUrl, "GET", { domain: this.domain });
|
||||
const access = this.access
|
||||
const res = await access.doRequest(siteUrl, "GET", { domain: this.domain });
|
||||
if (res.data.length === 0) {
|
||||
throw new Error(`未找到域名相关站点:${this.domain}`);
|
||||
}
|
||||
@@ -127,20 +118,20 @@ export class YidunDeployToCDNPlugin extends AbstractTaskPlugin {
|
||||
this.logger.info(`创建证书,域名:${this.domain}`);
|
||||
const certUrl = `http://user.yiduncdn.com/v1/certs`;
|
||||
const name = this.domain + "_" + new Date().getTime();
|
||||
await this.doRequest(certUrl, "POST", {
|
||||
await access.doRequest(certUrl, "POST", {
|
||||
name,
|
||||
type: "custom",
|
||||
cert: cert.crt,
|
||||
key: cert.key,
|
||||
});
|
||||
|
||||
const certs: any = await this.doRequest(certUrl, "GET", {
|
||||
const certs: any = await access.doRequest(certUrl, "GET", {
|
||||
name,
|
||||
});
|
||||
const certId = certs.data[0].id;
|
||||
|
||||
const siteUrl = "http://user.yiduncdn.com/v1/sites";
|
||||
await this.doRequest(siteUrl, "PUT", { id: site.id, https_listen: { cert: certId } });
|
||||
await access.doRequest(siteUrl, "PUT", { id: site.id, https_listen: { cert: certId } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export class YidunDeployToRCDNPlugin extends AbstractTaskPlugin {
|
||||
async onInstance() {}
|
||||
async execute(): Promise<void> {
|
||||
const access = await this.getAccess<YidunRcdnAccess>(this.accessId);
|
||||
const loginRes = await this.getLoginToken(access);
|
||||
const loginRes = await access.getLoginToken();
|
||||
|
||||
const curl = "https://rhcdn.yiduncdn.com/CdnDomainHttps/httpsConfiguration";
|
||||
for (const domain of this.domains) {
|
||||
@@ -78,71 +78,14 @@ export class YidunDeployToRCDNPlugin extends AbstractTaskPlugin {
|
||||
private_key: cert.key,
|
||||
},
|
||||
};
|
||||
await this.doRequest(curl, loginRes, update);
|
||||
await access.doRequest(curl, loginRes, update);
|
||||
this.logger.info(`站点${domain}证书更新成功`);
|
||||
}
|
||||
}
|
||||
|
||||
async getLoginToken(access: YidunRcdnAccess) {
|
||||
const url = "https://rhcdn.yiduncdn.com/login/loginUser";
|
||||
const data = {
|
||||
userAccount: access.username,
|
||||
userPwd: access.password,
|
||||
remember: true,
|
||||
};
|
||||
const http = this.ctx.http;
|
||||
const res: any = await http.request({
|
||||
url,
|
||||
method: "POST",
|
||||
data,
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
returnOriginRes: true,
|
||||
});
|
||||
if (!res.data?.success) {
|
||||
throw new Error(res.data?.message);
|
||||
}
|
||||
|
||||
|
||||
const jsessionId = this.ctx.utils.request.getCookie(res, "JSESSIONID");
|
||||
const token = res.data?.data;
|
||||
return {
|
||||
jsessionId,
|
||||
token,
|
||||
};
|
||||
}
|
||||
|
||||
async getDomainList(loginRes: any) {
|
||||
const url = "https://rhcdn.yiduncdn.com/CdnDomain/queryForDatatables";
|
||||
const data = {
|
||||
draw: 1,
|
||||
start: 0,
|
||||
length: 1000,
|
||||
search: {
|
||||
value: "",
|
||||
regex: false,
|
||||
},
|
||||
};
|
||||
|
||||
const res = await this.doRequest(url, loginRes, data);
|
||||
return res.data?.data;
|
||||
}
|
||||
|
||||
private async doRequest(url: string, loginRes: any, data: any) {
|
||||
const http = this.ctx.http;
|
||||
const res: any = await http.request({
|
||||
url,
|
||||
method: "POST",
|
||||
headers: {
|
||||
Cookie: `JSESSIONID=${loginRes.jsessionId};kuocai_cdn_token=${loginRes.token}`,
|
||||
},
|
||||
data,
|
||||
});
|
||||
if (!res.success) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
async onGetDomainList(data: any) {
|
||||
if (!this.accessId) {
|
||||
@@ -150,9 +93,9 @@ export class YidunDeployToRCDNPlugin extends AbstractTaskPlugin {
|
||||
}
|
||||
const access = await this.getAccess<YidunRcdnAccess>(this.accessId);
|
||||
|
||||
const loginRes = await this.getLoginToken(access);
|
||||
const loginRes = await access.getLoginToken();
|
||||
|
||||
const list = await this.getDomainList(loginRes);
|
||||
const list = await access.getDomainList(loginRes);
|
||||
|
||||
if (!list || list.length === 0) {
|
||||
throw new Error("您账户下还没有站点域名,请先添加域名");
|
||||
|
||||
@@ -70,6 +70,47 @@ export class ProxmoxAccess extends BaseAccess {
|
||||
encrypt: false,
|
||||
})
|
||||
realm = '';
|
||||
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "onTestRequest",
|
||||
},
|
||||
helper: "点击测试接口看是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getNodeList();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
||||
|
||||
async getNodeList() {
|
||||
const client = await this.getClient();
|
||||
const nodesRes = await client.nodes.index();
|
||||
// this.logger.info('nodes:', nodesRes.response);
|
||||
if (!nodesRes.response?.data) {
|
||||
return []
|
||||
}
|
||||
return nodesRes.response.data
|
||||
}
|
||||
|
||||
async getClient() {
|
||||
const pve = await import('@certd/cv4pve-api-javascript');
|
||||
const client = new pve.PveClient(this.host, this.port);
|
||||
const login = await client.login(this.username, this.password, this.realm || 'pam');
|
||||
if (!login) {
|
||||
throw new Error(`Login failed:${JSON.stringify(login)}`);
|
||||
}
|
||||
const versionRes = await client.version.version();
|
||||
this.ctx.logger.info('Proxmox version:', versionRes.response);
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
||||
new ProxmoxAccess();
|
||||
|
||||
@@ -66,8 +66,8 @@ export class ProxmoxUploadCert extends AbstractPlusTaskPlugin {
|
||||
//插件执行方法
|
||||
async execute(): Promise<void> {
|
||||
const { cert } = this;
|
||||
|
||||
const client = await this.getClient();
|
||||
const access = await this.getAccess<ProxmoxAccess>(this.accessId);
|
||||
const client = await access.getClient();
|
||||
|
||||
for (const node of this.nodes) {
|
||||
this.logger.info(`开始上传证书到节点:${node}`);
|
||||
@@ -84,31 +84,17 @@ export class ProxmoxUploadCert extends AbstractPlusTaskPlugin {
|
||||
this.logger.info('部署成功');
|
||||
}
|
||||
|
||||
async onGetNodeList() {
|
||||
const client = await this.getClient();
|
||||
async onGetNodeList() {
|
||||
|
||||
const nodesRes = await client.nodes.index();
|
||||
// this.logger.info('nodes:', nodesRes.response);
|
||||
return nodesRes.response.data.map((node: any) => {
|
||||
const access = await this.getAccess<ProxmoxAccess>(this.accessId);
|
||||
const nodesRes = await access.getNodeList();
|
||||
return nodesRes.map((node: any) => {
|
||||
return {
|
||||
value: node.node,
|
||||
label: node.node,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async getClient() {
|
||||
const access: ProxmoxAccess = await this.getAccess<ProxmoxAccess>(this.accessId);
|
||||
const pve = await import('@certd/cv4pve-api-javascript');
|
||||
const client = new pve.PveClient(access.host, access.port);
|
||||
const login = await client.login(access.username, access.password, access.realm || 'pam');
|
||||
if (!login) {
|
||||
throw new Error(`Login failed:${JSON.stringify(login)}`);
|
||||
}
|
||||
const versionRes = await client.version.version();
|
||||
this.logger.info('Proxmox version:', versionRes.response);
|
||||
return client;
|
||||
}
|
||||
}
|
||||
//实例化一下,注册插件
|
||||
new ProxmoxUploadCert();
|
||||
|
||||
@@ -108,15 +108,10 @@ export class QiniuDeployCertToCDN extends AbstractTaskPlugin {
|
||||
|
||||
async onGetDomainList() {
|
||||
const access = await this.getAccess<QiniuAccess>(this.accessId);
|
||||
const qiniuClient = new QiniuClient({
|
||||
http: this.ctx.http,
|
||||
access,
|
||||
logger: this.logger,
|
||||
});
|
||||
const url = `https://api.qiniu.com/domain?limit=1000`;
|
||||
const res = await qiniuClient.doRequest(url, 'get');
|
||||
|
||||
const domains = await access.getDomainList()
|
||||
|
||||
const options = res.domains.map((item: any) => {
|
||||
const options = domains.map((item: any) => {
|
||||
return {
|
||||
value: item.name,
|
||||
label: item.name,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {AccessInput, BaseAccess, IsAccess} from '@certd/pipeline';
|
||||
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
|
||||
import { UpyunClient } from './client.js';
|
||||
|
||||
/**
|
||||
* 这个注解将注册一个授权配置
|
||||
@@ -30,6 +31,41 @@ export class UpyunAccess extends BaseAccess {
|
||||
})
|
||||
password = '';
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "onTestRequest",
|
||||
},
|
||||
helper: "点击测试接口看是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getCdnList();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
||||
async getCdnList() {
|
||||
const upyunClient = new UpyunClient({
|
||||
access: this,
|
||||
logger: this.ctx.logger,
|
||||
http: this.ctx.http
|
||||
});
|
||||
const cookie = await upyunClient.getLoginToken();
|
||||
const req = {
|
||||
cookie,
|
||||
url: "https://console.upyun.com/api/account/domains/?limit=1000&business_type=file&security_cdn=false&websocket=false&key=&domain=",
|
||||
method: "GET",
|
||||
data: {}
|
||||
};
|
||||
const res = await upyunClient.doRequest(req);
|
||||
const domains = res.data?.domains || [];
|
||||
return domains
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
new UpyunAccess();
|
||||
|
||||
@@ -160,21 +160,7 @@ export class UpyunDeployToCdn extends AbstractTaskPlugin {
|
||||
}
|
||||
const access = await this.getAccess<UpyunAccess>(this.accessId);
|
||||
|
||||
const upyunClient = new UpyunClient({
|
||||
access,
|
||||
logger: this.logger,
|
||||
http: this.ctx.http
|
||||
});
|
||||
const cookie = await upyunClient.getLoginToken();
|
||||
const req = {
|
||||
cookie,
|
||||
url: "https://console.upyun.com/api/account/domains/?limit=15&business_type=file&security_cdn=false&websocket=false&key=&domain=",
|
||||
method: "GET",
|
||||
data: {}
|
||||
};
|
||||
const res = await upyunClient.doRequest(req);
|
||||
|
||||
const domains = res.data?.domains;
|
||||
const domains = await access.getCdnList();
|
||||
if (!domains || domains.length === 0) {
|
||||
throw new Error("没有找到加速域名");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {AccessInput, BaseAccess, IsAccess} from '@certd/pipeline';
|
||||
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
|
||||
import { VolcengineClient } from './ve-client.js';
|
||||
|
||||
/**
|
||||
* 这个注解将注册一个授权配置
|
||||
@@ -18,7 +19,7 @@ export class VolcengineAccess extends BaseAccess {
|
||||
component: {
|
||||
placeholder: 'AccessKeyID',
|
||||
},
|
||||
helper:"[获取密钥](https://console.volcengine.com/iam/keymanage/)",
|
||||
helper: "[获取密钥](https://console.volcengine.com/iam/keymanage/)",
|
||||
required: true,
|
||||
})
|
||||
accessKeyId = '';
|
||||
@@ -32,6 +33,50 @@ export class VolcengineAccess extends BaseAccess {
|
||||
})
|
||||
secretAccessKey = '';
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "onTestRequest",
|
||||
},
|
||||
helper: "点击测试接口看是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getCallerIdentity();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
async getCallerIdentity() {
|
||||
const veClient = new VolcengineClient({
|
||||
access: this,
|
||||
logger: this.ctx.logger,
|
||||
http: this.ctx.http,
|
||||
});
|
||||
const service = await veClient.getStsService();
|
||||
|
||||
const res = await service.request({
|
||||
action: "GetCallerIdentity",
|
||||
});
|
||||
|
||||
const result = res.Result || {};
|
||||
this.ctx.logger.info("✅ 密钥有效!");
|
||||
this.ctx.logger.info(` 账户ID: ${result.AccountId}`);
|
||||
this.ctx.logger.info(` ARN: ${result.Trn}`);
|
||||
this.ctx.logger.info(` 用户ID: ${result.IdentityId}`);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
accountId: result.AccountId,
|
||||
arn: result.Trn,
|
||||
userId: result.IdentityId
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
new VolcengineAccess();
|
||||
|
||||
@@ -113,6 +113,19 @@ export class VolcengineClient {
|
||||
return service;
|
||||
}
|
||||
|
||||
async getStsService() {
|
||||
const CommonService = await this.getServiceCls();
|
||||
|
||||
const service = new CommonService({
|
||||
serviceName: "sts",
|
||||
defaultVersion: "2018-01-01"
|
||||
});
|
||||
service.setAccessKeyId(this.opts.access.accessKeyId);
|
||||
service.setSecretKey(this.opts.access.secretAccessKey);
|
||||
service.setRegion("cn-north-1");
|
||||
return service;
|
||||
}
|
||||
|
||||
async getServiceCls() {
|
||||
if (this.CommonService) {
|
||||
return this.CommonService;
|
||||
|
||||
@@ -37,6 +37,25 @@ export class XinnetConnectAccess extends BaseAccess {
|
||||
})
|
||||
password = '';
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "onTestRequest",
|
||||
},
|
||||
helper: "点击测试接口看是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getDomainList({
|
||||
pageNo: 1,
|
||||
pageSize: 1,
|
||||
});
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
||||
|
||||
async getDomainList(req: PageSearch): Promise<any> {
|
||||
let bodyXml =`
|
||||
|
||||
Reference in New Issue
Block a user