CI からの webhook を受け取りたいけどお家Portを開けるのはちょっと...な場合に
便利なツールを見つけたので。
公式サイト
インストール
mac
brew install webhookrelay/tap/relay
raspi
DIR=$GOPATH/src/github.com/webhookrelay/
mkdir -p $DIR
cd $DIR
git clone https://github.com/webhookrelay/client
make deps
make build
使い方
双方向な connect と
片方向な forward があります。
今回は webhook なので forward で記述します。
- 公式ページからログイン
- Access Tokensを生成
- コマンド(relay)の認証
- forwarding
1. 公式ページからログイン
github アカウントを使ってログインします。
専用のアカウントを使った場合は、2番を飛ばしてよいです。
2. Access Tokensを生成
https://my.webhookrelay.com/tokens
から token を生成します。
生成後、説明文があるあたりに Access Key と Secret Key が表示されます。
3番で使うのでリロードしないようにします。
3. コマンド(relay)の認証
専用のアカウントの人は、自分のアカウント名+パスワード。
OAuthの人は、2番のキー。
relay login -u <Access Key> -p <Secret Key>
4. forwarding
localhostに立てた hubot に json を投げてみます。
forward開始
relay forward localhost:8080
Forwarding:
https://my.webhookrelay.com/v1/webhooks/fakeurl -> localhost:8080
Starting webhook relay agent...
INFO[0005] webhook relay ready... host="api.webhookrelay.com:8080"
hubot (localhost:8080でリッスン)
scripts/example.coffee
robot.router.post '/hubot/deployment/circleci', (req, res) ->
data = req.body
console.log(data)
client:
post
[@raspberrypi /tmp]$ curl -X POST https://fakeurl/hubot/deployment/circleci -d@hoge.json
jsonの中身
[@raspberrypi /tmp]$ cat hoge.json
{
"foo": "bar"
}
結果
hubotを起動している console に json が出力されていることが確認できます。
{ '{ "foo": "bar"}': '' }