-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Wai Middleware for Consul
--   
--   Proxies data to/from Consul. Watches for updates.
@package wai-middleware-consul
@version 0.1.0.2


-- | This module helps you proxy information to Consul from the internet
--   &amp; also react to changes to K/V data coming from Consul.
--   
--   <pre>
--         ┌─────────┐      ┌─────────┐
--         │  JSON   │      │  LOAD   │
--         │  HTTP   │─────▶│ BALANCR │
--         │  POST   │      │         │
--         └─────────┘      └─────────┘
--                               │
--           ┌────────────┬──────┘─ ─ ─
--           │                         │
--           ▼            ▼            ▼
--      ┌─────────┐  ┌─────────┐  ┌─────────┐
--      │         │  │         │  │         │
--   ┌──│ WAI App │  │ WAI App │  │ WAI App │
--   │  │         │  │         │  │         │
--   │  └─────────┘  └─────────┘  └─────────┘
--   │                    ▲            ▲
--   │                    │            │
--   │       ┌────────────┴────────────┘
--   │       │
--   │       │
--   │  ┌─────────┐  ┌─────────┐  ┌─────────┐
--   │  │         │  │         │  │         │
--   └─▶│ Consul  │──│ Consul  │──│ Consul  │
--      │         │  │         │  │         │
--      └─────────┘  └─────────┘  └─────────┘
--   </pre>
module Network.Wai.Middleware.Consul

-- | Consul Settings for watching &amp; proxying Consul data
data ConsulSettings
defaultConsulSettings :: ConsulSettings
getConsulCallback :: ConsulSettings -> ConsulCallback
getConsulFilter :: ConsulSettings -> Request -> Bool
getConsulHost :: ConsulSettings -> Text
getConsulKey :: ConsulSettings -> Text
getConsulLimit :: ConsulSettings -> Maybe Int
getConsulPort :: ConsulSettings -> PortNumber

-- | Create WAI middleware that can be used to proxy incoming data into
--   Consul (one-way). This function initiates our consul client and
--   returns the middleware for WAI to use. The middleware will filter
--   incoming requests that match ConsulSettings csFilter. If there is a
--   match it will create a make the key value put call for Consul using
--   the incoming request body as the data for the Consul K/V.
mkConsulProxy :: (MonadIO m, Functor m) => ConsulSettings -> m Middleware

-- | Creates a background process to receive notifications. Notifications
--   happen via blocking HTTP request. (The HTTP client manager used has
--   been configured to wait forever for a response.) The ConsulSettings
--   (csHost, csPort &amp; csKey) are used to connect to Consul and watch
--   for key-value changes. When Consul's value changes, it will respond to
--   the HTTP request. Upon receiving a good changed-value response, we
--   fire the csCallback function to allow for a reaction to the data
--   change. If there there is a problem with the request/response cycle or
--   an exception in the supplied callback function, we just re-make the
--   rquest &amp; wait patiently for changes again.
mkConsulWatch :: (MonadBaseControl IO m, MonadLoggerIO m) => ConsulSettings -> m Void
setConsulCallback :: ConsulCallback -> ConsulSettings -> ConsulSettings
setConsulFilter :: (Request -> Bool) -> ConsulSettings -> ConsulSettings
setConsulHost :: Text -> ConsulSettings -> ConsulSettings
setConsulKey :: Text -> ConsulSettings -> ConsulSettings
setConsulLimit :: Maybe Int -> ConsulSettings -> ConsulSettings
setConsulPort :: PortNumber -> ConsulSettings -> ConsulSettings

-- | Creates a complete Consul middleware for the cluster. Combines
--   mkConsulWatch async function (watches Consul data for updates) &amp;
--   mkConsulProxy (proxys data from the internet to Consul) into one
--   common-use function. This will probably be the function you want. See
--   the example/ application for more insight.
withConsul :: (Monad m, MonadBaseControl IO m, MonadLoggerIO m) => ConsulSettings -> (Middleware -> m a) -> m a


-- | This module contains specific configuration for using WAI Middleware
--   for Consul with Github. We can configure a GitHub Webhook to POST to
--   consul middleware. Consul middleware will push the GitHub webhook
--   payload to Consul. Consul will let every WAI application know of the
--   data update &amp; each application will execute `git pull` to update
--   their git repository contents.
--   
--   <pre>
--         ┌─────────┐      ┌─────────┐
--         │ Github  │      │         │
--         │  Repo   │─────▶│ AWS ELB │
--         │ Webhook │      │         │
--         └─────────┘      └─────────┘
--                               │
--           ┌────────────┬──────┘─ ─ ─
--           │                         │
--           ▼            ▼            ▼
--      ┌─────────┐  ┌─────────┐  ┌─────────┐
--      │         │  │         │  │         │
--   ┌──│ WAI App │  │ WAI App │  │ WAI App │
--   │  │         │  │         │  │         │
--   │  └─────────┘  └─────────┘  └─────────┘
--   │                    ▲            ▲
--   │                    │            │
--   │       ┌────────────┴────────────┘
--   │       │
--   │       │
--   │  ┌─────────┐  ┌─────────┐  ┌─────────┐
--   │  │         │  │         │  │         │
--   └─▶│ Consul  │──│ Consul  │──│ Consul  │
--      │         │  │         │  │         │
--      └─────────┘  └─────────┘  └─────────┘
--   </pre>
module Network.Wai.Middleware.Consul.GitHub

-- | GitHub Webhook handler with Consul callback that does a `git pull`
--   when fired.
gitHubPullOnWebhook :: ConsulSettings
