adnanh webhook 框架request values 说明

时间:2023-03-09 09:01:14
adnanh webhook 框架request values 说明

request values 在adnanh webhook 是比较重要的,规则触发以及命令参数传递都是通过它
支持的request values 类似

  • http header
  • 查询参数
  • playload(json 或者表单字段)(同时支持jsonpath)
  • 传递playload 的json 字符串(header ,query ,payload)
    说明:
    参数同时可以作为环境变量传递
    以下为参考

环境准备

docker-compose 运行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 json
[
{
"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":
[
{ // playload 使用
"source": "payload",
"name": "id"
},
// 查询字符串
{
"source": "url",
"name": "token"
},
// header
{
"source":"header",
"name":"token"
},
//
{
"source": "payload",
"name": "users.0.id"
},
// 环境变量
{
"source": "url",
"name": "token",
"envname": "MY_TOKEN"
},
// playload json 字符串
{
"source": "entire-payload",
"name":"all-json"
},
// header json 字符串
{
"source": "entire-headers",
"name":"all-header"
},
// 查询参数json 字符串
{
"source": "entire-query",
"name":"all-query"
}
],
"trigger-rule":
{
"match":
{
"type": "value",
"value": "42",
"parameter":
{
"source": "url",
"name": "token"
}
}
}
}
]
  • shell command 文件
#!/bin/sh
echo $@ , $1, $2

header

  • 配置
单一值:
{
"source":"header",
"name":"token"
}
header json 字符串:
{
"source": "entire-headers",
"name":"all-header"
}

url

  • 配置
单一值:
{
"source": "url",
"name": "token"
}
json 字符串
{
"source": "entire-query",
"name":"all-query"
}

playload

  • 配置
单一值:
{
"source": "payload",
"name": "id"
}
jsonpath:
{
"source": "payload",
"name": "users.0.id"
}
json 字符串
{
"source": "entire-payload",
"name":"all-json"
}

运行测试

  • curl 代码
curl -X POST \
'http://localhost:9000/hooks/simple-one?token=42&name=demoapp&mytoken=%E8%8D%A3' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: 2248c162-de61-562d-23c0-3e7d60445785' \
-H 'token: demoapp' \
-d '{
"id":"荣锋亮",
"users":[ {
"name":"demoapp",
"id":555555
}
]
}'
  • 结果
HOSTNAME=b4addd3279c7
SHLVL=1
HOME=/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/shells
荣锋亮 42 demoapp 555555 荣 {"id":"荣锋亮","users":[{"id":555555,"name":"demoapp"}]} {"Accept":"*/*","Cache-Control":"no-cache","Content-Length":"87","Content-Type":"application/json","Postman-Token":"2248c162-de61-562d-23c0-3e7d60445785","Token":"demoapp","User-Agent":"curl/7.54.0"} {"mytoken":"荣","name":"demoapp","token":"42"} , 荣锋亮, 42

问题

当前测试环境变量是有点问题的,待确定原因

参考资料

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