duct 2020-09-15

Is there some convention for replacing a single value in an existing config key? I am running into an issue with duct/module.sql and not being able to specify the maximum pool size. I thought I might be able to do something to the :duct.database.sql/hikaricp key that is included via the module, but it seems to just over write it.

Haven't used module.sql, but the configs should get merged during prep, no? From my understanding of the docs I would try {:duct.database.sql/hikaricp {:maximum-pool-size 5}}

That is what I tried, and it seemed to replace the config completely. I was able to solve this by creating a module that extends the sql module with this value

(ns duct.module.pool-size
  (:require [integrant.core :as ig]))

(derive ::hikaricp :duct/module)

(defmethod ig/init-key ::hikaricp [_ {:keys [maximum-pool-size]}]
  (fn [config]
    (assoc-in config [:duct.database.sql/hikaricp :maximum-pool-size] maximum-pool-size)))

(defmethod ig/prep-key ::hikaricp [_ options]
  (assoc options ::requires (ig/ref :duct.module/sql)))

πŸ‘ 1

perhaps a little too bespoke, but it works πŸ™‚

Thank you for the help πŸ™‡

Hey! I am trying to get buddy auth to work with Duct, but have trouble understanding how to make it work. I am looking at this issue: https://github.com/duct-framework/module.ataraxy/issues/4, but can’t grok what weavejester is suggesting. What would a complete config look like if you follow what he is saying?

Your config should have a key for :duct.middleware.buddy/authorization . There may be multiple ways to do this, but I have been configuring these at the router and root handler

For example, my router config looks like this:

;; Routes
  :duct.router/ataraxy
  {:routes
   {[:post "/login"]     [:web.handler/login]
    [:post "/authorize"] [:web.handler/authorize]
    [:post "/slash"]     ^:slack [:web.handler/slash]
    [:post "/action"]    ^:slack [:web.handler/action]
    [:post "/message"]   ^:protected [:web.handler/message]
    [:get "/info"]       [:web.handler/info]}
   :middleware {:slack #ig/ref :web.middleware/slack
                :protected #ig/ref :web.middleware/protected}}

notice how the keys in :middleware are repurposed as meta for the individual routes

And if you need global middleware, you should be able to apply those to :duct.handler/root

:duct.handler/root
  {:middleware [#ig/ref :web.middleware/cors]}

in your case that should be #ig/ref :duct.middleware.buddy/authentication

(I believe this should work)

Thank you for explaining with a great example! Will try it out

Have you implemented :protected with buddy?

No problem! I have not

As a newcomer it is generally hard to find complete examples of how stuff works πŸ˜…

πŸ’― 1