mirror of https://github.com/certd/certd
perf: 支持更新金山云cdn证书
parent
4e432ed03f
commit
462e22a3b0
|
@ -83,7 +83,7 @@ export class KsyunAccess extends BaseAccess {
|
||||||
method:"POST",
|
method:"POST",
|
||||||
url:"/2016-09-01/cert/SetCertificate",
|
url:"/2016-09-01/cert/SetCertificate",
|
||||||
data:{
|
data:{
|
||||||
CertificateId: parseInt(opts.certId),
|
CertificateId: opts.certId,
|
||||||
CertificateName: opts.certName,
|
CertificateName: opts.certName,
|
||||||
ServerCertificate: opts.cert.crt,
|
ServerCertificate: opts.cert.crt,
|
||||||
PrivateKey: opts.cert.key
|
PrivateKey: opts.cert.key
|
||||||
|
@ -93,6 +93,24 @@ export class KsyunAccess extends BaseAccess {
|
||||||
return res
|
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() {
|
async getCdnClient() {
|
||||||
return new KsyunClient({
|
return new KsyunClient({
|
||||||
accessKeyId: this.accessKeyId,
|
accessKeyId: this.accessKeyId,
|
||||||
|
|
|
@ -38,6 +38,7 @@ export class KsyunClient {
|
||||||
try{
|
try{
|
||||||
return await this.http.request(config)
|
return await this.http.request(config)
|
||||||
}catch (e) {
|
}catch (e) {
|
||||||
|
this.logger.error(e.request)
|
||||||
if (e.response?.data?.Error?.Message){
|
if (e.response?.data?.Error?.Message){
|
||||||
throw new Error(e.response?.data?.Error?.Message)
|
throw new Error(e.response?.data?.Error?.Message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,18 +75,22 @@ export class KsyunRefreshCDNCert extends AbstractTaskPlugin {
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
const access = await this.getAccess<KsyunAccess>(this.accessId);
|
const access = await this.getAccess<KsyunAccess>(this.accessId);
|
||||||
|
|
||||||
const certReader = new CertReader(this.cert)
|
|
||||||
const certName = certReader.buildCertName()
|
|
||||||
const client = await access.getCdnClient();
|
const client = await access.getCdnClient();
|
||||||
for (const item of this.certList) {
|
for (const certId of this.certList) {
|
||||||
this.logger.info(`----------- 开始更新证书:${item}`);
|
this.logger.info(`----------- 开始更新证书:${certId}`);
|
||||||
|
|
||||||
|
const oldCert = await access.getCert({
|
||||||
|
client,
|
||||||
|
certId:certId
|
||||||
|
})
|
||||||
|
|
||||||
await access.updateCert({
|
await access.updateCert({
|
||||||
client,
|
client,
|
||||||
certId: item,
|
certId: certId,
|
||||||
certName,
|
certName: oldCert.CertificateName,
|
||||||
cert: this.cert
|
cert: this.cert
|
||||||
});
|
});
|
||||||
this.logger.info(`----------- 更新证书${item}成功`);
|
this.logger.info(`----------- 更新证书${certId}成功`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info("部署完成");
|
this.logger.info("部署完成");
|
||||||
|
|
Loading…
Reference in New Issue