mirror of https://github.com/certd/certd
chore: 优化access
parent
b09acfb4dc
commit
551311d3a0
|
@ -1,6 +1,8 @@
|
||||||
import { Registrable } from "../registry/index.js";
|
import { Registrable } from "../registry/index.js";
|
||||||
import { FormItemProps } from "../dt/index.js";
|
import { FormItemProps } from "../dt/index.js";
|
||||||
import { HttpClient, ILogger, utils } from "../utils";
|
import { HttpClient, ILogger, utils } from "../utils/index.js";
|
||||||
|
import _ from "lodash-es";
|
||||||
|
import { AccessRequestHandleReq } from "../core";
|
||||||
|
|
||||||
export type AccessInputDefine = FormItemProps & {
|
export type AccessInputDefine = FormItemProps & {
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -26,3 +28,26 @@ export type AccessContext = {
|
||||||
logger: ILogger;
|
logger: ILogger;
|
||||||
utils: typeof utils;
|
utils: typeof utils;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export abstract class BaseAccess implements IAccess {
|
||||||
|
ctx!: AccessContext;
|
||||||
|
|
||||||
|
async onRequest(req: AccessRequestHandleReq) {
|
||||||
|
if (!req.action) {
|
||||||
|
throw new Error("action is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
let methodName = req.action;
|
||||||
|
if (!req.action.startsWith("on")) {
|
||||||
|
methodName = `on${_.upperFirst(req.action)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
const method = this[methodName];
|
||||||
|
if (method) {
|
||||||
|
// @ts-ignore
|
||||||
|
return await this[methodName](req.data);
|
||||||
|
}
|
||||||
|
throw new Error(`action ${req.action} not found`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { AccessContext, AccessDefine, AccessInputDefine } from "./api.js";
|
||||||
import { Decorator } from "../decorator/index.js";
|
import { Decorator } from "../decorator/index.js";
|
||||||
import _ from "lodash-es";
|
import _ from "lodash-es";
|
||||||
import { accessRegistry } from "./registry.js";
|
import { accessRegistry } from "./registry.js";
|
||||||
import { http, logger, utils } from "../utils";
|
import { http, logger, utils } from "../utils/index.js";
|
||||||
|
|
||||||
// 提供一个唯一 key
|
// 提供一个唯一 key
|
||||||
export const ACCESS_CLASS_KEY = "pipeline:access";
|
export const ACCESS_CLASS_KEY = "pipeline:access";
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import _ from "lodash-es";
|
import { HttpClient, ILogger, utils } from "../utils/index.js";
|
||||||
import { HttpClient, ILogger, utils } from "../utils";
|
|
||||||
|
|
||||||
export type PluginRequestHandleReq<T = any> = {
|
export type PluginRequestHandleReq<T = any> = {
|
||||||
typeName: string;
|
typeName: string;
|
||||||
|
@ -20,24 +19,3 @@ export type AccessRequestHandleContext = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AccessRequestHandleReq<T = any> = PluginRequestHandleReq<AccessRequestHandleReqInput<T>>;
|
export type AccessRequestHandleReq<T = any> = PluginRequestHandleReq<AccessRequestHandleReqInput<T>>;
|
||||||
|
|
||||||
export class AccessRequestHandler<T = any> {
|
|
||||||
async onRequest(req: AccessRequestHandleReq<T>, ctx: AccessRequestHandleContext) {
|
|
||||||
if (!req.action) {
|
|
||||||
throw new Error("action is required");
|
|
||||||
}
|
|
||||||
|
|
||||||
let methodName = req.action;
|
|
||||||
if (!req.action.startsWith("on")) {
|
|
||||||
methodName = `on${_.upperFirst(req.action)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
const method = this[methodName];
|
|
||||||
if (method) {
|
|
||||||
// @ts-ignore
|
|
||||||
return await this[methodName](req.data, ctx);
|
|
||||||
}
|
|
||||||
throw new Error(`action ${req.action} not found`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { IAccessService } from "../access/index.js";
|
||||||
import { IEmailService } from "../service/index.js";
|
import { IEmailService } from "../service/index.js";
|
||||||
import { IContext, PluginRequestHandleReq, RunnableCollection } from "../core/index.js";
|
import { IContext, PluginRequestHandleReq, RunnableCollection } from "../core/index.js";
|
||||||
import { ILogger, logger, utils } from "../utils/index.js";
|
import { ILogger, logger, utils } from "../utils/index.js";
|
||||||
import { HttpClient } from "../utils/util.request";
|
import { HttpClient } from "../utils/util.request.js";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import _ from "lodash-es";
|
import _ from "lodash-es";
|
||||||
export type UserInfo = {
|
export type UserInfo = {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { IsAccess, AccessInput } from "@certd/pipeline";
|
import { IsAccess, AccessInput, BaseAccess } from "@certd/pipeline";
|
||||||
|
|
||||||
@IsAccess({
|
@IsAccess({
|
||||||
name: "eab",
|
name: "eab",
|
||||||
title: "EAB授权",
|
title: "EAB授权",
|
||||||
desc: "ZeroSSL证书申请需要EAB授权",
|
desc: "ZeroSSL证书申请需要EAB授权",
|
||||||
})
|
})
|
||||||
export class EabAccess {
|
export class EabAccess extends BaseAccess {
|
||||||
@AccessInput({
|
@AccessInput({
|
||||||
title: "KID",
|
title: "KID",
|
||||||
component: {
|
component: {
|
||||||
|
|
|
@ -64,7 +64,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
rowHandle: {
|
rowHandle: {
|
||||||
width: "130px"
|
width: 200
|
||||||
},
|
},
|
||||||
table: {
|
table: {
|
||||||
scroll: {
|
scroll: {
|
||||||
|
|
|
@ -42,6 +42,9 @@ export default function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOpti
|
||||||
span: 6
|
span: 6
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
rowHandle: {
|
||||||
|
width: 200
|
||||||
|
},
|
||||||
columns: {
|
columns: {
|
||||||
id: {
|
id: {
|
||||||
title: "ID",
|
title: "ID",
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { useRouter } from "vue-router";
|
||||||
import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery, UserPageRes, useUi } from "@fast-crud/fast-crud";
|
import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery, UserPageRes, useUi } from "@fast-crud/fast-crud";
|
||||||
import { statusUtil } from "/@/views/certd/pipeline/pipeline/utils/util.status";
|
import { statusUtil } from "/@/views/certd/pipeline/pipeline/utils/util.status";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { message, Modal } from "ant-design-vue";
|
import { message, Modal, notification } from "ant-design-vue";
|
||||||
import { env } from "/@/utils/util.env";
|
import { env } from "/@/utils/util.env";
|
||||||
import { useUserStore } from "/@/store/modules/user";
|
import { useUserStore } from "/@/store/modules/user";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
@ -181,23 +181,34 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
table: {
|
||||||
|
scroll: { x: 1500 }
|
||||||
|
},
|
||||||
rowHandle: {
|
rowHandle: {
|
||||||
minWidth: 200,
|
width: 300,
|
||||||
fixed: "right",
|
fixed: "right",
|
||||||
buttons: {
|
buttons: {
|
||||||
play: {
|
play: {
|
||||||
|
order: -999,
|
||||||
title: null,
|
title: null,
|
||||||
type: "link",
|
type: "link",
|
||||||
icon: "ant-design:play-outlined",
|
icon: "ant-design:play-circle-outlined",
|
||||||
|
click({ row }) {
|
||||||
|
Modal.confirm({
|
||||||
|
title: "确认",
|
||||||
|
content: `确定要触发运行吗?`,
|
||||||
|
async onOk() {
|
||||||
|
await api.Trigger(row.id);
|
||||||
|
notification.success({ message: "管道已经开始运行" });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
view: {
|
||||||
click({ row }) {
|
click({ row }) {
|
||||||
router.push({ path: "/certd/pipeline/detail", query: { id: row.id, editMode: "false" } });
|
router.push({ path: "/certd/pipeline/detail", query: { id: row.id, editMode: "false" } });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// view: {
|
|
||||||
// click({ row }) {
|
|
||||||
// router.push({ path: "/certd/pipeline/detail", query: { id: row.id, editMode: "false" } });
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
copy: {
|
copy: {
|
||||||
click: async (context) => {
|
click: async (context) => {
|
||||||
userStore.checkPlus();
|
userStore.checkPlus();
|
||||||
|
@ -303,7 +314,7 @@ export default function ({ crudExpose, context: { certdFormRef } }: CreateCrudOp
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
column: {
|
column: {
|
||||||
width: 300,
|
width: 350,
|
||||||
sorter: true,
|
sorter: true,
|
||||||
component: {
|
component: {
|
||||||
on: {
|
on: {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { IsAccess, AccessInput } from '@certd/pipeline';
|
import { IsAccess, AccessInput, BaseAccess } from '@certd/pipeline';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 这个注解将注册一个授权配置
|
* 这个注解将注册一个授权配置
|
||||||
|
@ -9,7 +9,7 @@ import { IsAccess, AccessInput } from '@certd/pipeline';
|
||||||
title: 'cloudflare授权',
|
title: 'cloudflare授权',
|
||||||
desc: '',
|
desc: '',
|
||||||
})
|
})
|
||||||
export class CloudflareAccess {
|
export class CloudflareAccess extends BaseAccess {
|
||||||
/**
|
/**
|
||||||
* 授权属性配置
|
* 授权属性配置
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { IsAccess, AccessInput, IAccess } from '@certd/pipeline';
|
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 这个注解将注册一个授权配置
|
* 这个注解将注册一个授权配置
|
||||||
|
@ -9,7 +9,7 @@ import { IsAccess, AccessInput, IAccess } from '@certd/pipeline';
|
||||||
title: '授权插件示例',
|
title: '授权插件示例',
|
||||||
desc: '',
|
desc: '',
|
||||||
})
|
})
|
||||||
export class DemoAccess implements IAccess {
|
export class DemoAccess extends BaseAccess {
|
||||||
/**
|
/**
|
||||||
* 授权属性配置
|
* 授权属性配置
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { IsAccess, AccessInput } from '@certd/pipeline';
|
import { IsAccess, AccessInput, BaseAccess } from '@certd/pipeline';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 这个注解将注册一个授权配置
|
* 这个注解将注册一个授权配置
|
||||||
|
@ -9,7 +9,7 @@ import { IsAccess, AccessInput } from '@certd/pipeline';
|
||||||
title: '多吉云',
|
title: '多吉云',
|
||||||
desc: '',
|
desc: '',
|
||||||
})
|
})
|
||||||
export class DogeCloudAccess {
|
export class DogeCloudAccess extends BaseAccess {
|
||||||
/**
|
/**
|
||||||
* 授权属性配置
|
* 授权属性配置
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { AccessInput, IsAccess } from '@certd/pipeline';
|
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 这个注解将注册一个授权配置
|
* 这个注解将注册一个授权配置
|
||||||
|
@ -9,7 +9,7 @@ import { AccessInput, IsAccess } from '@certd/pipeline';
|
||||||
title: 'dynadot授权',
|
title: 'dynadot授权',
|
||||||
desc: '************\n注意:申请证书时会覆盖已有的域名解析配置,慎用\n************\n待优化,主要是dynadot的接口一言难尽',
|
desc: '************\n注意:申请证书时会覆盖已有的域名解析配置,慎用\n************\n待优化,主要是dynadot的接口一言难尽',
|
||||||
})
|
})
|
||||||
export class DynadotAccess {
|
export class DynadotAccess extends BaseAccess {
|
||||||
/**
|
/**
|
||||||
* 授权属性配置
|
* 授权属性配置
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { AccessInput, IAccess, IsAccess } from '@certd/pipeline';
|
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
|
||||||
import { ConnectConfig } from 'ssh2';
|
import { ConnectConfig } from 'ssh2';
|
||||||
|
|
||||||
@IsAccess({
|
@IsAccess({
|
||||||
|
@ -7,7 +7,7 @@ import { ConnectConfig } from 'ssh2';
|
||||||
desc: '',
|
desc: '',
|
||||||
input: {},
|
input: {},
|
||||||
})
|
})
|
||||||
export class SshAccess implements IAccess, ConnectConfig {
|
export class SshAccess extends BaseAccess implements ConnectConfig {
|
||||||
@AccessInput({
|
@AccessInput({
|
||||||
title: '主机地址',
|
title: '主机地址',
|
||||||
component: {
|
component: {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { IsAccess, AccessInput } from '@certd/pipeline';
|
import { IsAccess, AccessInput, BaseAccess } from '@certd/pipeline';
|
||||||
|
|
||||||
@IsAccess({
|
@IsAccess({
|
||||||
name: 'huawei',
|
name: 'huawei',
|
||||||
title: '华为云授权',
|
title: '华为云授权',
|
||||||
desc: '',
|
desc: '',
|
||||||
})
|
})
|
||||||
export class HuaweiAccess {
|
export class HuaweiAccess extends BaseAccess {
|
||||||
@AccessInput({
|
@AccessInput({
|
||||||
title: 'accessKeyId',
|
title: 'accessKeyId',
|
||||||
component: {
|
component: {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { AccessInput, IsAccess } from '@certd/pipeline';
|
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 这个注解将注册一个授权配置
|
* 这个注解将注册一个授权配置
|
||||||
|
@ -9,7 +9,7 @@ import { AccessInput, IsAccess } from '@certd/pipeline';
|
||||||
title: '京东云授权',
|
title: '京东云授权',
|
||||||
desc: '暂时无法成功申请,还没测试通过',
|
desc: '暂时无法成功申请,还没测试通过',
|
||||||
})
|
})
|
||||||
export class JDCloudAccess {
|
export class JDCloudAccess extends BaseAccess {
|
||||||
/**
|
/**
|
||||||
* 授权属性配置
|
* 授权属性配置
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { IsAccess, AccessInput } from '@certd/pipeline';
|
import { IsAccess, AccessInput, BaseAccess } from '@certd/pipeline';
|
||||||
|
|
||||||
@IsAccess({
|
@IsAccess({
|
||||||
name: 'dnspod',
|
name: 'dnspod',
|
||||||
|
@ -6,7 +6,7 @@ import { IsAccess, AccessInput } from '@certd/pipeline';
|
||||||
desc: '腾讯云的域名解析接口已迁移到dnspod',
|
desc: '腾讯云的域名解析接口已迁移到dnspod',
|
||||||
deprecated: 'dnspod已废弃,请换成腾讯云',
|
deprecated: 'dnspod已废弃,请换成腾讯云',
|
||||||
})
|
})
|
||||||
export class DnspodAccess {
|
export class DnspodAccess extends BaseAccess {
|
||||||
@AccessInput({
|
@AccessInput({
|
||||||
title: '端点',
|
title: '端点',
|
||||||
component: {
|
component: {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { IsAccess, AccessInput } from '@certd/pipeline';
|
import { IsAccess, AccessInput, BaseAccess } from '@certd/pipeline';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 这个注解将注册一个授权配置
|
* 这个注解将注册一个授权配置
|
||||||
|
@ -9,7 +9,7 @@ import { IsAccess, AccessInput } from '@certd/pipeline';
|
||||||
title: '西部数码授权',
|
title: '西部数码授权',
|
||||||
desc: '',
|
desc: '',
|
||||||
})
|
})
|
||||||
export class WestAccess {
|
export class WestAccess extends BaseAccess {
|
||||||
/**
|
/**
|
||||||
* 授权属性配置
|
* 授权属性配置
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue