分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

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

发布时间:2023-09-06 02:15责任编辑:顾先生关键词:暂无标签

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/shecho $@ , $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 以及参数传递处理

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved