3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

webhook(public)をprivateネットワークに投げる

3
Posted at

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 で記述します。

  1. 公式ページからログイン
  2. Access Tokensを生成
  3. コマンド(relay)の認証
  4. 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"}': '' }
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?