mirror of
https://github.com/certd/certd.git
synced 2026-04-24 20:57:26 +08:00
chore: 1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import {AccessInput, BaseAccess, IsAccess} from "@certd/pipeline";
|
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
||||||
import {HttpRequestConfig} from "@certd/basic";
|
import { HttpRequestConfig } from "@certd/basic";
|
||||||
import { CertInfo, CertReader } from "@certd/plugin-cert";
|
import { CertInfo, CertReader } from "@certd/plugin-cert";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ export class GoEdgeAccess extends BaseAccess {
|
|||||||
name: "a-input",
|
name: "a-input",
|
||||||
vModel: "value"
|
vModel: "value"
|
||||||
},
|
},
|
||||||
helper:"例如:http://yourdomain.com:8002, 需要在API节点配置中开启HTTP访问地址",
|
helper: "例如:http://yourdomain.com:8002, 需要在API节点配置中开启HTTP访问地址",
|
||||||
encrypt: false,
|
encrypt: false,
|
||||||
required: true
|
required: true
|
||||||
})
|
})
|
||||||
@@ -49,7 +49,7 @@ export class GoEdgeAccess extends BaseAccess {
|
|||||||
|
|
||||||
@AccessInput({
|
@AccessInput({
|
||||||
title: "accessKeyId",
|
title: "accessKeyId",
|
||||||
helper:`用户AccessKey: 在”平台用户-用户-详情-AccessKey” 或 商业版的“访问控制” 中创建。
|
helper: `用户AccessKey: 在”平台用户-用户-详情-AccessKey” 或 商业版的“访问控制” 中创建。
|
||||||
管理员AccessKey:在”系统用户-用户-详情-AccessKey” 中创建。`,
|
管理员AccessKey:在”系统用户-用户-详情-AccessKey” 中创建。`,
|
||||||
component: {
|
component: {
|
||||||
name: "a-input",
|
name: "a-input",
|
||||||
@@ -83,10 +83,10 @@ export class GoEdgeAccess extends BaseAccess {
|
|||||||
})
|
})
|
||||||
testRequest = true;
|
testRequest = true;
|
||||||
|
|
||||||
accessToken: {expiresAt:number,token:string}
|
accessToken: { expiresAt: number, token: string }
|
||||||
|
|
||||||
async onTestRequest() {
|
async onTestRequest() {
|
||||||
await this.getCertList({pageSize:1});
|
await this.getCertList({ pageSize: 1 });
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,32 +115,32 @@ export class GoEdgeAccess extends BaseAccess {
|
|||||||
"ocspError": ""
|
"ocspError": ""
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async getCertList(req:{pageNo?:number,pageSize?:number,query?:string,onlyUser?:boolean,userId?:number}){
|
async getCertList(req: { pageNo?: number, pageSize?: number, query?: string, onlyUser?: boolean, userId?: number }) {
|
||||||
const pageNo = req.pageNo ?? 1;
|
const pageNo = req.pageNo ?? 1;
|
||||||
const pageSize = req.pageSize ?? 20;
|
const pageSize = req.pageSize ?? 20;
|
||||||
const body:any = {
|
const body: any = {
|
||||||
keyword: req.query??"",
|
keyword: req.query ?? "",
|
||||||
offset: (pageNo-1)*pageSize,
|
offset: (pageNo - 1) * pageSize,
|
||||||
size: pageSize,
|
size: pageSize,
|
||||||
}
|
}
|
||||||
if (req.onlyUser){
|
if (req.onlyUser) {
|
||||||
body["onlyUser"] = true;
|
body["onlyUser"] = true;
|
||||||
}
|
}
|
||||||
if (req.userId){
|
if (req.userId) {
|
||||||
body["userId"] = req.userId;
|
body["userId"] = req.userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const countRes = await this.doRequest({
|
const countRes = await this.doRequest({
|
||||||
url: `/SSLCertService/countSSLCerts`,
|
url: `/SSLCertService/countSSLCerts`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data:body
|
data: body
|
||||||
});
|
});
|
||||||
const total = countRes.count || 9999;
|
const total = countRes.count || 9999;
|
||||||
|
|
||||||
const res = await this.doRequest({
|
const res = await this.doRequest({
|
||||||
url: `/SSLCertService/listSSLCerts`,
|
url: `/SSLCertService/listSSLCerts`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data:body
|
data: body
|
||||||
});
|
});
|
||||||
// this.ctx.logger.info("getCertList",JSON.stringify(res));
|
// this.ctx.logger.info("getCertList",JSON.stringify(res));
|
||||||
const sslCertsJSON = this.ctx.utils.hash.base64Decode(res.sslCertsJSON) || "[]";
|
const sslCertsJSON = this.ctx.utils.hash.base64Decode(res.sslCertsJSON) || "[]";
|
||||||
@@ -153,8 +153,10 @@ export class GoEdgeAccess extends BaseAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async doCertReplace(req:{certId:number,cert:CertInfo}){
|
async doCertReplace(req: { certId: number, cert: CertInfo }) {
|
||||||
|
|
||||||
|
let sslCert:any = {}
|
||||||
|
try {
|
||||||
const res = await this.doRequest({
|
const res = await this.doRequest({
|
||||||
url: `/SSLCertService/findEnabledSSLCertConfig`,
|
url: `/SSLCertService/findEnabledSSLCertConfig`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -163,7 +165,10 @@ export class GoEdgeAccess extends BaseAccess {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const sslCertJSON = this.ctx.utils.hash.base64Decode(res.sslCertJSON) || "{}";
|
const sslCertJSON = this.ctx.utils.hash.base64Decode(res.sslCertJSON) || "{}";
|
||||||
const sslCert = JSON.parse(sslCertJSON) ;
|
sslCert = JSON.parse(sslCertJSON);
|
||||||
|
} catch (error) {
|
||||||
|
this.ctx.logger.error("获取原来的证书详情失败", error);
|
||||||
|
}
|
||||||
|
|
||||||
const certReader = new CertReader(req.cert);
|
const certReader = new CertReader(req.cert);
|
||||||
const dnsNames = certReader.getAllDomains()
|
const dnsNames = certReader.getAllDomains()
|
||||||
@@ -176,12 +181,12 @@ export class GoEdgeAccess extends BaseAccess {
|
|||||||
sslCertId: req.certId,
|
sslCertId: req.certId,
|
||||||
certData: this.ctx.utils.hash.base64(req.cert.crt),
|
certData: this.ctx.utils.hash.base64(req.cert.crt),
|
||||||
keyData: this.ctx.utils.hash.base64(req.cert.key),
|
keyData: this.ctx.utils.hash.base64(req.cert.key),
|
||||||
isOn: sslCert.isOn,
|
isOn: sslCert.isOn ?? true,
|
||||||
name: sslCert.name || certReader.buildCertName(),
|
name: sslCert.name || certReader.buildCertName(),
|
||||||
description: sslCert.description || "upload by certd",
|
description: sslCert.description || "upload by certd",
|
||||||
serverName: sslCert.serverName,
|
serverName: sslCert.serverName,
|
||||||
timeBeginAt: certReader.detail.notBefore.getTime()/1000,
|
timeBeginAt: certReader.detail.notBefore.getTime() / 1000,
|
||||||
timeEndAt: certReader.detail.notAfter.getTime()/1000,
|
timeEndAt: certReader.detail.notAfter.getTime() / 1000,
|
||||||
dnsNames: dnsNames,
|
dnsNames: dnsNames,
|
||||||
/**
|
/**
|
||||||
* // 是否启用
|
* // 是否启用
|
||||||
@@ -207,9 +212,9 @@ export class GoEdgeAccess extends BaseAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async getToken(){
|
async getToken() {
|
||||||
// /APIAccessTokenService/getAPIAccessToken
|
// /APIAccessTokenService/getAPIAccessToken
|
||||||
if (this.accessToken && this.accessToken.expiresAt >dayjs().unix()){
|
if (this.accessToken && this.accessToken.expiresAt > dayjs().unix()) {
|
||||||
return this.accessToken;
|
return this.accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,26 +231,26 @@ export class GoEdgeAccess extends BaseAccess {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
async doRequest(req:HttpRequestConfig){
|
async doRequest(req: HttpRequestConfig) {
|
||||||
|
|
||||||
const headers: Record<string,string> = {}
|
const headers: Record<string, string> = {}
|
||||||
if(!req.url.endsWith("/getAPIAccessToken")){
|
if (!req.url.endsWith("/getAPIAccessToken")) {
|
||||||
if (!this.accessToken || this.accessToken.expiresAt < dayjs().unix()){
|
if (!this.accessToken || this.accessToken.expiresAt < dayjs().unix()) {
|
||||||
await this.getToken();
|
await this.getToken();
|
||||||
}
|
}
|
||||||
headers["X-Edge-Access-Token"] = this.accessToken.token;
|
headers["X-Edge-Access-Token"] = this.accessToken.token;
|
||||||
}
|
}
|
||||||
let endpoint = this.endpoint;
|
let endpoint = this.endpoint;
|
||||||
if (endpoint.endsWith("/")){
|
if (endpoint.endsWith("/")) {
|
||||||
endpoint = endpoint.slice(0,-1);
|
endpoint = endpoint.slice(0, -1);
|
||||||
}
|
}
|
||||||
const res = await this.ctx.http.request({
|
const res = await this.ctx.http.request({
|
||||||
url: req.url,
|
url: req.url,
|
||||||
baseURL: endpoint,
|
baseURL: endpoint,
|
||||||
method: req.method|| "POST",
|
method: req.method || "POST",
|
||||||
data: req.data,
|
data: req.data,
|
||||||
params: req.params,
|
params: req.params,
|
||||||
headers:{
|
headers: {
|
||||||
...headers,
|
...headers,
|
||||||
...req.headers
|
...req.headers
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user