Safe Haskell | None |
---|---|
Language | Haskell2010 |
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 yourWAI
-based web server (such aswarp
). - Use the
authenticate
middleware to reject requests that don't originate fromtravis-ci.com
.
For example,
-- In .travis.yml notifications: 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
- payload :: Request -> IO Value
- data TravisException
Authentication
authenticate :: [Text] -> Middleware Source #
Only allow travis-ci.com
to POST
to the given path.
Payload
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.
Exceptions
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 |
Example
{-# 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 = casepathInfo
request of ["travis"] -> do -- (2) payload <- TravisCI.payload
request -- (3) print payload _ -> pure () respond (responseLBS
status200
[] "")
Above is a minimal WAI
application that authenticates POST
s to /travis
,
then prints out the parsed payload (an aeson
Value
).
- At
(1)
, we define the middleware, which authenticates everyPOST
to/travis
. - At
(2)
, we handle thesePOST
s in our application. - At
(3)
, we parse the JSON payload, whose schema is, unsurprisingly, barely defined at all. See https://docs.travis-ci.com/user/notifications/#Webhooks-Delivery-Format for more information.