Liking cljdoc? Tell your friends :D

ring-audit-middleware

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, send a message to a queue, send an email...

Compojure example

(ns foo.bar
  (:use compojure.core
        [ring.audit.middleware.core :only [wrap-audit-middleware]])
  (:require [compojure.handler :as handler]
            [compojure.route :as route]))

(defroutes foo-app
  (GET "/foo/bar/:id" ...)
  (POST "/admin/:id/edit" ...)
  (POST "/users" ...))

The audit fn

Must accept two arguments, the ring request map and map of request parameters from clout (see clout documentation)

(defn audit-fn [req params] ... )

Options for wrap-audit-middleware

Audit all routes


(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/*"])))

Instruct the middleware to audit routes in a future (useful for long running audits)


(def app
  (-> (handler/site foo-app)
      (wrap-audit-middleware audit-fn :future true)))

Why not both?


(def app
  (-> (handler/site foo-app)
      (wrap-audit-middleware audit-fn :routes ["/admin/:id/*"] :future true)))

License

Copyright (C) 2013 Kyle Gann

Distributed under the Eclipse Public License, the same as Clojure.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close