Files
certd/packages/ui/certd-server/src/plugins/plugin-dokploy/access.ts
T

110 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-08-29 00:38:45 +08:00
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
import { HttpRequestConfig } from "@certd/basic";
import { CertInfo } from "@certd/plugin-cert";
/**
*/
@IsAccess({
name: "dokploy",
title: "Dokploy授权",
desc: "",
2026-05-31 01:41:33 +08:00
icon: "svg:icon-lucky",
2025-08-29 00:38:45 +08:00
})
export class DokployAccess extends BaseAccess {
@AccessInput({
title: "Dokploy地址",
component: {
placeholder: "http://192.168.11.11:5480",
},
required: true,
})
2026-05-31 01:41:33 +08:00
endpoint = "";
2025-08-29 00:38:45 +08:00
@AccessInput({
2026-05-31 01:41:33 +08:00
title: "ApiKey",
2025-08-29 00:38:45 +08:00
component: {
2026-05-31 01:41:33 +08:00
placeholder: "ApiKey",
2025-08-29 00:38:45 +08:00
},
// naAyXbZmxtsfrDfneOCeirbQNIICmBgfBiYXQwryPIUOdzPkXkfnaKjeAdbOQdwp
//tlyvdNzojaFkNfGScALLmyuFHkHcYWaxoYjiDzWFHcnZAWdjOquMSqBwHLvGDGZK
helper: "[settings-profile](https://app.dokploy.com/dashboard/settings/profile)中配置API Keys",
required: true,
encrypt: true,
})
2026-05-31 01:41:33 +08:00
apiKey = "";
2025-08-29 00:38:45 +08:00
@AccessInput({
title: "测试",
component: {
name: "api-test",
2026-05-31 01:41:33 +08:00
action: "TestRequest",
2025-08-29 00:38:45 +08:00
},
2026-05-31 01:41:33 +08:00
helper: "点击测试接口是否正常",
2025-08-29 00:38:45 +08:00
})
testRequest = true;
async onTestRequest() {
await this.getCertList();
2026-05-31 01:41:33 +08:00
return "ok";
2025-08-29 00:38:45 +08:00
}
2026-05-31 01:41:33 +08:00
async getServerList() {
const req = {
2026-05-31 01:41:33 +08:00
url: "/api/server.all",
method: "get",
2026-05-31 01:41:33 +08:00
};
return await this.doRequest(req);
}
2026-05-31 01:41:33 +08:00
async getCertList() {
2025-08-29 00:38:45 +08:00
const req = {
2026-05-31 01:41:33 +08:00
url: "/api/certificates.all",
2025-08-29 00:38:45 +08:00
method: "get",
2026-05-31 01:41:33 +08:00
};
2025-08-29 00:38:45 +08:00
return await this.doRequest(req);
}
2026-05-31 01:41:33 +08:00
async createCert(opts: { cert: CertInfo; serverId: string; name: string }) {
2025-08-29 00:38:45 +08:00
const req = {
2026-05-31 01:41:33 +08:00
url: "/api/certificates.create",
2025-08-29 00:38:45 +08:00
method: "post",
2026-05-31 01:41:33 +08:00
data: {
2025-08-29 00:38:45 +08:00
// certificateId:opts.certificateId,
2026-05-31 01:41:33 +08:00
name: opts.name,
certificateData: opts.cert.crt,
privateKey: opts.cert.key,
serverId: opts.serverId,
2025-08-29 00:38:45 +08:00
autoRenew: false,
2026-05-31 01:41:33 +08:00
organizationId: "",
},
};
2025-08-29 00:38:45 +08:00
return await this.doRequest(req);
}
2026-05-31 01:41:33 +08:00
async removeCert(opts: { id: string }) {
2025-08-29 00:38:45 +08:00
const req = {
2026-05-31 01:41:33 +08:00
url: "/api/certificates.remove",
2025-08-29 00:38:45 +08:00
method: "post",
2026-05-31 01:41:33 +08:00
data: {
certificateId: opts.id,
},
};
2025-08-29 00:38:45 +08:00
return await this.doRequest(req);
}
2026-05-31 01:41:33 +08:00
async doRequest(req: HttpRequestConfig) {
2025-08-29 00:38:45 +08:00
const headers = {
"x-api-key": this.apiKey,
2026-05-31 01:41:33 +08:00
...req.headers,
2025-08-29 00:38:45 +08:00
};
return await this.ctx.http.request({
headers,
baseURL: this.endpoint,
...req,
logRes: false,
2025-08-29 00:38:45 +08:00
});
}
}
new DokployAccess();