; Copyright © 2015, JUXT LTD.

(ns yada.walk
  (:require
   [clojure.walk :refer [postwalk]])
  (:import [yada.handler Handler]
           [yada.resource Resource]))

;; Functions to update inner routes

(defn update-routes [routes f & args]
  (postwalk
   (fn [x]
     (if (or
          (instance? Handler x)
          (instance? Resource x))
       (apply f x args)
       x))
   routes))

(defn merge-options [m routes]
  (update-routes routes
                 (fn [{:keys [handler args]}]
                   (merge handler m))))

(defn basic-auth [realm auth-fn routes]
  (merge-options
   {:security {:type :basic :realm realm}
    :authorization auth-fn}
   routes))

; Copyright © 2015, JUXT LTD.

(ns yada.walk
  (:require
   [clojure.walk :refer [postwalk]])
  (:import [yada.handler Handler]
           [yada.resource Resource]))

;; Functions to update inner routes

(defn update-routes [routes f & args]
  (postwalk
   (fn [x]
     (if (or
          (instance? Handler x)
          (instance? Resource x))
       (apply f x args)
       x))
   routes))

(defn merge-options [m routes]
  (update-routes routes
                 (fn [{:keys [handler args]}]
                   (merge handler m))))

#_(defn basic-auth [routes realm authn-fn authorization ]
  (merge-options
   {:access-control
    {realm {:authentication-schemes
            [{:scheme "Basic"
              :verify authn-fn}]
            :authorization {:methods {:get "secret/view"}}}}}
   routes))

Comment out basic auth - no need for fn here
Comment out basic auth - no need for fn here

mbutlerw/yada,mbutlerw/yada,mbutlerw/yada,juxt/yada,delitescere/yada,delitescere/yada,delitescere/yada,juxt/yada,juxt/yada