chore: format

This commit is contained in:
xiaojunnuo
2026-05-31 01:41:33 +08:00
parent acd440106b
commit 4b57a0d729
557 changed files with 12530 additions and 14039 deletions
@@ -152,7 +152,7 @@ export class OnePanelAccess extends BaseAccess {
page: 1,
pageSize: 1,
order: "ascending",
orderBy: "expire_date"
orderBy: "expire_date",
},
});
return "ok";
@@ -93,8 +93,8 @@ export class OnePanelClient {
if (res.code === 200) {
return res.data;
}
if (res?.message?.includes("record not found")){
throw new Error("没有找到证书,请确认证书在1panel上是否已被删除,如果被删除请重新选择新的证书id:"+ config.url);
if (res?.message?.includes("record not found")) {
throw new Error("没有找到证书,请确认证书在1panel上是否已被删除,如果被删除请重新选择新的证书id:" + config.url);
}
throw new Error(res.message);
}
@@ -67,7 +67,7 @@ export class OnePanelDeployToPanelPlugin extends AbstractTaskPlugin {
options: [
{ label: "启用SSL(旧版本)", value: "enable" },
{ label: "Strict模式(>=2.1.x)", value: "Enable" },
{ label: "Mux模式(>=2.1.x)", value: "Mux" }
{ label: "Mux模式(>=2.1.x)", value: "Mux" },
],
},
value: "enable",
@@ -81,7 +81,6 @@ export class OnePanelDeployToPanelPlugin extends AbstractTaskPlugin {
}
//http://xxx:xxxx/1panel/swagger/index.html#/App/get_apps__key
async execute(): Promise<void> {
const client = new OnePanelClient({
access: this.access,
http: this.http,
@@ -89,7 +88,6 @@ export class OnePanelDeployToPanelPlugin extends AbstractTaskPlugin {
utils: this.ctx.utils,
});
const certReader = new CertReader(this.cert);
const domain = certReader.getMainDomain();
@@ -129,7 +127,6 @@ export class OnePanelDeployToPanelPlugin extends AbstractTaskPlugin {
await this.ctx.utils.sleep(10000);
this.logger.info(`证书更新完成`);
}
isNeedUpdate(certRes: any) {
@@ -140,8 +137,6 @@ export class OnePanelDeployToPanelPlugin extends AbstractTaskPlugin {
return true;
}
async onGetNodes() {
const options = [{ label: "主节点", value: "local" }];
if (this.access.apiVersion === "v1") {
@@ -166,6 +161,5 @@ export class OnePanelDeployToPanelPlugin extends AbstractTaskPlugin {
// console.log('resp', resp)
return [...options, ...(resp?.map(item => ({ label: `${item.addr}(${item.name})`, value: item.name })) || [])];
}
}
new OnePanelDeployToPanelPlugin();
@@ -66,7 +66,7 @@ export class OnePanelDeployToWebsitePlugin extends AbstractTaskPlugin {
watches: ["accessId"],
helper: "要更新的1Panel证书id,选择授权之后,从下拉框中选择\nIP需要加白名单,如果是同一台机器部署的,可以试试172.16.0.0/12",
required: true,
uploadCert: {}
uploadCert: {},
})
)
sslIds!: string[];
@@ -196,7 +196,7 @@ export class OnePanelDeployToWebsitePlugin extends AbstractTaskPlugin {
page: 1,
pageSize: 99999,
order: "ascending",
orderBy: "expire_date"
orderBy: "expire_date",
},
currentNode: this.currentNode,
});
@@ -215,11 +215,11 @@ export class OnePanelDeployToWebsitePlugin extends AbstractTaskPlugin {
return this.ctx.utils.options.buildGroupOptions(list, this.certDomains);
}
async onUploadCert(data: { pipelineId: string, certName: string }) {
async onUploadCert(data: { pipelineId: string; certName: string }) {
if (!this.access) {
throw new Error("请先选择1panel授权");
}
const certInfoGetter = await this.ctx.serviceGetter.get<ICertInfoGetter>("certInfoGetter")
const certInfoGetter = await this.ctx.serviceGetter.get<ICertInfoGetter>("certInfoGetter");
const cert = await certInfoGetter.getByPipelineId(Number(data.pipelineId));
const client = new OnePanelClient({
@@ -243,7 +243,6 @@ export class OnePanelDeployToWebsitePlugin extends AbstractTaskPlugin {
},
currentNode: this.currentNode,
});
}
}
new OnePanelDeployToWebsitePlugin();
@@ -1,2 +1,2 @@
export * from "./deploy-to-website.js";
export * from "./deploy-to-panel.js";
export * from "./deploy-to-panel.js";
@@ -41,7 +41,7 @@ function generateAESKey(): string {
const randomBytes = new Uint8Array(keyLength);
crypto.getRandomValues(randomBytes);
return Array.from(randomBytes)
.map((b) => b.toString(16).padStart(2, "0"))
.map(b => b.toString(16).padStart(2, "0"))
.join("");
}
@@ -227,7 +227,7 @@ export class DeployCertToBaiduCcePlugin extends AbstractTaskPlugin {
secretNames = [secretName];
}
for (const secret of secretNames) {
await k8sClient.patchSecret({ namespace, secretName: secret, body ,createOnNotFound: this.createOnNotFound});
await k8sClient.patchSecret({ namespace, secretName: secret, body, createOnNotFound: this.createOnNotFound });
this.logger.info(`cert secret已更新: ${secret}`);
}
}
@@ -242,4 +242,4 @@ export class DeployCertToBaiduCcePlugin extends AbstractTaskPlugin {
}
}
new DeployCertToBaiduCcePlugin();
new DeployCertToBaiduCcePlugin();
@@ -1,4 +1,4 @@
export * from "./plugins/index.js";
export * from "./access.js";
export * from "./waf-access.js";
export * from "./lib/client.js";
export * from "./lib/client.js";
@@ -30,8 +30,6 @@ export class CtyunAccess extends BaseAccess {
})
securityKey = "";
@AccessInput({
title: "测试",
component: {
@@ -43,23 +41,23 @@ export class CtyunAccess extends BaseAccess {
testRequest = true;
async onTestRequest() {
await this.getCdnDomainList()
await this.getCdnDomainList();
return "ok";
}
async getCdnDomainList() {
const http: HttpClient = this.ctx.http;
const client = new CtyunClient({
access:this,
http,
logger: this.ctx.logger,
});
// 008 是天翼云的CDN加速域名产品码
const all = await client.getDomainList({ productCode: "008" });
const list = all || []
return list
}
async getCdnDomainList() {
const http: HttpClient = this.ctx.http;
const client = new CtyunClient({
access: this,
http,
logger: this.ctx.logger,
});
// 008 是天翼云的CDN加速域名产品码
const all = await client.getDomainList({ productCode: "008" });
const list = all || [];
return list;
}
}
new CtyunAccess();
@@ -1,3 +1,3 @@
export * from "./plugins/index.js";
export * from "./access/ctyun-access.js";
export * from "./lib.js";
export * from "./lib.js";
@@ -1 +1 @@
export * from "./plugin-deploy-to-esxi.js";
export * from "./plugin-deploy-to-esxi.js";
@@ -43,8 +43,7 @@ export class EsxiDeployCertPlugin extends AbstractPlusTaskPlugin {
})
accessId!: string;
async onInstance() { }
async onInstance() {}
async execute(): Promise<void> {
const sshConf = await this.getAccess<SshAccess>(this.accessId);
@@ -56,7 +55,7 @@ export class EsxiDeployCertPlugin extends AbstractPlusTaskPlugin {
await certReader.readCertFile({
logger: this.logger,
handle: async (ctx) => {
handle: async ctx => {
const crtPath = ctx.tmpCrtPath;
const keyPath = ctx.tmpKeyPath;
await sshClient.uploadFiles({
@@ -77,7 +76,7 @@ export class EsxiDeployCertPlugin extends AbstractPlusTaskPlugin {
});
const cmd = `/etc/init.d/hostd restart
/etc/init.d/vpxa restart`
/etc/init.d/vpxa restart`;
await sshClient.exec({
connectConf: sshConf,
@@ -30,8 +30,6 @@ export class K8sAccess extends BaseAccess {
})
skipTLSVerify: boolean;
@AccessInput({
title: "测试",
component: {
@@ -43,13 +41,12 @@ export class K8sAccess extends BaseAccess {
testRequest = true;
async onTestRequest() {
const k8sClient = await this.getK8sClient()
const k8sClient = await this.getK8sClient();
await k8sClient.getSecrets({
namespace: "default",
})
});
return "ok";
}
}
async getK8sClient() {
const sdk = await import("@certd/lib-k8s");
@@ -62,7 +59,6 @@ export class K8sAccess extends BaseAccess {
});
return k8sClient;
}
}
new K8sAccess();
@@ -31,8 +31,6 @@ export class KuocaiCdnAccess extends BaseAccess {
})
password = "";
@AccessInput({
title: "测试",
component: {
@@ -47,9 +45,8 @@ export class KuocaiCdnAccess extends BaseAccess {
const loginRes = await this.getLoginToken();
await this.getDomainList(loginRes);
return "ok";
}
}
async getLoginToken() {
const url = "https://kuocaicdn.com/login/loginUser";
const data = {
@@ -110,7 +107,6 @@ export class KuocaiCdnAccess extends BaseAccess {
}
return res;
}
}
new KuocaiCdnAccess();
@@ -83,7 +83,6 @@ export class KuocaiDeployToCDNPlugin extends AbstractTaskPlugin {
}
}
async onGetDomainList(data: any) {
if (!this.accessId) {
throw new Error("请选择Access授权");
@@ -86,7 +86,6 @@ export class LeCDNAccess extends BaseAccess {
})
apiToken = "";
@AccessInput({
title: "测试",
component: {
@@ -102,11 +101,9 @@ export class LeCDNAccess extends BaseAccess {
async onTestRequest() {
await this.getCerts();
return "ok";
}
}
async getCerts() {
async getCerts() {
// http://cdnadmin.kxfox.com/prod-api/certificate?current_page=1&total=3&page_size=10
return await this.doRequest({
url: `/prod-api/certificate`,
@@ -118,8 +115,7 @@ export class LeCDNAccess extends BaseAccess {
});
}
async doRequest(config: any) {
async doRequest(config: any) {
const token = await this.getToken();
const access = this;
const Authorization = access.type === "token" ? access.apiToken : `Bearer ${token}`;
@@ -134,41 +130,39 @@ export class LeCDNAccess extends BaseAccess {
return res.data;
}
async getToken() {
if (this.type === "token") {
return this.apiToken;
}
if (this._token){
return this._token;
}
// http://cdnadmin.kxfox.com/prod-api/login
const access = this;
const res = await this.ctx.http.request({
url: `/prod-api/login`,
baseURL: access.url,
method: "post",
data: {
//新旧版本不一样,旧版本是username,新版本是email
email: access.username,
username: access.username,
password: access.password,
},
});
this.checkRes(res);
//新旧版本不一样,旧版本是access_token,新版本是token
const token = res.data.access_token || res.data.token;
this._token = token;
return token;
if (this.type === "token") {
return this.apiToken;
}
if (this._token) {
return this._token;
}
// http://cdnadmin.kxfox.com/prod-api/login
const access = this;
const res = await this.ctx.http.request({
url: `/prod-api/login`,
baseURL: access.url,
method: "post",
data: {
//新旧版本不一样,旧版本是username,新版本是email
email: access.username,
username: access.username,
password: access.password,
},
});
this.checkRes(res);
//新旧版本不一样,旧版本是access_token,新版本是token
const token = res.data.access_token || res.data.token;
private checkRes(res: any) {
this._token = token;
return token;
}
private checkRes(res: any) {
if (res.code !== 0 && res.code !== 200) {
throw new Error(res.message || JSON.stringify(res));
}
}
}
new LeCDNAccess();
@@ -61,8 +61,6 @@ export class LeCDNUpdateCertV2 extends AbstractTaskPlugin {
this.access.getToken();
}
async getCertInfo(id: number) {
// http://cdnadmin.kxfox.com/prod-api/certificate/9
// Bearer edGkiOiIJ8
@@ -100,8 +98,6 @@ export class LeCDNUpdateCertV2 extends AbstractTaskPlugin {
this.logger.info(`更新证书完成`);
}
async onGetCertList(data: any) {
if (!this.accessId) {
throw new Error("请选择Access授权");
@@ -50,7 +50,6 @@ export class LuckyAccess extends BaseAccess {
})
openToken = "";
@AccessInput({
title: "测试",
component: {
@@ -66,7 +65,6 @@ export class LuckyAccess extends BaseAccess {
return "ok";
}
async doRequest(req: { urlPath: string; data: any; method?: string }) {
const { urlPath, data, method } = req;
let url = `${this.url}/${this.safePath || ""}${urlPath}?_=${Math.floor(new Date().getTime())}`;
@@ -103,7 +101,7 @@ export class LuckyAccess extends BaseAccess {
method: "GET",
});
const list = res.list || [];
return list
return list;
}
}
@@ -84,11 +84,8 @@ export class MaoyunAccess extends BaseAccess {
method: "GET",
});
const list = res.data || [];
return list
return list;
}
}
new MaoyunAccess();
@@ -1,6 +1,6 @@
import { IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
import { CertReader } from "@certd/plugin-lib";
import { CertReader } from "@certd/plugin-lib";
import { SshAccess } from "../../plugin-lib/ssh/ssh-access.js";
import { SshClient } from "../../plugin-lib/ssh/ssh.js";
import { AbstractPlusTaskPlugin } from "@certd/plugin-plus";
@@ -43,8 +43,7 @@ export class OpenwrtDeployCertPlugin extends AbstractPlusTaskPlugin {
})
accessId!: string;
async onInstance() { }
async onInstance() {}
async execute(): Promise<void> {
const sshConf = await this.getAccess<SshAccess>(this.accessId);
@@ -56,7 +55,7 @@ export class OpenwrtDeployCertPlugin extends AbstractPlusTaskPlugin {
await certReader.readCertFile({
logger: this.logger,
handle: async (ctx) => {
handle: async ctx => {
const crtPath = ctx.tmpCrtPath;
const keyPath = ctx.tmpKeyPath;
await sshClient.uploadFiles({
@@ -77,7 +76,7 @@ export class OpenwrtDeployCertPlugin extends AbstractPlusTaskPlugin {
});
this.logger.info(`证书上传完成,准备重启uhttpd生效`);
const cmd = `/etc/init.d/uhttpd restart`
const cmd = `/etc/init.d/uhttpd restart`;
await sshClient.exec({
connectConf: sshConf,
@@ -64,10 +64,9 @@ export class SafelineAccess extends BaseAccess {
data: {},
});
const nodes = res?.nodes || [];
return nodes
return nodes;
}
async doRequest(config: HttpRequestConfig<any>) {
config.baseURL = this.baseUrl;
config.skipSslVerify = this.skipSslVerify ?? false;
@@ -82,7 +81,6 @@ export class SafelineAccess extends BaseAccess {
}
throw new Error(res.msg);
}
}
new SafelineAccess();
@@ -68,30 +68,28 @@ export class SafelineDeployToWebsitePlugin extends AbstractTaskPlugin {
}
async uploadCert(certId: number) {
const data:any = {
const data: any = {
manual: {
crt: this.cert.crt,
key: this.cert.key,
},
type: 2,
};
let type = "新增"
let type = "新增";
// @ts-ignore
if (certId !== "0" && certId >0) {
if (certId !== "0" && certId > 0) {
//@ts-ignore
data.id = parseInt(certId)
type = "更新"
data.id = parseInt(certId);
type = "更新";
}
const res = await this.access.doRequest({
url: "/api/open/cert",
method: "post",
data:data
data: data,
});
this.logger.info(`证书<${certId}>${type}成功,ID:${res}`);
}
// requestHandle
async onGetCertIds() {
@@ -63,7 +63,7 @@ export class SynologyAccess extends BaseAccess {
name: "a-switch",
vModel: "checked",
},
col:{span:24},
col: { span: 24 },
helper: "是否启用了双重认证",
required: true,
})
@@ -77,7 +77,7 @@ export class SynologyAccess extends BaseAccess {
type: "access",
typeName: "synology",
},
col:{span:24},
col: { span: 24 },
mergeScript: `
return {
component:{
@@ -58,10 +58,10 @@ export class SynologyDeployToPanel extends AbstractPlusTaskPlugin {
async onInstance() {}
async execute(): Promise<void> {
const access: SynologyAccess = await this.getAccess<SynologyAccess>(this.accessId);
if (access.deviceId){
this.logger.warn(`检测到您开启了二次认证,建议将证书申请任务的更新天数修改为65天,以保证每个月在群辉部署执行一次,刷新二次认证的有效期`);
if (access.deviceId) {
this.logger.warn(`检测到您开启了二次认证,建议将证书申请任务的更新天数修改为65天,以保证每个月在群辉部署执行一次,刷新二次认证的有效期`);
}
const client = new SynologyClient(access as any, this.ctx.http, this.ctx.logger, access.skipSslVerify);
// await client.init();
await client.doLogin();
@@ -76,16 +76,14 @@ export class SynologyDeployToPanel extends AbstractPlusTaskPlugin {
throw new Error(`未找到证书: ${this.certName}`);
}
this.logger.info(`找到证书: ${certItem.id}`);
await client.updateCertToPanel(certItem,this.cert);
await client.updateCertToPanel(certItem, this.cert);
} else {
this.logger.info("开始更新全部证书");
for (const item of certListRes.certificates) {
this.logger.info(`更新证书: ${item.id}`);
await client.updateCertToPanel(item,this.cert);
await client.updateCertToPanel(item, this.cert);
}
}
}
}
new SynologyDeployToPanel();
@@ -17,8 +17,6 @@ import { SynologyAccess } from "../access.js";
needPlus: true,
})
export class SynologyKeepAlivePlugin extends AbstractPlusTaskPlugin {
@TaskInput({
title: "群晖授权",
helper: "群晖登录授权,请确保账户是管理员用户组",
@@ -30,15 +28,14 @@ export class SynologyKeepAlivePlugin extends AbstractPlusTaskPlugin {
})
accessId!: string;
//授权选择框
//授权选择框
@TaskInput({
title: "间隔天数",
helper: "多少天刷新一次,建议15天以内",
value: 15,
component: {
name: "a-input-number",
vModel:"value",
vModel: "value",
},
required: true,
})
@@ -46,14 +43,14 @@ export class SynologyKeepAlivePlugin extends AbstractPlusTaskPlugin {
@TaskOutput({
title: "上次刷新时间",
type :"SynologyLastRefreshTime"
type: "SynologyLastRefreshTime",
})
lastRefreshTime!: number;
async onInstance() {}
async execute(): Promise<any> {
this.logger.info("开始刷新群晖登录有效期");
const now = dayjs()
const now = dayjs();
const status = this.getLastStatus();
if (status) {
let lastRefreshTime = this.getLastOutput("lastRefreshTime");
@@ -61,16 +58,15 @@ export class SynologyKeepAlivePlugin extends AbstractPlusTaskPlugin {
this.lastRefreshTime = lastRefreshTime;
const lastTime = dayjs(lastRefreshTime);
const diffDays = now.diff(lastTime, "day");
this.logger.info(`上次刷新时间${lastTime.format("YYYY-MM-DD")}`);
if (diffDays < this.intervalDays) {
this.logger.info(`距离上次刷新${diffDays}天,不足${this.intervalDays}天,无需刷新`);
this.logger.info(`下一次刷新时间${lastTime.add(this.intervalDays, "day").format("YYYY-MM-DD")}`);
return "skip";
}else{
} else {
this.logger.info(`超过${this.intervalDays}天,需要刷新`);
}
}
const access: SynologyAccess = await this.getAccess<SynologyAccess>(this.accessId);
@@ -80,7 +76,5 @@ export class SynologyKeepAlivePlugin extends AbstractPlusTaskPlugin {
this.lastRefreshTime = now.valueOf();
this.logger.info("刷新群晖登录有效期成功");
}
}
new SynologyKeepAlivePlugin();
@@ -31,8 +31,7 @@ export class YidunRcdnAccess extends BaseAccess {
})
password = "";
@AccessInput({
@AccessInput({
title: "测试",
component: {
name: "api-test",
@@ -81,7 +80,7 @@ export class YidunRcdnAccess extends BaseAccess {
}
async getLoginToken() {
const access: YidunRcdnAccess = this
const access: YidunRcdnAccess = this;
const url = "https://rhcdn.yiduncdn.com/login/loginUser";
const data = {
userAccount: access.username,
@@ -48,31 +48,30 @@ export class YidunAccess extends BaseAccess {
return "ok";
}
async getDomainList(){
async getDomainList() {
const siteUrl = "http://user.yiduncdn.com/v1/sites";
const res = await this.doRequest(siteUrl, "GET", { });
return res.data
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;
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();
@@ -91,11 +91,10 @@ export class YidunDeployToCDNPlugin extends AbstractTaskPlugin {
});
}
private async updateByDomain(cert: CertInfo) {
//查询站点
const siteUrl = "http://user.yiduncdn.com/v1/sites";
const access = this.access
const access = this.access;
const res = await access.doRequest(siteUrl, "GET", { domain: this.domain });
if (res.data.length === 0) {
throw new Error(`未找到域名相关站点:${this.domain}`);
@@ -83,10 +83,6 @@ export class YidunDeployToRCDNPlugin extends AbstractTaskPlugin {
}
}
async onGetDomainList(data: any) {
if (!this.accessId) {
throw new Error("请选择Access授权");