mirror of https://github.com/certd/certd
commit
5649f708e3
|
@ -10,3 +10,4 @@ export * from './plugin-west/index.js';
|
||||||
export * from './plugin-doge/index.js';
|
export * from './plugin-doge/index.js';
|
||||||
export * from './plugin-qiniu/index.js';
|
export * from './plugin-qiniu/index.js';
|
||||||
export * from './plugin-jdcloud/index.js';
|
export * from './plugin-jdcloud/index.js';
|
||||||
|
export * from './plugin-woai/index.js';
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
|
||||||
|
|
||||||
|
@IsAccess({
|
||||||
|
name: 'woai',
|
||||||
|
title: '我爱云授权',
|
||||||
|
desc: '我爱云CDN',
|
||||||
|
})
|
||||||
|
export class WoaiAccess extends BaseAccess {
|
||||||
|
@AccessInput({
|
||||||
|
title: '账号',
|
||||||
|
component: {
|
||||||
|
placeholder: '我爱云的账号',
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
username = '';
|
||||||
|
@AccessInput({
|
||||||
|
title: '密码',
|
||||||
|
component: {
|
||||||
|
placeholder: '我爱云的密码',
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
encrypt: true,
|
||||||
|
})
|
||||||
|
password = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
new WoaiAccess();
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './plugins/index.js';
|
||||||
|
export * from './access.js';
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './plugin-deploy-to-cdn.js';
|
|
@ -0,0 +1,94 @@
|
||||||
|
import {AbstractTaskPlugin, HttpClient, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput} from '@certd/pipeline';
|
||||||
|
import {CertInfo} from '@certd/plugin-cert';
|
||||||
|
import {WoaiAccess} from '../access.js';
|
||||||
|
|
||||||
|
@IsTaskPlugin({
|
||||||
|
name: 'woaiCloud',
|
||||||
|
title: '部署证书到我爱云 CDN',
|
||||||
|
desc: '部署证书到我爱云CDN',
|
||||||
|
icon: 'clarity:plugin-line',
|
||||||
|
group: pluginGroups.other.key,
|
||||||
|
default: {
|
||||||
|
strategy: {
|
||||||
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
export class WoaiCdnPlugin extends AbstractTaskPlugin {
|
||||||
|
@TaskInput({
|
||||||
|
title: '证书ID',
|
||||||
|
helper: '请填写 <a href="https://console.edge.51vs.club/site/certificate" target="_blank">证书列表</a> 中的证书的ID',
|
||||||
|
component: {name: 'a-input'},
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
certId!: string;
|
||||||
|
@TaskInput({
|
||||||
|
title: '域名证书',
|
||||||
|
helper: '请选择前置任务输出的域名证书',
|
||||||
|
component: {
|
||||||
|
name: 'pi-output-selector',
|
||||||
|
from: ['CertApply', 'CertApplyLego'],
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
cert!: CertInfo;
|
||||||
|
@TaskInput({
|
||||||
|
title: 'Access授权',
|
||||||
|
helper: '我爱云的用户、密码授权',
|
||||||
|
component: {
|
||||||
|
name: 'pi-access-selector',
|
||||||
|
type: 'woai',
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
accessId!: string;
|
||||||
|
http!: HttpClient;
|
||||||
|
private readonly baseApi = 'https://console.edeg.51vs.club';
|
||||||
|
|
||||||
|
async onInstance() {
|
||||||
|
this.http = this.ctx.http;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async doRequestApi(url: string, data: any = null, method = 'post', token: string | null = null) {
|
||||||
|
const headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...(token ? {'Token': token} : {}),
|
||||||
|
};
|
||||||
|
const res = await this.http.request<any, any>({
|
||||||
|
url,
|
||||||
|
method,
|
||||||
|
data,
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
if (res.code !== 200) {
|
||||||
|
throw new Error(`${JSON.stringify(res.message)}`);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute(): Promise<void> {
|
||||||
|
const {certId, cert, accessId} = this;
|
||||||
|
const access = (await this.accessService.getById(accessId)) as WoaiAccess;
|
||||||
|
// 登录获取token
|
||||||
|
const loginResponse = await this.doRequestApi(`${this.baseApi}/account/login`, {
|
||||||
|
username: access.username,
|
||||||
|
password: access.password,
|
||||||
|
});
|
||||||
|
const token = loginResponse.data.token;
|
||||||
|
this.logger.info('登录成功,获取到Token:', token);
|
||||||
|
// 更新证书
|
||||||
|
const editCertResponse = await this.doRequestApi(
|
||||||
|
`${this.baseApi}/certificate/edit`,
|
||||||
|
{
|
||||||
|
id: certId,
|
||||||
|
cert: cert.crt,
|
||||||
|
key: cert.key,
|
||||||
|
},
|
||||||
|
'post',
|
||||||
|
token
|
||||||
|
);
|
||||||
|
this.logger.info('证书更新成功:', editCertResponse.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new WoaiCdnPlugin();
|
Loading…
Reference in New Issue