Listens on a specified port for (authenticated) incoming webhooks or requests and runs a specified command.
The configuration should mostly be self-explanatory, below is an example. Hooks
will be authenticated using the Token
header, if either the hook-specific
Token
or the globalToken
match, the command below will be run using
/bin/sh -c
.
Individual hooks will be matched by path using the name in the hooks
map.
host: "127.0.0.1"
port: "9999"
globalToken: "the-defaulttoken"
hooks:
hello:
command: "echo 'hello world'"
token: "token1"
ping:
command: "ping -c 4 google.de"
token: "token2"
list:
Command: "ls -l"
With the configuration above:
curl 127.0.0.1:9999/hello -H 'Token: token1'
would executeecho 'hello world'
curl 127.0.0.1:9999/ping -H 'Token: the-defaulttoken'
would executeping -c 4 google.de
curl 127.0.0.1:9999/list -H 'Token: the-defaulttoken'
would executels -l
The path to the configuration should be specified using the HOOKER_CONFIG
environment variable.
To avoid having tokens in the configuration, it is also possible to specify them via environment variables
- The
globalToken
can be specified using theHOOKER_TOKEN
environment variable. - Tokens for individual hooks will be searched in environment variables with the
same name and the
HOOKER_TOKEN_
prefix (HOOKER_TOKEN_<name of the token in uppercase>
). e.g.: for the last hook of the configuration example above the token would be specified inHOOKER_TOKEN_LIST
.
The flake.nix
file includes a module for NixOS users. Import and use as shown
below:
# Add to flake inputs
inputs.webhooker.url = "github:pinpox/webhooker";
# Import the module in your configuration.nix
imports = [ self.inputs.webhooker.nixosModules.webhooker ];
services.webhooker = {
enable = true;
envFile = "/path/to/your/envfile";
settings = {
host = "0.0.0.0";
port = "8888";
hooks = {
hello.command = "echo 'hello'";
world.command = "echo 'world'";
};
};
};
For develoment the flake also provides NixOS tests. Use nix flake check -v
to
run them or nix run .\#checks.x86_64-linux.vmTest.driverInteractive
for
interactive testing and debugging.