Giter VIP home page Giter VIP logo

captainhook's Introduction

captainhook

A generic webhook endpoint that runs scripts based on the URL called

This tool was built as part of a CI orchestration process, to be called when Docker trusted builds finish. It explicitly ignores the posted data from the webhook because that would be insecure, which is bad.

Quick Start

Install captainhook

go get github.com/bketelsen/captainhook

Create the configdir

mkdir ~/captainhook

Add a script

{
    "scripts": [
        {
            "command": "ls",
            "args": [
                "-l",
                "-a"
            ]
        },
        {
            "command": "echo",
            "args": [
		    "hello"
		    ]
        }
    ]
}

Name this script endpoint1.json

Start the service

captainhook -configdir ~/captainhook

Test using curl

curl -X POST http://localhost:8080/endpoint1

Configure calling webhooks

Each script you create in the configdir will be executed when the corresponding endpoint is called.

If you have a script called deployBigApp.json you would trigger it by posting to http://your.captainhook.url/deployBigApp.

The scripts in the json file are executed sequentially, and the output is logged and returned to the caller in the response, which always has an HTTP status code of 200 (OK) even if your scripts didn't work. This is intentional, to avoid causing errors in external services like Docker or Github, which might not like you returning statuses other than 200 (OK).

Accessing the Request POST Body

You'll sometimes need to access the POST data of the request for information such as a callback URL. You can pass the raw POST data to a script by adding {{POST}} to the script arguments.

{
    "scripts": [
        {
            "command": "echo",
            "args": [
            "{{POST}}"
            ]
        }
    ]
}

Limiting access for webhooks

You can limit who can call your webhooks by specifying "allowedNetworks" in the json config.

{
    "scripts": [
        {
            "command": "echo"
        }
    ],
    "allowedNetworks": [
        "10.0.0.0/8",
        "127.0.0.1/32"
    ]
}

This would allow your hook to be called from the 10.0.0.0/8 network, or from localhost.

Supporting proxy headers for client IP

Only enable proxy support if you are on a trusted network behind a reverse proxy. End-users with direct network access can subvert the allowedNetworks restriction if proxy support is on.

captainhook -configdir ~/captainhook -enable-proxy -proxy-header X-Forwarded-For

Docker

docker pull bketelsen/captainhook
mkdir /some/local/config
$EDITOR /some/local/config/myhook.json
docker run -d -v /some/local/config:/config bketelsen/captainhook

Install

go get github.com/bketelsen/captainhook

Build

Download

mkdir -p $GOPATH/src/github.com/bketelsen
cd $GOPATH/src/github.com/bketelsen
git clone [email protected]:bketelsen/captainhook.git
go build .

To Do

  • more logs

Copyright 2014, Brian Ketelsen and Kelsey Hightower LICENSE information found in LICENSE file.

captainhook's People

Contributors

bketelsen avatar kelseyhightower avatar soellman avatar kelcecil avatar vic3lord avatar

Watchers

James Cloos avatar Nick Reese avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.