diff --git a/packages/core/basic/src/utils/util.request.ts b/packages/core/basic/src/utils/util.request.ts index dd1cbe497..aeb720e0b 100644 --- a/packages/core/basic/src/utils/util.request.ts +++ b/packages/core/basic/src/utils/util.request.ts @@ -236,8 +236,8 @@ export function createAgent(opts: CreateAgentOptions = {}) { } const httpsProxy = opts.httpsProxy; if (httpsProxy) { - process.env.HTTPS_PROXY = httpProxy; - process.env.https_proxy = httpProxy; + process.env.HTTPS_PROXY = httpsProxy; + process.env.https_proxy = httpsProxy; logger.info('use httpsProxy:', httpsProxy); httpsAgent = new HttpsProxyAgent(httpsProxy, opts as any); merge(httpsAgent.options, opts); diff --git a/packages/core/pipeline/src/core/executor.ts b/packages/core/pipeline/src/core/executor.ts index 89eb6e254..8114c4095 100644 --- a/packages/core/pipeline/src/core/executor.ts +++ b/packages/core/pipeline/src/core/executor.ts @@ -303,6 +303,7 @@ export class Executor { }; const taskCtx: TaskInstanceContext = { pipeline: this.pipeline, + runtime: this.runtime, step, lastStatus, http, @@ -313,6 +314,8 @@ export class Executor { emailService: this.options.emailService, cnameProxyService: this.options.cnameProxyService, pluginConfigService: this.options.pluginConfigService, + notificationService: this.options.notificationService, + urlService: this.options.urlService, pipelineContext: this.pipelineContext, userContext: this.contextFactory.getContext("user", this.options.user.id), fileStore: new FileStore({ diff --git a/packages/core/pipeline/src/notification/api.ts b/packages/core/pipeline/src/notification/api.ts index 10ffbb33a..288fadb77 100644 --- a/packages/core/pipeline/src/notification/api.ts +++ b/packages/core/pipeline/src/notification/api.ts @@ -6,13 +6,13 @@ import * as _ from "lodash-es"; import { IEmailService } from "../service/index.js"; export type NotificationBody = { - userId: number; + userId?: number; title: string; content: string; - pipeline: Pipeline; - pipelineId: number; + pipeline?: Pipeline; + pipelineId?: number; result?: HistoryResult; - historyId: number; + historyId?: number; errorMessage?: string; url?: string; }; @@ -39,6 +39,7 @@ export type NotificationDefine = Registrable & { export type NotificationInstanceConfig = { id: number; type: string; + name: string; userId: number; setting: { [key: string]: any; @@ -47,6 +48,7 @@ export type NotificationInstanceConfig = { export interface INotificationService { getById(id: number): Promise; + getDefault(): Promise; } export interface INotification { @@ -97,7 +99,7 @@ export abstract class BaseNotification implements INotification { async onTestRequest() { await this.send({ userId: 0, - title: "【Certd】测试通知", + title: "【Certd】测试通知,标题长度测试、测试、测试", content: "测试通知", pipeline: { id: 1, diff --git a/packages/core/pipeline/src/notification/decorator.ts b/packages/core/pipeline/src/notification/decorator.ts index 66b17b4df..bd3bbf2d2 100644 --- a/packages/core/pipeline/src/notification/decorator.ts +++ b/packages/core/pipeline/src/notification/decorator.ts @@ -2,7 +2,7 @@ import { Decorator } from "../decorator/index.js"; import * as _ from "lodash-es"; import { notificationRegistry } from "./registry.js"; -import { NotificationContext, NotificationDefine, NotificationInputDefine } from "./api.js"; +import { NotificationBody, NotificationContext, NotificationDefine, NotificationInputDefine, NotificationInstanceConfig } from "./api.js"; // 提供一个唯一 key export const NOTIFICATION_CLASS_KEY = "pipeline:notification"; @@ -38,7 +38,7 @@ export function NotificationInput(input?: NotificationInputDefine): PropertyDeco }; } -export function newNotification(type: string, input: any, ctx: NotificationContext) { +export async function newNotification(type: string, input: any, ctx: NotificationContext) { const register = notificationRegistry.get(type); if (register == null) { throw new Error(`notification ${type} not found`); @@ -52,5 +52,11 @@ export function newNotification(type: string, input: any, ctx: NotificationConte throw new Error("ctx is required"); } plugin.setCtx(ctx); + await plugin.onInstance(); return plugin; } + +export async function sendNotification(opts: { config: NotificationInstanceConfig; ctx: NotificationContext; body: NotificationBody }) { + const notification = await newNotification(opts.config.type, opts.config.setting, opts.ctx); + await notification.send(opts.body); +} diff --git a/packages/core/pipeline/src/plugin/api.ts b/packages/core/pipeline/src/plugin/api.ts index da4379b0d..742eb71c9 100644 --- a/packages/core/pipeline/src/plugin/api.ts +++ b/packages/core/pipeline/src/plugin/api.ts @@ -2,13 +2,14 @@ import { Registrable } from "../registry/index.js"; import { FileItem, FormItemProps, Pipeline, Runnable, Step } from "../dt/index.js"; import { FileStore } from "../core/file-store.js"; import { IAccessService } from "../access/index.js"; -import { ICnameProxyService, IEmailService } from "../service/index.js"; -import { CancelError, IContext, RunnableCollection } from "../core/index.js"; +import { ICnameProxyService, IEmailService, IUrlService } from "../service/index.js"; +import { CancelError, IContext, RunHistory, RunnableCollection } from "../core/index.js"; import { HttpRequestConfig, ILogger, logger, utils } from "@certd/basic"; import { HttpClient } from "@certd/basic"; import dayjs from "dayjs"; import { IPluginConfigService } from "../service/config"; import { upperFirst } from "lodash-es"; +import { INotificationService } from "../notification"; export type PluginRequestHandleReq = { typeName: string; @@ -72,6 +73,8 @@ export type TaskResult = { export type TaskInstanceContext = { //流水线定义 pipeline: Pipeline; + //运行时历史 + runtime: RunHistory; //步骤定义 step: Step; //日志 @@ -86,6 +89,10 @@ export type TaskInstanceContext = { cnameProxyService: ICnameProxyService; //插件配置服务 pluginConfigService: IPluginConfigService; + //通知服务 + notificationService: INotificationService; + //url构建 + urlService: IUrlService; //流水线上下文 pipelineContext: IContext; //用户上下文 diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/base.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/base.ts index f22907264..91d0027a3 100644 --- a/packages/plugins/plugin-cert/src/plugin/cert-plugin/base.ts +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/base.ts @@ -1,4 +1,4 @@ -import { AbstractTaskPlugin, IContext, Step, TaskInput, TaskOutput } from "@certd/pipeline"; +import { AbstractTaskPlugin, IContext, NotificationBody, sendNotification, Step, TaskInput, TaskOutput } from "@certd/pipeline"; import dayjs from "dayjs"; import type { CertInfo } from "./acme.js"; import { CertReader } from "./cert-reader.js"; @@ -73,14 +73,14 @@ export abstract class CertApplyBasePlugin extends AbstractTaskPlugin { renewDays!: number; @TaskInput({ - title: "成功后邮件通知", + title: "证书申请成功通知", value: true, component: { name: "a-switch", vModel: "checked", }, order: 100, - helper: "申请成功后是否发送邮件通知", + helper: "证书申请成功后是否发送通知,优先使用默认通知渠道", }) successNotify = true; @@ -120,7 +120,7 @@ export abstract class CertApplyBasePlugin extends AbstractTaskPlugin { this.clearLastStatus(); if (this.successNotify) { - await this.sendSuccessEmail(); + await this.sendSuccessNotify(); } } else { throw new Error("申请证书失败"); @@ -301,19 +301,44 @@ export abstract class CertApplyBasePlugin extends AbstractTaskPlugin { leftDays, }; } - - private async sendSuccessEmail() { + async sendSuccessNotify() { + this.logger.info("发送证书申请成功通知"); + const url = await this.ctx.urlService.getPipelineDetailUrl(this.pipeline.id, this.ctx.runtime.id); + const body: NotificationBody = { + title: `【Certd】证书申请成功【${this.pipeline.title}】`, + content: `域名:${this.domains.join(",")}`, + url: url, + }; try { - this.logger.info("发送成功邮件通知:" + this.email); - const subject = `【CertD】证书申请成功【${this.domains[0]}】`; - await this.ctx.emailService.send({ - userId: this.ctx.pipeline.userId, - receivers: [this.email], - subject: subject, - content: `证书申请成功,域名:${this.domains.join(",")}`, - }); + const defNotification = await this.ctx.notificationService.getDefault(); + if (defNotification) { + this.logger.info(`通知渠道:${defNotification.name}`); + const notificationCtx = { + http: this.ctx.http, + logger: this.logger, + utils: this.ctx.utils, + emailService: this.ctx.emailService, + }; + await sendNotification({ + config: defNotification, + ctx: notificationCtx, + body, + }); + return; + } + this.logger.warn("未配置默认通知,将发送邮件通知"); + await this.sendSuccessEmail(body); } catch (e) { - this.logger.error("send email error", e); + this.logger.error("证书申请成功通知发送失败", e); } } + async sendSuccessEmail(body: NotificationBody) { + this.logger.info("发送邮件通知:" + this.email); + await this.ctx.emailService.send({ + userId: this.ctx.pipeline.userId, + receivers: [this.email], + subject: body.title, + content: body.content, + }); + } } 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 f38c7383f..883031478 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,21 @@ export function createApi() { }); }, + async SetDefault(id: number) { + return await request({ + url: apiPrefix + "/setDefault", + method: "post", + params: { id } + }); + }, + + async GetDefaultId() { + return await request({ + url: apiPrefix + "/getDefaultId", + method: "post" + }); + }, + async GetSimpleInfo(id: number) { return await request({ url: apiPrefix + "/simpleInfo", diff --git a/packages/ui/certd-client/src/views/certd/notification/common.tsx b/packages/ui/certd-client/src/views/certd/notification/common.tsx index de81152aa..b169089d6 100644 --- a/packages/ui/certd-client/src/views/certd/notification/common.tsx +++ b/packages/ui/certd-client/src/views/certd/notification/common.tsx @@ -2,6 +2,8 @@ import { ColumnCompositionProps, compute, dict } from "@fast-crud/fast-crud"; import { computed, provide, ref, toRef } from "vue"; import { useReference } from "/@/use/use-refrence"; import { forEach, get, merge, set } from "lodash-es"; +import { Modal } from "ant-design-vue"; +import * as api from "/@/views/sys/cname/provider/api"; export function getCommonColumnDefine(crudExpose: any, typeRef: any, api: any) { provide("notificationApi", api); @@ -141,6 +143,47 @@ export function getCommonColumnDefine(crudExpose: any, typeRef: any, api: any) { width: 200 } }, + isDefault: { + title: "是否默认", + type: "dict-switch", + dict: dict({ + data: [ + { label: "是", value: true, color: "success" }, + { label: "否", value: false, color: "default" } + ] + }), + form: { + value: false, + rules: [{ required: true, message: "请选择是否默认" }], + order: 999 + }, + column: { + align: "center", + width: 100, + component: { + name: "a-switch", + vModel: "checked", + disabled: compute(({ value }) => { + return value === true; + }), + on: { + change({ row }) { + Modal.confirm({ + title: "提示", + content: "确定设置为默认通知?", + onOk: async () => { + await api.SetDefault(row.id); + await crudExpose.doRefresh(); + }, + onCancel: async () => { + await crudExpose.doRefresh(); + } + }); + } + } + } + } + } as ColumnCompositionProps, test: { title: "测试", form: { @@ -151,7 +194,7 @@ export function getCommonColumnDefine(crudExpose: any, typeRef: any, api: any) { name: "api-test", action: "TestRequest" }, - order: 999, + order: 990, col: { span: 24 } 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 b9252db06..11faaf1d4 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 @@ -7,7 +7,7 @@ {{ placeholder }} 选择 - +
@@ -45,6 +45,10 @@ export default defineComponent({ disabled: { type: Boolean, default: false + }, + useDefault: { + type: Boolean, + default: false } }, emits: ["update:modelValue", "selectedChange", "change"], @@ -60,6 +64,15 @@ export default defineComponent({ } } + async function loadDefault() { + const defId = await api.GetDefaultId(); + if (defId) { + await emitValue(defId); + } + } + + loadDefault(); + function clear() { if (props.disabled) { return; diff --git a/packages/ui/certd-client/src/views/certd/notification/notification-selector/modal/crud.tsx b/packages/ui/certd-client/src/views/certd/notification/notification-selector/modal/crud.tsx index 64a43eb20..7bd22238d 100644 --- a/packages/ui/certd-client/src/views/certd/notification/notification-selector/modal/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/notification/notification-selector/modal/crud.tsx @@ -56,9 +56,6 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat show: false }, form: { - wrapper: { - width: "1050px" - }, labelCol: { //固定label宽度 span: null, @@ -72,7 +69,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat }, table: { scroll: { - x: 800 + x: 700 }, rowSelection: { type: "radio", 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 8c0d4c2b5..170dade69 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 @@ -109,7 +109,8 @@ export default function (certPluginGroup: PluginGroup, formWrapperRef: any): Cre form: { component: { name: NotificationSelector, - vModel: "modelValue" + vModel: "modelValue", + useDefault: true }, order: 101, helper: "建议设置,任务执行失败实时提醒" diff --git a/packages/ui/certd-client/src/views/certd/settings/api.ts b/packages/ui/certd-client/src/views/certd/settings/api.ts new file mode 100644 index 000000000..4cec16e03 --- /dev/null +++ b/packages/ui/certd-client/src/views/certd/settings/api.ts @@ -0,0 +1,27 @@ +// @ts-ignore +import { request } from "/@/api/service"; +import { SysPrivateSetting, SysPublicSetting } from "/@/api/modules/api.basic"; +const apiPrefix = "/user/settings"; +export type UserSettings = { + defaultNotification?: number; + defaultCron?: string; +}; + +export async function UserSettingsGet() { + const res = await request({ + url: apiPrefix + "/getDefault", + method: "post" + }); + if (!res) { + return {}; + } + return res; +} + +export async function UserSettingsSave(setting: any) { + return await request({ + url: apiPrefix + "/saveDefault", + method: "post", + data: setting + }); +} diff --git a/packages/ui/certd-client/src/views/certd/settings/index.vue b/packages/ui/certd-client/src/views/certd/settings/index.vue new file mode 100644 index 000000000..f2344e221 --- /dev/null +++ b/packages/ui/certd-client/src/views/certd/settings/index.vue @@ -0,0 +1,74 @@ + + + + + diff --git a/packages/ui/certd-server/db/migration/v10014__notification_default.sql b/packages/ui/certd-server/db/migration/v10014__notification_default.sql new file mode 100644 index 000000000..f86e9b478 --- /dev/null +++ b/packages/ui/certd-server/db/migration/v10014__notification_default.sql @@ -0,0 +1 @@ +ALTER TABLE pi_notification ADD COLUMN is_default boolean DEFAULT (0); diff --git a/packages/ui/certd-server/src/controller/pipeline/handle-controller.ts b/packages/ui/certd-server/src/controller/pipeline/handle-controller.ts index ddb06ed68..30d2c9814 100644 --- a/packages/ui/certd-server/src/controller/pipeline/handle-controller.ts +++ b/packages/ui/certd-server/src/controller/pipeline/handle-controller.ts @@ -69,7 +69,7 @@ export class HandleController extends BaseController { // } // } - const notification = newNotification(body.typeName, input, { + const notification = await newNotification(body.typeName, input, { http, logger, utils, 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 ca1d68275..7a0701dc3 100644 --- a/packages/ui/certd-server/src/controller/pipeline/notification-controller.ts +++ b/packages/ui/certd-server/src/controller/pipeline/notification-controller.ts @@ -1,5 +1,5 @@ import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core'; -import { Constants, CrudController } from '@certd/lib-server'; +import { Constants, CrudController, ValidateException } from '@certd/lib-server'; import { NotificationService } from '../../modules/pipeline/service/notification-service.js'; import { AuthService } from '../../modules/sys/authority/service/auth-service.js'; @@ -84,8 +84,30 @@ export class NotificationController extends CrudController @Post('/simpleInfo', { summary: Constants.per.authOnly }) async simpleInfo(@Query('id') id: number) { + if (id === 0) { + //获取默认 + const res = await this.service.getDefault(this.getUserId()); + if (!res) { + throw new ValidateException('默认通知配置不存在'); + } + const simple = await this.service.getSimpleInfo(res.id); + return this.ok(simple); + } await this.authService.checkEntityUserId(this.ctx, this.service, id); const res = await this.service.getSimpleInfo(id); return this.ok(res); } + + @Post('/getDefaultId', { summary: Constants.per.authOnly }) + async getDefaultId() { + const res = await this.service.getDefault(this.getUserId()); + return this.ok(res?.id); + } + + @Post('/setDefault', { summary: Constants.per.authOnly }) + async setDefault(@Query('id') id: number) { + await this.service.checkUserId(id, this.getUserId()); + const res = await this.service.setDefault(id, this.getUserId()); + return this.ok(res); + } } diff --git a/packages/ui/certd-server/src/modules/pipeline/entity/notification.ts b/packages/ui/certd-server/src/modules/pipeline/entity/notification.ts index 03f00d844..555c4e884 100644 --- a/packages/ui/certd-server/src/modules/pipeline/entity/notification.ts +++ b/packages/ui/certd-server/src/modules/pipeline/entity/notification.ts @@ -17,6 +17,9 @@ export class NotificationEntity { @Column({ name: 'setting', comment: '通知配置', length: 10240 }) setting: string; + @Column({ name: 'is_default', comment: '是否默认' }) + isDefault: boolean; + @Column({ name: 'create_time', comment: '创建时间', diff --git a/packages/ui/certd-server/src/modules/pipeline/service/notification-getter.ts b/packages/ui/certd-server/src/modules/pipeline/service/notification-getter.ts index 2fbb03b33..34baa8cad 100644 --- a/packages/ui/certd-server/src/modules/pipeline/service/notification-getter.ts +++ b/packages/ui/certd-server/src/modules/pipeline/service/notification-getter.ts @@ -1,14 +1,20 @@ import { INotificationService } from '@certd/pipeline'; +import { NotificationService } from './notification-service.js'; export class NotificationGetter implements INotificationService { userId: number; - getter: (id: any, userId?: number) => Promise; - constructor(userId: number, getter: (id: any, userId: number) => Promise) { + notificationService: NotificationService; + + constructor(userId: number, notificationService: NotificationService) { this.userId = userId; - this.getter = getter; + this.notificationService = notificationService; } - async getById(id: any) { - return await this.getter(id, this.userId); + async getDefault() { + return await this.notificationService.getDefault(this.userId); + } + + async getById(id: any) { + return await this.notificationService.getById(id, this.userId); } } diff --git a/packages/ui/certd-server/src/modules/pipeline/service/notification-service.ts b/packages/ui/certd-server/src/modules/pipeline/service/notification-service.ts index da17735cb..81130a956 100644 --- a/packages/ui/certd-server/src/modules/pipeline/service/notification-service.ts +++ b/packages/ui/certd-server/src/modules/pipeline/service/notification-service.ts @@ -50,14 +50,60 @@ export class NotificationService extends BaseService { }, }); if (!res) { - throw new ValidateException('通知配置不存在'); + throw new ValidateException(`通知配置不存在<${id}>`); } + return this.buildNotificationInstanceConfig(res); + } + + private buildNotificationInstanceConfig(res: NotificationEntity) { const setting = JSON.parse(res.setting); return { id: res.id, type: res.type, + name: res.name, userId: res.userId, setting, }; } + + async getDefault(userId: number): Promise { + const res = await this.repository.findOne({ + where: { + userId, + }, + order: { + isDefault: 'DESC', + }, + }); + if (!res) { + throw new ValidateException('默认通知配置不存在'); + } + return this.buildNotificationInstanceConfig(res); + } + + async setDefault(id: number, userId: number) { + if (!id) { + throw new ValidateException('id不能为空'); + } + if (!userId) { + throw new ValidateException('userId不能为空'); + } + await this.repository.update( + { + userId, + }, + { + isDefault: false, + } + ); + await this.repository.update( + { + id, + userId, + }, + { + isDefault: true, + } + ); + } } diff --git a/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts b/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts index 587744a6f..7f19190fd 100644 --- a/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts +++ b/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts @@ -393,7 +393,7 @@ export class PipelineService extends BaseService { }; const accessGetter = new AccessGetter(userId, this.accessService.getById.bind(this.accessService)); const cnameProxyService = new CnameProxyService(userId, this.cnameRecordService.getWithAccessByDomain.bind(this.cnameRecordService)); - const notificationGetter = new NotificationGetter(userId, this.notificationService.getById.bind(this.notificationService)); + const notificationGetter = new NotificationGetter(userId, this.notificationService); const executor = new Executor({ user, pipeline, diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/bark/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/bark/index.ts index 47a0dc9d6..cb776545f 100644 --- a/packages/ui/certd-server/src/plugins/plugin-notification/bark/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-notification/bark/index.ts @@ -30,6 +30,18 @@ export class BarkNotification extends BaseNotification { helper: '你的bark服务地址+key', }) webhook = ''; + + @NotificationInput({ + title: '忽略证书校验', + value: false, + component: { + name: 'a-switch', + vModel: 'checked', + }, + required: false, + }) + skipSslVerify: boolean; + async send(body: NotificationBody) { if (!this.webhook) { throw new Error('服务器地址不能为空'); @@ -47,6 +59,7 @@ export class BarkNotification extends BaseNotification { 'Content-Type': 'application/json; charset=utf-8', }, data: payload, + skipSslVerify: this.skipSslVerify, }); } } diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/serverchan/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/serverchan/index.ts index 7be7485d8..67c356aef 100644 --- a/packages/ui/certd-server/src/plugins/plugin-notification/serverchan/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-notification/serverchan/index.ts @@ -43,6 +43,17 @@ export class ServerChanNotification extends BaseNotification { }) noip: boolean; + @NotificationInput({ + title: '忽略证书校验', + value: false, + component: { + name: 'a-switch', + vModel: 'checked', + }, + required: false, + }) + skipSslVerify: boolean; + async send(body: NotificationBody) { if (!this.sendKey) { throw new Error('sendKey不能为空'); @@ -54,6 +65,7 @@ export class ServerChanNotification extends BaseNotification { text: body.title, desp: body.content + '[查看详情](' + body.url + ')', }, + skipSslVerify: this.skipSslVerify, }); } } diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/vocechat/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/vocechat/index.ts index c7c4f679a..9a1116bd7 100644 --- a/packages/ui/certd-server/src/plugins/plugin-notification/vocechat/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-notification/vocechat/index.ts @@ -49,6 +49,17 @@ export class VoceChatNotification extends BaseNotification { }) targetId = ''; + @NotificationInput({ + title: '忽略证书校验', + value: false, + component: { + name: 'a-switch', + vModel: 'checked', + }, + required: false, + }) + skipSslVerify: boolean; + async send(body: NotificationBody) { if (!this.apiKey) { throw new Error('API Key不能为空'); @@ -68,6 +79,7 @@ export class VoceChatNotification extends BaseNotification { 'Content-Type': 'text/markdown', }, data: `# ${body.title}\n\n${body.content}\n[查看详情](${body.url})`, + skipSslVerify: this.skipSslVerify, }); } } diff --git a/packages/ui/certd-server/src/plugins/plugin-notification/webhook/index.ts b/packages/ui/certd-server/src/plugins/plugin-notification/webhook/index.ts index 9e38a41c3..a4c65644d 100644 --- a/packages/ui/certd-server/src/plugins/plugin-notification/webhook/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-notification/webhook/index.ts @@ -82,6 +82,17 @@ export class WebhookNotification extends BaseNotification { }) template = ''; + @NotificationInput({ + title: '忽略证书校验', + value: false, + component: { + name: 'a-switch', + vModel: 'checked', + }, + required: false, + }) + skipSslVerify: boolean; + replaceTemplate(target: string, body: any, urlEncode = false) { let bodyStr = target; const keys = Object.keys(body); @@ -143,6 +154,7 @@ export class WebhookNotification extends BaseNotification { ...headers, }, data: data, + skipSslVerify: this.skipSslVerify, }); } catch (e) { if (e.response?.data) {