Ring middleware to facilitate audit requirements.
Makes use of clout to match routes and execute an fn
of your choice!
Have it write to a db, place a message on a queue, send an email...
[ring-audit-middleware "0.1.0"]
(ns foo.bar
(:use compojure.core
ring.audit.middleware.core)
(:require [compojure.handler :as handler]
[compojure.route :as route]))
(defroutes foo-app
(GET "/foo/bar/:id" ...)
(POST "/admin/:id/edit" ...)
(POST "/users" ...))
(defn audit-fn [req params] ... )
(def app
(-> (handler/site foo-app)
(wrap-audit-middleware audit-fn)))
Must accept two arguments
- ring request map
- request parameters from clout (see clout documentation)
Note - the audit fn
is for side-effects only. If the request map is modified, it will not be persisted through the remaining middleware stack
(defn audit-fn [req params] ... )
(def app
(-> (handler/site foo-app)
(wrap-audit-middleware audit-fn)))
Provide a collection of routes (see clout documentation) to determine if the request should be audited
(def app
(-> (handler/site foo-app) ;; audit all admin member routes and all user routes
(wrap-audit-middleware audit-fn :routes ["/admin/:id/*" "/users/*"])))
(def app
(-> (handler/site foo-app)
(wrap-audit-middleware audit-fn :future? true)))
(def app
(-> (handler/site foo-app)
(wrap-audit-middleware audit-fn :routes ["/admin/:id/*"] :future? true)))
(def app
(-> (handler/site foo-app)
(wrap-audit-middleware some-fn-for-admin-routes :routes ["/admin/:id/*"])
(wrap-audit-middleware some-fn-for-user-routes :routes ["/user/*"] :future? true)))
Right now, all audit fn
's are executed for their side-effects and they can not modify the request map
- allow for request map modification as well as side-effects (middleware could handle authentication)
Copyright (C) 2013 Kyle Gann
Distributed under the Eclipse Public License, the same as Clojure.