wai-middleware-travisci-0.1.0: WAI middleware for authenticating webhook payloads from Travis CI

Safe HaskellNone




travis-ci.com webhook authentication middleware.

See https://docs.travis-ci.com/user/notifications/#Configuring-webhook-notifications for more information about webhooks.

In brief:

  • Configure travis-ci.com to send webhook notifications to your WAI-based web server (such as warp).
  • Use the authenticate middleware to reject requests that don't originate from travis-ci.com.

For example,

-- In .travis.yml
  webhooks: http://my-domain.com/my-webhook-path
-- In code
TravisCI.authenticate ["my-webhook-path"]

See the bottom of this module for a longer example.



authenticate :: [Text] -> Middleware Source #

Only allow travis-ci.com to POST to the given path.


payload :: Request -> IO Value Source #

Retrieve the payload from an authenticated Request.

This function must be called on a Request that was handled by the authenticate middleware. Otherwise, it will throw a TravisNoValue exception.


data TravisException Source #


TravisNoParse Request

JSON-decoding an authenticated payload failed. This should never happen; it means Travis CI signed and sent a payload that was not valid JSON.

TravisNoValue Request

A call to payload failed because there was no Value inserted into the request vault by the authenticate middleware. This should never happen, but if it does, it's your fault; it means you called payload on a Request that did not pass through the authenticate middleware.


{-# language OverloadedStrings #-}

import Network.Wai                    -- wai
import Network.Wai.Handler.Warp (run) -- warp
import Network.HTTP.Types             -- http-types

import qualified Network.Wai.Middleware.TravisCI as TravisCI

main :: IO ()
main =
  run 8000 (middleware app)

middleware :: Middleware
middleware =
  TravisCI.authenticate ["travis"]         -- (1)

app :: Application
app request respond =
  case pathInfo request of
    ["travis"] -> do                       -- (2)
      payload <- TravisCI.payload request  -- (3)
      print payload
    _ -> pure ()
  respond (responseLBS status200 [] "")

Above is a minimal WAI application that authenticates POSTs to /travis, then prints out the parsed payload (an aeson Value).