chore: 补充其他access的测试按钮

This commit is contained in:
xiaojunnuo
2026-02-15 22:45:22 +08:00
parent 9671348dc1
commit 7cd8a645a8
16 changed files with 420 additions and 136 deletions
@@ -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("您账户下还没有站点域名,请先添加域名");