mirror of https://github.com/certd/certd
perf: 支持上传到七牛云oss
parent
7532a96085
commit
bf024bdda8
|
@ -1,24 +0,0 @@
|
|||
import { AccessInput, IAccess, IsAccess } from '@certd/pipeline';
|
||||
|
||||
@IsAccess({
|
||||
name: 'qiniu',
|
||||
title: '七牛云授权',
|
||||
desc: '',
|
||||
input: {},
|
||||
})
|
||||
export class QiniuAccess implements IAccess {
|
||||
@AccessInput({
|
||||
title: 'AccessKey',
|
||||
rules: [{ required: true, message: '此项必填' }],
|
||||
helper: 'AK,前往[密钥管理](https://portal.qiniu.com/developer/user/key)获取',
|
||||
})
|
||||
accessKey!: string;
|
||||
@AccessInput({
|
||||
title: 'SecretKey',
|
||||
encrypt: true,
|
||||
helper: 'SK',
|
||||
})
|
||||
secretKey!: string;
|
||||
}
|
||||
|
||||
new QiniuAccess();
|
|
@ -1 +0,0 @@
|
|||
export * from './access.js';
|
|
@ -1,2 +1 @@
|
|||
export * from './plugin/index.js';
|
||||
export * from './access/index.js';
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
|
||||
import { QiniuAccess } from '../../access/index.js';
|
||||
import { QiniuAccess, QiniuClient } from '@certd/plugin-plus';
|
||||
import { CertInfo } from '@certd/plugin-cert';
|
||||
import { doRequest, uploadCert } from '../lib/sdk.js';
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: 'QiniuDeployCertToCDN',
|
||||
|
@ -49,24 +48,27 @@ export class QiniuDeployCertToCDN extends AbstractTaskPlugin {
|
|||
async execute(): Promise<void> {
|
||||
this.logger.info('开始部署证书到七牛云cdn');
|
||||
const access = await this.accessService.getById<QiniuAccess>(this.accessId);
|
||||
|
||||
const qiniuClient = new QiniuClient({
|
||||
http: this.ctx.http,
|
||||
access,
|
||||
});
|
||||
const url = `https://api.qiniu.com/domain/${this.domainName}/httpsconf`;
|
||||
let certId = null;
|
||||
if (typeof this.cert !== 'string') {
|
||||
// 是证书id,直接上传即可
|
||||
this.logger.info('先上传证书');
|
||||
certId = await uploadCert(this.ctx.http, access, this.cert, this.appendTimeSuffix('certd'));
|
||||
certId = await qiniuClient.uploadCert(this.cert, this.appendTimeSuffix('certd'));
|
||||
} else {
|
||||
certId = this.cert;
|
||||
}
|
||||
|
||||
//开始修改证书
|
||||
this.logger.info('开始修改证书');
|
||||
this.logger.info(`开始修改证书,certId:${certId},domain:${this.domainName}`);
|
||||
const body = {
|
||||
certID: certId,
|
||||
};
|
||||
|
||||
await doRequest(this.ctx.http, access, url, 'put', body);
|
||||
await qiniuClient.doRequest(url, 'put', body);
|
||||
|
||||
this.logger.info('部署完成');
|
||||
}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
import { HttpClient } from '@certd/pipeline';
|
||||
import { QiniuAccess } from '../../access/index.js';
|
||||
import { CertInfo } from '@certd/plugin-cert';
|
||||
|
||||
export async function doRequest(http: HttpClient, access: QiniuAccess, url: string, method: string, body: any) {
|
||||
const { generateAccessToken } = await import('qiniu/qiniu/util.js');
|
||||
const token = generateAccessToken(access, url);
|
||||
const res = await http.request({
|
||||
url,
|
||||
method: method,
|
||||
headers: {
|
||||
Authorization: token,
|
||||
},
|
||||
data: body,
|
||||
});
|
||||
|
||||
if (res.code !== 200 || res.error) {
|
||||
throw new Error('请求失败:' + res.error);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function uploadCert(http: HttpClient, access: QiniuAccess, cert: CertInfo, certName?: string) {
|
||||
const url = 'https://api.qiniu.com/sslcert';
|
||||
|
||||
const body = {
|
||||
name: certName,
|
||||
common_name: 'certd',
|
||||
pri: cert.key,
|
||||
ca: cert.crt,
|
||||
};
|
||||
|
||||
const res = await doRequest(http, access, url, 'post', body);
|
||||
|
||||
return res.certID;
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from '@certd/pipeline';
|
||||
import { QiniuAccess } from '../../access/index.js';
|
||||
import { QiniuAccess, QiniuClient } from '@certd/plugin-plus';
|
||||
import { CertInfo } from '@certd/plugin-cert';
|
||||
import { uploadCert } from '../lib/sdk.js';
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: 'QiniuCertUpload',
|
||||
|
@ -53,7 +52,11 @@ export class QiniuCertUpload extends AbstractTaskPlugin {
|
|||
async execute(): Promise<void> {
|
||||
this.logger.info('开始上传证书到七牛云');
|
||||
const access = (await this.accessService.getById(this.accessId)) as QiniuAccess;
|
||||
this.qiniuCertId = await uploadCert(this.ctx.http, access, this.cert, this.appendTimeSuffix(this.certName));
|
||||
const qiniuClient = new QiniuClient({
|
||||
http: this.ctx.http,
|
||||
access,
|
||||
});
|
||||
this.qiniuCertId = await qiniuClient.uploadCert(this.cert, this.appendTimeSuffix(this.certName));
|
||||
this.logger.info('上传完成,id:', this.qiniuCertId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue