Fork me on GitHub
#pedestal
<
2016-10-24
>
crimeminister18:10:04

Hi folks, does anyone have an example of a trivial or small Pedestal app using component?

crimeminister20:10:46

Excuse me while I wipe the egg off my face…

mtnygard20:10:54

Hope it helps.

crimeminister20:10:54

Much appreciated

hagmonk21:10:34

I'm going a bit mad here with pedestal, I must be doing something wrong

mtnygard21:10:09

You just caught me before heading out the door. Whatcha got?

hagmonk21:10:16

Caused by: java.lang.IllegalArgumentException: No matching ctor found for class io.pedestal.interceptor.helpers$before$fn__23165

hagmonk21:10:22

I'll try to be quick :)(

hagmonk21:10:40

thrown when I tried to start a debug repl in IntelliJ

hagmonk21:10:50

it's making me wonder if I've deviated from some normal way the pedestal namespaces are imported

mtnygard21:10:32

Hmm... it doesn't look like a require problem. It looks like what happens when a macro emits a function value.

mtnygard21:10:48

Are you wrapping anything with macros? Or syntax-quoting your routes, maybe?

hagmonk21:10:42

No I tried to steer away from the syntax quoting approach

hagmonk21:10:58

(defroutes
  routes
  [[["/__health" {:get health}]
    ["/api"
     ^:interceptors [auth/configure-authentication auth/check-authentication]
     ["/test" {:get echo}]
     ["/keyword-demo" {:get keyword-demo-route}]]]])

mtnygard21:10:17

That seems OK at first glance.

mtnygard21:10:27

Can you paste in the code where you're calling defbefore?

hagmonk21:10:17

This is all WIP code so forgive weirdness

hagmonk21:10:23

(defbefore
  check-authentication
  [{:keys [request auth-backends] :as context}]
  (let [req (apply authentication-request request auth-backends)]
    (if (:identity req)
      (assoc context :request req)
      (-> context
          terminate
          (assoc :response {:status 401
                            :body {:message "Unauthorized"}
                            :headers {"WWW-Authenticate" (format "Basic realm=\"%s\"" "Blip")}})))))

hagmonk21:10:05

basically I'm wiring up buddy-sign to do JWT authentication with a fallback to LDAP

mtnygard21:10:17

And if you comment that out, can you load the namespace?

hagmonk21:10:40

I bet so, but let me confirm

hagmonk21:10:18

Yep if I commented out those defbefores it started working. What's weird is that they were working in regular REPL, when I switched to debug REPL that's when they started barfing

mtnygard21:10:58

My advice would be to rework it from using defbefore. Hang on one minute and I'll show you an example.

hagmonk21:10:45

Yah! I wanted to use plain data structures but kept barking my shins on those too 🙂

mtnygard21:10:22

(def check-authentication
  {::check-authentication
   :enter
   (fn [{:keys [request auth-backends] :as context}]
     (let [req (apply authentication-request request auth-backends)]
       (if (:identity req)
         (assoc context :request req)
         (-> context
            terminate
            (assoc :response {:status 401
                            :body {:message "Unauthorized"}
                            :headers {"WWW-Authenticate" (format "Basic realm=\"%s\"" "Blip")}}
)))))})

mtnygard21:10:40

I'm not 100% sure I got the close parens right. I don't have a repl up right now.

mtnygard21:10:59

This actually removes 2 layers of wrapped macros.

hagmonk21:10:25

well, I will continue poking at this and let you get out that door 🙂 super helpful, thanks so much

mtnygard21:10:44

yw. If you still have trouble, send me a direct message and I'll look at it later on.