mirror of
https://github.com/certd/certd.git
synced 2026-07-08 21:57:36 +08:00
chore: format
This commit is contained in:
@@ -1,49 +1,45 @@
|
||||
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
|
||||
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
||||
|
||||
@IsAccess({
|
||||
name: 'CacheFly',
|
||||
title: 'CacheFly',
|
||||
desc: 'CacheFly',
|
||||
icon: 'clarity:plugin-line',
|
||||
name: "CacheFly",
|
||||
title: "CacheFly",
|
||||
desc: "CacheFly",
|
||||
icon: "clarity:plugin-line",
|
||||
})
|
||||
export class CacheflyAccess extends BaseAccess {
|
||||
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: 'username',
|
||||
title: "username",
|
||||
component: {
|
||||
placeholder: 'username',
|
||||
placeholder: "username",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
username = '';
|
||||
username = "";
|
||||
@AccessInput({
|
||||
title: 'password',
|
||||
title: "password",
|
||||
component: {
|
||||
placeholder: 'password',
|
||||
placeholder: "password",
|
||||
},
|
||||
required: true,
|
||||
encrypt: true,
|
||||
})
|
||||
password = '';
|
||||
password = "";
|
||||
@AccessInput({
|
||||
title: 'totp key',
|
||||
title: "totp key",
|
||||
component: {
|
||||
placeholder: 'totp key',
|
||||
placeholder: "totp key",
|
||||
},
|
||||
encrypt: true,
|
||||
})
|
||||
otpkey = '';
|
||||
|
||||
otpkey = "";
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "TestRequest"
|
||||
action: "TestRequest",
|
||||
},
|
||||
helper: "测试授权是否正确"
|
||||
helper: "测试授权是否正确",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
@@ -52,16 +48,15 @@ export class CacheflyAccess extends BaseAccess {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
||||
async login(){
|
||||
async login() {
|
||||
let otp = null;
|
||||
if (this.otpkey) {
|
||||
const response = await this.ctx.http.request<any, any>({
|
||||
url: `https://cn-api.my-api.cn/api/totp/?key=${this.otpkey}`,
|
||||
method: 'get',
|
||||
method: "get",
|
||||
});
|
||||
otp = response;
|
||||
this.ctx.logger.info('获取到otp:', otp);
|
||||
this.ctx.logger.info("获取到otp:", otp);
|
||||
}
|
||||
const loginResponse = await this.doRequestApi(`/api/2.6/auth/login`, {
|
||||
username: this.username,
|
||||
@@ -69,17 +64,16 @@ export class CacheflyAccess extends BaseAccess {
|
||||
...(otp && { otp }),
|
||||
});
|
||||
const token = loginResponse.token;
|
||||
this.ctx.logger.info('Token 获取成功');
|
||||
this.ctx.logger.info("Token 获取成功");
|
||||
return token;
|
||||
}
|
||||
|
||||
async doRequestApi(url: string, data: any = null, method = 'post', token: string | null = null) {
|
||||
|
||||
const baseApi = 'https://api.cachefly.com';
|
||||
async doRequestApi(url: string, data: any = null, method = "post", token: string | null = null) {
|
||||
const baseApi = "https://api.cachefly.com";
|
||||
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
...(token ? { 'x-cf-authorization': `Bearer ${token}` } : {}),
|
||||
"Content-Type": "application/json",
|
||||
...(token ? { "x-cf-authorization": `Bearer ${token}` } : {}),
|
||||
};
|
||||
const res = await this.ctx.http.request<any, any>({
|
||||
url,
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './plugins/index.js';
|
||||
export * from './access.js';
|
||||
export * from "./plugins/index.js";
|
||||
export * from "./access.js";
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './plugin-deploy-to-cdn.js';
|
||||
export * from "./plugin-deploy-to-cdn.js";
|
||||
|
||||
+18
-22
@@ -1,12 +1,12 @@
|
||||
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
|
||||
import { CertInfo } from '@certd/plugin-cert';
|
||||
import { CacheflyAccess } from '../access.js';
|
||||
import { CertApplyPluginNames} from '@certd/plugin-cert';
|
||||
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
|
||||
import { CertInfo } from "@certd/plugin-cert";
|
||||
import { CacheflyAccess } from "../access.js";
|
||||
import { CertApplyPluginNames } from "@certd/plugin-cert";
|
||||
@IsTaskPlugin({
|
||||
name: 'CacheFly',
|
||||
title: 'CacheFly-部署证书到CacheFly',
|
||||
desc: '部署证书到 CacheFly',
|
||||
icon: 'clarity:plugin-line',
|
||||
name: "CacheFly",
|
||||
title: "CacheFly-部署证书到CacheFly",
|
||||
desc: "部署证书到 CacheFly",
|
||||
icon: "clarity:plugin-line",
|
||||
group: pluginGroups.cdn.key,
|
||||
default: {
|
||||
strategy: {
|
||||
@@ -16,36 +16,32 @@ import { CertApplyPluginNames} from '@certd/plugin-cert';
|
||||
})
|
||||
export class CacheFlyPlugin extends AbstractTaskPlugin {
|
||||
@TaskInput({
|
||||
title: '域名证书',
|
||||
helper: '请选择前置任务输出的域名证书',
|
||||
title: "域名证书",
|
||||
helper: "请选择前置任务输出的域名证书",
|
||||
component: {
|
||||
name: 'output-selector',
|
||||
name: "output-selector",
|
||||
from: [...CertApplyPluginNames],
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
cert!: CertInfo;
|
||||
@TaskInput({
|
||||
title: 'Access授权',
|
||||
helper: 'CacheFly 的授权',
|
||||
title: "Access授权",
|
||||
helper: "CacheFly 的授权",
|
||||
component: {
|
||||
name: 'access-selector',
|
||||
type: 'CacheFly',
|
||||
name: "access-selector",
|
||||
type: "CacheFly",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
accessId!: string;
|
||||
|
||||
|
||||
async onInstance() {}
|
||||
|
||||
|
||||
|
||||
|
||||
async execute(): Promise<void> {
|
||||
const { cert, accessId } = this;
|
||||
const access = (await this.getAccess(accessId)) as CacheflyAccess;
|
||||
|
||||
|
||||
const token = await access.login();
|
||||
// 更新证书
|
||||
await access.doRequestApi(
|
||||
@@ -54,10 +50,10 @@ export class CacheFlyPlugin extends AbstractTaskPlugin {
|
||||
certificate: cert.crt,
|
||||
certificateKey: cert.key,
|
||||
},
|
||||
'post',
|
||||
"post",
|
||||
token
|
||||
);
|
||||
this.logger.info('证书更新成功');
|
||||
this.logger.info("证书更新成功");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user