An webhook-driven executor with a plugin interface designed for audit compliance
Install the Rust toolchain. Instructions can be found here.
Navigate to miss-demeanor/
and run cargo build --release
.
Your executable will be located at ./target/release/miss-demeanor
.
Currently the TLS library that miss-demeanor uses only supports a PCKS12/DER identity format. This is not my choice and I hope to eventually be able to support PEM identites for the server.
To easily generate a self-signed certificate for testing, run: ``` openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365 openssl pkcs12 -export -out identity.pfx -inkey key.pem -in cert.pem
```
The invocation is pretty simple: provide the path to -f
for your PKCS12 identity file and use
the environment variable PKCS12_PASSWORD
to supply the password.
The config file is written in TOML.
Here is a sample config file with some comment explanations:
``` triggertype = "cabi" # Can also be "interpreted"
[server] servertype = "webhook" # Can also be "unixsocket" listenaddr = "127.0.0.1:8080" # Must be in the format IP:PORT usetls = false # You probably want this on unless you are running it over localhost - must pass -f on CLI when this is enabled
[[server.endpoints]] path = "/pr" # URL path trigger_name = "github-pr" # Unique name
[[server.endpoints]] path = "/merged" trigger_name = "github-merged"
[[triggers]] name = "github-merged" # Unique name plugin_path = "./example-plugins/golang/github-merged.so" # Path to C ABI compatible shared object (.so) ```
The idea is to expose the server configuration declaratively. The config file controls everything about the server - endpoints, listen address, transport layer, plugins associated with each endpoint, etc.
How do you actually write a plugin for miss-demeanor though?
First check out miss-demeanor/example-plugins/
for code
examples.
The longer answer is this: a plugin can be one of two formats.
trigger
. To use this feature, set trigger type
to c_abi
.C function signature:
int trigger(void *http_request);
Rust function signature:
fn trigger(http_request: *const libc::c_void) -> libc::c_int;
C example:
```
int trigger(void *httprequest) { printf("%s\n", requestgetmethod(httprequest)); return 0; } ```
Golang example:
``` // #include "trigger.h" // #cgo LDFLAGS: -lmissdemeanor -ldl import "C" import "unsafe"
import "fmt"
//export trigger func trigger(httprequest unsafe.Pointer) C.int { fmt.Println(C.GoString(C.requestgetmethod(httprequest))) }
func main {} ```
Rust example:
``` use missdemeanor::CRequest;
pub fn trigger(httprequest: *const CRequest) -> libc::cint { let method = match unsafe { request.asref() }.getmethod() { Ok(b) => b, Err(e) => { println!("{}", e); return 1; }, }; println!("{}", method); } ```
interpreted
.Python example:
```
import sys
method = sys.argv[1]
print(method) ```