码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2018-09-25 18:01:05      阅读:534      评论:0      收藏:0      [点我收藏+]

标签:content   curl   ima   .json   payload   echo   width   post   spl   

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

技术分享图片

  • 规则匹配
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

技术分享图片

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

  • url
  • header
  • json (payload)

参考资料

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

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

标签:content   curl   ima   .json   payload   echo   width   post   spl   

原文地址:https://www.cnblogs.com/rongfengliang/p/9700831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!