mirror of https://github.com/certd/certd
chore:
parent
e08cf57b72
commit
86e521b9aa
|
@ -228,13 +228,10 @@ export abstract class AbstractTaskPlugin implements ITaskPlugin {
|
|||
}
|
||||
|
||||
buildCertName(domain: string) {
|
||||
if (domain.includes("*")) {
|
||||
domain = domain.replaceAll("*", "_");
|
||||
}
|
||||
domain = domain.replaceAll("*", "_").replaceAll(".", "_");
|
||||
return `${domain}_${dayjs().format("YYYYMMDDHHmmssSSS")}`;
|
||||
}
|
||||
|
||||
|
||||
async onRequest(req: PluginRequestHandleReq<any>) {
|
||||
if (!req.action) {
|
||||
throw new Error("action is required");
|
||||
|
|
|
@ -93,6 +93,11 @@ export class CertReader {
|
|||
return domains;
|
||||
}
|
||||
|
||||
getAltNames() {
|
||||
const { detail } = this.getCrtDetail();
|
||||
return detail.domains.altNames;
|
||||
}
|
||||
|
||||
static getMainDomain(crt: string) {
|
||||
const { detail } = CertReader.readCertDetail(crt);
|
||||
return detail.domains.commonName;
|
||||
|
@ -174,8 +179,14 @@ export class CertReader {
|
|||
buildCertFileName(suffix: string, applyTime: any, prefix = "cert") {
|
||||
const detail = this.getCrtDetail();
|
||||
let domain = detail.detail.domains.commonName;
|
||||
domain = domain.replace(".", "_").replace("*", "_");
|
||||
domain = domain.replaceAll(".", "_").replaceAll("*", "_");
|
||||
const timeStr = dayjs(applyTime).format("YYYYMMDDHHmmss");
|
||||
return `${prefix}_${domain}_${timeStr}.${suffix}`;
|
||||
}
|
||||
|
||||
buildCertName() {
|
||||
let domain = this.getMainDomain();
|
||||
domain = domain.replaceAll("*", "_").replaceAll("*", "_");
|
||||
return `${domain}_${dayjs().format("YYYYMMDDHHmmssSSS")}`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ export class AliyunSslClient {
|
|||
method: "POST",
|
||||
};
|
||||
|
||||
this.opts.logger.info("开始上传证书");
|
||||
this.opts.logger.info(`开始上传证书:${req.name}`);
|
||||
const ret: any = await client.request("UploadUserCertificate", params, requestOption);
|
||||
this.checkRet(ret);
|
||||
this.opts.logger.info("证书上传成功:aliyunCertId=", ret.CertId);
|
||||
|
|
|
@ -50,9 +50,22 @@ export class TencentSslClient {
|
|||
const ret = await client.UploadCertificate(params);
|
||||
this.checkRet(ret);
|
||||
this.logger.info("证书上传成功:tencentCertId=", ret.CertificateId);
|
||||
await this.switchCertNotify([ret.CertificateId], true);
|
||||
return ret.CertificateId;
|
||||
}
|
||||
|
||||
async switchCertNotify(certIds: string[], disabled: boolean) {
|
||||
const client = await this.getSslClient();
|
||||
const params = {
|
||||
CertificateIds: certIds,
|
||||
SwitchStatus: disabled ? 1 : 0, //1是忽略通知,0是不忽略
|
||||
};
|
||||
const ret = await client.ModifyCertificatesExpiringNotificationSwitch(params);
|
||||
this.checkRet(ret);
|
||||
this.logger.info(`关闭证书${certIds}过期通知成功`);
|
||||
return ret.RequestId;
|
||||
}
|
||||
|
||||
async deployCertificateInstance(params: any) {
|
||||
const client = await this.getSslClient();
|
||||
const res = await client.DeployCertificateInstance(params);
|
||||
|
|
|
@ -140,7 +140,7 @@ function createRequestFunction(service: any) {
|
|||
headers: {
|
||||
"Content-Type": get(config, "headers.Content-Type", "application/json"),
|
||||
},
|
||||
timeout: 20000,
|
||||
timeout: 30000,
|
||||
baseURL: env.API,
|
||||
data: {},
|
||||
};
|
||||
|
|
|
@ -70,9 +70,10 @@ export class FarcdnAccess extends BaseAccess {
|
|||
return "ok";
|
||||
}
|
||||
}catch (e) {
|
||||
if(e.message.indexOf("null")){
|
||||
if(e.message.indexOf("11111111")>-1){
|
||||
return "ok";
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
throw "测试失败,未知错误";
|
||||
|
@ -103,10 +104,12 @@ export class FarcdnAccess extends BaseAccess {
|
|||
const params = {
|
||||
sslCertId,
|
||||
};
|
||||
return await this.doRequest({
|
||||
const res= await this.doRequest({
|
||||
url: "/findSSLCertConfig",
|
||||
data: params
|
||||
});
|
||||
this.ctx.logger.info(`找到证书${sslCertId}: name=${res.name},domain=${res.commonNames},dnsNames=${res.dnsNames}`);
|
||||
return res
|
||||
}
|
||||
|
||||
async updateSSLCert(req:{
|
||||
|
@ -163,10 +166,10 @@ export class FarcdnAccess extends BaseAccess {
|
|||
data: params
|
||||
});
|
||||
|
||||
if (res.data.code === 200) {
|
||||
return res.data.data;
|
||||
if (res.code === "200") {
|
||||
return res.data;
|
||||
}
|
||||
throw new Error(res.data.message);
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ export class FarcdnRefreshCert extends AbstractPlusTaskPlugin {
|
|||
}
|
||||
|
||||
async onGetCertList() {
|
||||
throw new Error("暂无查询证书列表接口");
|
||||
throw new Error("暂无查询证书列表接口,您需要手动输入证书id");
|
||||
// const access = await this.getAccess<FarcdnAccess>(this.accessId);
|
||||
|
||||
// const res = await access.doRequest({
|
||||
|
|
Loading…
Reference in New Issue