perf: 支持更新金山云cdn证书

v2
xiaojunnuo 2025-08-15 10:27:06 +08:00
parent 4e432ed03f
commit 462e22a3b0
3 changed files with 31 additions and 8 deletions

View File

@ -83,7 +83,7 @@ export class KsyunAccess extends BaseAccess {
method:"POST",
url:"/2016-09-01/cert/SetCertificate",
data:{
CertificateId: parseInt(opts.certId),
CertificateId: opts.certId,
CertificateName: opts.certName,
ServerCertificate: opts.cert.crt,
PrivateKey: opts.cert.key
@ -93,6 +93,24 @@ export class KsyunAccess extends BaseAccess {
return res
}
async getCert(opts:{client:KsyunClient,certId:string}){
const res = await opts.client.doRequest({
action: "GetCertificates",
version: "2016-09-01",
method:"POST",
url:"/2016-09-01/cert/GetCertificates",
data:{
CertificateId: opts.certId,
}
})
this.ctx.logger.info(res)
const list = res.Certificates
if (list.length > 0) {
return list[0]
}
throw new Error(`未找到证书:${opts.certId}`)
}
async getCdnClient() {
return new KsyunClient({
accessKeyId: this.accessKeyId,

View File

@ -38,6 +38,7 @@ export class KsyunClient {
try{
return await this.http.request(config)
}catch (e) {
this.logger.error(e.request)
if (e.response?.data?.Error?.Message){
throw new Error(e.response?.data?.Error?.Message)
}

View File

@ -75,18 +75,22 @@ export class KsyunRefreshCDNCert extends AbstractTaskPlugin {
async execute(): Promise<void> {
const access = await this.getAccess<KsyunAccess>(this.accessId);
const certReader = new CertReader(this.cert)
const certName = certReader.buildCertName()
const client = await access.getCdnClient();
for (const item of this.certList) {
this.logger.info(`----------- 开始更新证书:${item}`);
for (const certId of this.certList) {
this.logger.info(`----------- 开始更新证书:${certId}`);
const oldCert = await access.getCert({
client,
certId:certId
})
await access.updateCert({
client,
certId: item,
certName,
certId: certId,
certName: oldCert.CertificateName,
cert: this.cert
});
this.logger.info(`----------- 更新证书${item}成功`);
this.logger.info(`----------- 更新证书${certId}成功`);
}
this.logger.info("部署完成");