mirror of https://github.com/certd/certd
chore:
parent
cbe0b1c5a6
commit
5f4a89cecc
|
@ -1,4 +1,4 @@
|
||||||
import { Controller, Get, Inject, Provide } from '@midwayjs/core';
|
import {Body, Controller, Get, Inject, Post, Provide} from '@midwayjs/core';
|
||||||
import { BaseController, Constants, FileService, SysSettingsService, SysSiteInfo } from '@certd/lib-server';
|
import { BaseController, Constants, FileService, SysSettingsService, SysSiteInfo } from '@certd/lib-server';
|
||||||
import { http, logger } from '@certd/basic';
|
import { http, logger } from '@certd/basic';
|
||||||
import { isComm } from '@certd/plus-core';
|
import { isComm } from '@certd/plus-core';
|
||||||
|
@ -46,4 +46,10 @@ export class AppController extends BaseController {
|
||||||
this.ctx.response.redirect(redirect);
|
this.ctx.response.redirect(redirect);
|
||||||
this.ctx.response.set('Cache-Control', 'public,max-age=25920');
|
this.ctx.response.set('Cache-Control', 'public,max-age=25920');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('/webhook', { summary: Constants.per.guest })
|
||||||
|
public async webhook( @Body() body: any) {
|
||||||
|
logger.info('webhook', JSON.stringify(body))
|
||||||
|
return this.ok("success")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ import qs from 'qs';
|
||||||
import {
|
import {
|
||||||
AbstractTaskPlugin,
|
AbstractTaskPlugin,
|
||||||
IsTaskPlugin,
|
IsTaskPlugin,
|
||||||
NotificationBody,
|
|
||||||
pluginGroups,
|
pluginGroups,
|
||||||
RunStrategy,
|
RunStrategy,
|
||||||
TaskInput
|
TaskInput
|
||||||
|
@ -15,7 +14,7 @@ import {CertApplyPluginNames, CertInfo, CertReader} from "@certd/plugin-cert";
|
||||||
icon: 'ion:send-sharp',
|
icon: 'ion:send-sharp',
|
||||||
desc: '调用webhook部署证书',
|
desc: '调用webhook部署证书',
|
||||||
group: pluginGroups.other.key,
|
group: pluginGroups.other.key,
|
||||||
showRunStrategy:true,
|
showRunStrategy: false,
|
||||||
default: {
|
default: {
|
||||||
strategy: {
|
strategy: {
|
||||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||||
|
@ -33,7 +32,7 @@ export class WebhookDeployCert extends AbstractTaskPlugin {
|
||||||
},
|
},
|
||||||
required: true
|
required: true
|
||||||
})
|
})
|
||||||
cert!: CertInfo ;
|
cert!: CertInfo;
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: 'webhook地址',
|
title: 'webhook地址',
|
||||||
|
@ -54,9 +53,9 @@ export class WebhookDeployCert extends AbstractTaskPlugin {
|
||||||
name: 'a-select',
|
name: 'a-select',
|
||||||
placeholder: 'post/put/get',
|
placeholder: 'post/put/get',
|
||||||
options: [
|
options: [
|
||||||
{ value: 'POST', label: 'POST' },
|
{value: 'POST', label: 'POST'},
|
||||||
{ value: 'PUT', label: 'PUT' },
|
{value: 'PUT', label: 'PUT'},
|
||||||
{ value: 'GET', label: 'GET' },
|
{value: 'GET', label: 'GET'},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -69,8 +68,8 @@ export class WebhookDeployCert extends AbstractTaskPlugin {
|
||||||
component: {
|
component: {
|
||||||
name: 'a-auto-complete',
|
name: 'a-auto-complete',
|
||||||
options: [
|
options: [
|
||||||
{ value: 'application/json', label: 'application/json' },
|
{value: 'application/json', label: 'application/json'},
|
||||||
{ value: 'application/x-www-form-urlencoded', label: 'application/x-www-form-urlencoded' },
|
{value: 'application/x-www-form-urlencoded', label: 'application/x-www-form-urlencoded'},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
helper: '也可以自定义填写',
|
helper: '也可以自定义填写',
|
||||||
|
@ -97,8 +96,8 @@ export class WebhookDeployCert extends AbstractTaskPlugin {
|
||||||
title: '消息body模版',
|
title: '消息body模版',
|
||||||
value: `{
|
value: `{
|
||||||
"id":"123",
|
"id":"123",
|
||||||
"crt":"{crt}",
|
"crt":"\${crt}",
|
||||||
"key":"{key}"
|
"key":"\${key}"
|
||||||
}`,
|
}`,
|
||||||
component: {
|
component: {
|
||||||
name: 'a-textarea',
|
name: 'a-textarea',
|
||||||
|
@ -126,6 +125,17 @@ export class WebhookDeployCert extends AbstractTaskPlugin {
|
||||||
})
|
})
|
||||||
skipSslVerify: boolean;
|
skipSslVerify: boolean;
|
||||||
|
|
||||||
|
|
||||||
|
@TaskInput({
|
||||||
|
title: '成功判定',
|
||||||
|
helper: "返回结果中包含此字符串则表示部署成功,不填则仅通过statusCode判定",
|
||||||
|
component: {
|
||||||
|
name: 'a-input',
|
||||||
|
placeholder: '例如: status:"success"',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
successStr = '';
|
||||||
|
|
||||||
replaceTemplate(target: string, body: any, urlEncode = false) {
|
replaceTemplate(target: string, body: any, urlEncode = false) {
|
||||||
let bodyStr = target;
|
let bodyStr = target;
|
||||||
const keys = Object.keys(body);
|
const keys = Object.keys(body);
|
||||||
|
@ -184,8 +194,9 @@ export class WebhookDeployCert extends AbstractTaskPlugin {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let res = null
|
||||||
try {
|
try {
|
||||||
const res = await this.http.request({
|
res = await this.http.request({
|
||||||
url: url,
|
url: url,
|
||||||
method: this.method,
|
method: this.method,
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -194,21 +205,30 @@ export class WebhookDeployCert extends AbstractTaskPlugin {
|
||||||
},
|
},
|
||||||
data: data,
|
data: data,
|
||||||
skipSslVerify: this.skipSslVerify,
|
skipSslVerify: this.skipSslVerify,
|
||||||
|
responseType: "text",
|
||||||
|
returnOriginRes: true
|
||||||
});
|
});
|
||||||
return res
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.response?.data) {
|
if (e.response?.data) {
|
||||||
throw new Error(e.message + ',' + JSON.stringify(e.response.data));
|
throw new Error(e.message + ',' + JSON.stringify(e.response.data));
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.successStr && !res?.data?.includes(this.successStr)) {
|
||||||
|
throw new Error(`请求失败,期望包含:${this.successStr},实际返回:${res.data}`);
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
async onInstance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async onInstance() {}
|
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
this.logger.info(`通过webhook部署开始`);
|
this.logger.info(`通过webhook部署开始`);
|
||||||
await this.send();
|
await this.send();
|
||||||
this.logger.info('部署成功');
|
this.logger.info('部署成功');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new WebhookDeployCert();
|
new WebhookDeployCert();
|
||||||
|
|
Loading…
Reference in New Issue