diff --git a/packages/core/basic/src/utils/util.request.ts b/packages/core/basic/src/utils/util.request.ts index aeb720e0b..df1db445c 100644 --- a/packages/core/basic/src/utils/util.request.ts +++ b/packages/core/basic/src/utils/util.request.ts @@ -98,10 +98,22 @@ export function createAxiosService({ logger }: { logger: Logger }) { config.timeout = 15000; } let agents = defaultAgents; - if (config.skipSslVerify) { - logger.info('跳过SSL验证'); - agents = createAgent({ rejectUnauthorized: false } as any); + if (config.skipSslVerify || config.httpProxy) { + let rejectUnauthorized = true; + if (config.skipSslVerify) { + logger.info('跳过SSL验证'); + rejectUnauthorized = false; + } + const proxy: any = {}; + if (config.httpProxy) { + logger.info('使用自定义http代理:', config.httpProxy); + proxy.httpProxy = config.httpProxy; + proxy.httpsProxy = config.httpProxy; + } + + agents = createAgent({ rejectUnauthorized, ...proxy } as any); } + delete config.skipSslVerify; config.httpsAgent = agents.httpsAgent; config.httpAgent = agents.httpAgent; @@ -200,6 +212,7 @@ export type HttpRequestConfig = { skipCheckRes?: boolean; logParams?: boolean; logRes?: boolean; + httpProxy?: string; } & AxiosRequestConfig; export type HttpClient = { request(config: HttpRequestConfig): Promise>; diff --git a/packages/core/pipeline/src/core/executor.ts b/packages/core/pipeline/src/core/executor.ts index 374db9351..79f066e20 100644 --- a/packages/core/pipeline/src/core/executor.ts +++ b/packages/core/pipeline/src/core/executor.ts @@ -388,6 +388,7 @@ export class Executor { if (!notification.when.includes(when)) { continue; } + if (notification.type === "email") { try { await this.options.emailService?.send({ @@ -401,7 +402,16 @@ export class Executor { } else { try { //构建notification插件,发送通知 - const notifyConfig = await this.options.notificationService.getById(notification.notificationId); + let notifyConfig: any; + if (notification.notificationId === 0) { + notifyConfig = await this.options.notificationService.getDefault(); + } else { + notifyConfig = await this.options.notificationService.getById(notification.notificationId); + } + if (notifyConfig == null) { + throw new Error(`通知配置不存在`); + } + const notificationPlugin = notificationRegistry.get(notifyConfig.type); const notificationCls: any = notificationPlugin.target; const notificationSender = new notificationCls(); diff --git a/packages/ui/certd-client/src/style/common.less b/packages/ui/certd-client/src/style/common.less index b6a5a012c..fc2ede2ee 100644 --- a/packages/ui/certd-client/src/style/common.less +++ b/packages/ui/certd-client/src/style/common.less @@ -77,6 +77,9 @@ h1, h2, h3, h4, h5, h6 { .flex-1 { flex: 1; } +.flex-0 { + flex: 0; +} .flex-col { display: flex; diff --git a/packages/ui/certd-client/src/views/certd/notification/api.ts b/packages/ui/certd-client/src/views/certd/notification/api.ts index 883031478..459b07e96 100644 --- a/packages/ui/certd-client/src/views/certd/notification/api.ts +++ b/packages/ui/certd-client/src/views/certd/notification/api.ts @@ -43,6 +43,13 @@ export function createApi() { }); }, + async GetOptions(id: number) { + return await request({ + url: apiPrefix + "/options", + method: "post" + }); + }, + async SetDefault(id: number) { return await request({ url: apiPrefix + "/setDefault", @@ -66,6 +73,13 @@ export function createApi() { }); }, + async GetDefineTypes() { + return await request({ + url: apiPrefix + "/getTypeDict", + method: "post" + }); + }, + async GetProviderDefine(type: string) { return await request({ url: apiPrefix + "/define", diff --git a/packages/ui/certd-client/src/views/certd/notification/crud.tsx b/packages/ui/certd-client/src/views/certd/notification/crud.tsx index 22c76c151..8e7b615bb 100644 --- a/packages/ui/certd-client/src/views/certd/notification/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/notification/crud.tsx @@ -1,12 +1,9 @@ -// @ts-ignore -import { useI18n } from "vue-i18n"; import { ref } from "vue"; import { getCommonColumnDefine } from "./common"; -import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, EditReq, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud"; - +import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, EditReq, UserPageQuery, UserPageRes } from "@fast-crud/fast-crud"; +import { createApi } from "/@/views/certd/notification/api"; +const api = createApi(); export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet { - const { t } = useI18n(); - const api = context.api; const pageRequest = async (query: UserPageQuery): Promise => { return await api.GetList(query); }; diff --git a/packages/ui/certd-client/src/views/certd/notification/notification-selector/index.vue b/packages/ui/certd-client/src/views/certd/notification/notification-selector/index.vue index 11faaf1d4..7d9d02e18 100644 --- a/packages/ui/certd-client/src/views/certd/notification/notification-selector/index.vue +++ b/packages/ui/certd-client/src/views/certd/notification/notification-selector/index.vue @@ -1,162 +1,156 @@ - diff --git a/packages/ui/certd-client/src/views/certd/pipeline/certd-form/crud.tsx b/packages/ui/certd-client/src/views/certd/pipeline/certd-form/crud.tsx index 170dade69..eef7c4f07 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/certd-form/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/pipeline/certd-form/crud.tsx @@ -107,6 +107,7 @@ export default function (certPluginGroup: PluginGroup, formWrapperRef: any): Cre title: "失败通知", type: "text", form: { + value: 0, component: { name: NotificationSelector, vModel: "modelValue", diff --git a/packages/ui/certd-server/src/controller/pipeline/notification-controller.ts b/packages/ui/certd-server/src/controller/pipeline/notification-controller.ts index cbaf99997..3ffe5ee4d 100644 --- a/packages/ui/certd-server/src/controller/pipeline/notification-controller.ts +++ b/packages/ui/certd-server/src/controller/pipeline/notification-controller.ts @@ -140,4 +140,17 @@ export class NotificationController extends CrudController const res = await this.service.setDefault(id, this.getUserId()); return this.ok(res); } + + @Post('/options', { summary: Constants.per.authOnly }) + async options() { + const res = await this.service.list({ + query: { + userId: this.getUserId(), + }, + }); + for (const item of res) { + delete item.setting; + } + return this.ok(res); + } } diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/discord/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/discord/index.ts index fcede4ee0..e681adc71 100644 --- a/packages/ui/certd-server/src/plugins/plugin-notification/discord/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-notification/discord/index.ts @@ -30,6 +30,27 @@ export class DiscordNotification extends BaseNotification { }) mentionedList!: string[]; + @NotificationInput({ + title: '代理', + component: { + placeholder: 'http://xxxxx:xx', + }, + helper: '使用https_proxy', + required: false, + }) + httpsProxy = ''; + + @NotificationInput({ + title: '忽略证书校验', + value: false, + component: { + name: 'a-switch', + vModel: 'checked', + }, + required: false, + }) + skipSslVerify: boolean; + async send(body: NotificationBody) { if (!this.webhook) { throw new Error('Webhook URL 不能为空'); @@ -49,6 +70,8 @@ export class DiscordNotification extends BaseNotification { url: this.webhook, method: 'POST', data: json, + httpProxy: this.httpsProxy, + skipSslVerify: this.skipSslVerify, }); } } diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/slack/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/slack/index.ts index 4d6a8e2a5..31a17a901 100644 --- a/packages/ui/certd-server/src/plugins/plugin-notification/slack/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-notification/slack/index.ts @@ -17,6 +17,27 @@ export class SlackNotification extends BaseNotification { }) webhook = ''; + @NotificationInput({ + title: '代理', + component: { + placeholder: 'http://xxxxx:xx', + }, + helper: '使用https_proxy', + required: false, + }) + httpsProxy = ''; + + @NotificationInput({ + title: '忽略证书校验', + value: false, + component: { + name: 'a-switch', + vModel: 'checked', + }, + required: false, + }) + skipSslVerify: boolean; + async send(body: NotificationBody) { if (!this.webhook) { throw new Error('token不能为空'); @@ -28,6 +49,8 @@ export class SlackNotification extends BaseNotification { data: { text: `${body.title}\n${body.content}\n[查看详情](${body.url})`, }, + httpProxy: this.httpsProxy, + skipSslVerify: this.skipSslVerify, }); } } diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/telegram/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/telegram/index.ts index a2b570e98..6c5f1af12 100644 --- a/packages/ui/certd-server/src/plugins/plugin-notification/telegram/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-notification/telegram/index.ts @@ -7,6 +7,16 @@ import { BaseNotification, IsNotification, NotificationBody, NotificationInput } needPlus: true, }) export class TelegramNotification extends BaseNotification { + @NotificationInput({ + title: 'URL', + value: 'https://api.telegram.org', + component: { + placeholder: 'https://api.telegram.org', + }, + required: true, + }) + endpoint = 'https://api.telegram.org'; + @NotificationInput({ title: 'Bot Token', component: { @@ -27,6 +37,27 @@ export class TelegramNotification extends BaseNotification { }) chatId = ''; + @NotificationInput({ + title: '代理', + component: { + placeholder: 'http://xxxxx:xx', + }, + helper: '使用https_proxy', + required: false, + }) + httpsProxy = ''; + + @NotificationInput({ + title: '忽略证书校验', + value: false, + component: { + name: 'a-switch', + vModel: 'checked', + }, + required: false, + }) + skipSslVerify: boolean; + async send(body: NotificationBody) { if (!this.botToken || !this.chatId) { throw new Error('Bot Token 和聊天ID不能为空'); @@ -47,6 +78,8 @@ export class TelegramNotification extends BaseNotification { text: messageContent, parse_mode: 'MarkdownV2', // 或使用 'HTML' 取决于需要的格式 }, + httpProxy: this.httpsProxy, + skipSslVerify: this.skipSslVerify, }); } }