首页 技术 正文
技术 2022年11月17日
0 收藏 356 点赞 4,676 浏览 1573 个字

 

adnanh webhook是一个很不错的webhook 实现,方便灵活。
adnanh webhook 支持以下功能:

  • 接收请求
  • 解析header 以及负载以及查询变量
  • 规则检查
  • 执行命令
    下面进行简单的参数传递测试

环境准备

参考git https://github.com/rongfengliang/adnanh-webhook-docker-compose

  • docker-compose
version: "3"
services:
webhook:
image: almir/webhook
command: ["-verbose", "-hooks=/etc/webhook/hooks.json","-hotreload"]
volumes:
- "./hooks.json:/etc/webhook/hooks.json"
- "./shell/:/shells/"
ports:
- "9000:9000"
  • hooks 文件
[
{
"id": "simple-one",
"execute-command": "/shells/app",
"include-command-output-in-response":true,
"include-command-output-in-response-on-error":true,
"command-working-directory":"/shells",
"pass-arguments-to-command":
[
{
"source": "payload",
"name": "id"
},
{
"source": "url",
"name": "token"
}
],
"trigger-rule":
{
"match":
{
"type": "value",
"value": "42",
"parameter":
{
"source": "url",
"name": "token"
}
}
}
}
]
  • shell 脚本
#!/bin/sh
echo $@ , $1, $2

说明

对于请求参数包含token=42 的才会执行shell 命令,同时将url 参数token 以及payload(post请求)中的id,传递给shell
同时配置了将shell 结果输出到响应,从运行模式来看就类似当前serverless框架的运行原理。

测试

  • 不符合wehook rule
curl -X POST \
'http://localhost:9000/hooks/simple-one?token=44' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: 85f3425b-a0a7-cf80-c49a-87299d905a6c' \
-d '{
"id":"dalongdemo"
}'
Hook rules were not satisfied

adnanh webhook 框架execute-command 以及参数传递处理

  • 规则匹配
curl -X POST \
'http://localhost:9000/hooks/simple-one?token=42' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: 76d20d8d-a72e-9ae4-2570-115f57479116' \
-d '{
"id":"dalongdemo"
}'
dalongdemo 42 , dalongdemo, 42

adnanh webhook 框架execute-command 以及参数传递处理

支持的传递给执行命令的参数

  • url
  • header
  • json (payload)

参考资料

https://github.com/rongfengliang/adnanh-webhook-docker-compose
https://github.com/adnanh/webhook/blob/master/docs/Referencing-Request-Values.md

    

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902