duct

scaturr 2020-09-15T12:58:49.048300Z

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.

jntn 2020-09-15T13:02:42.050100Z

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?

jntn 2020-09-15T13:03:42.051200Z

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

πŸ’― 1
scaturr 2020-09-15T13:11:01.051300Z

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

scaturr 2020-09-15T13:11:23.051500Z

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}}

scaturr 2020-09-15T13:11:59.051700Z

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

scaturr 2020-09-15T13:12:31.051900Z

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

scaturr 2020-09-15T13:12:56.052100Z

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

scaturr 2020-09-15T13:13:20.052300Z

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

scaturr 2020-09-15T13:13:41.052500Z

(I believe this should work)

jntn 2020-09-15T13:16:19.052700Z

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

jntn 2020-09-15T13:17:24.053Z

Have you implemented :protected with buddy?

scaturr 2020-09-15T13:22:56.053200Z

No problem! I have not

walterl 2020-09-15T13:39:53.053400Z

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}}

scaturr 2020-09-15T13:46:50.053700Z

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

scaturr 2020-09-15T13:46:51.053900Z

https://github.com/duct-framework/core#modules

scaturr 2020-09-15T13:47:15.054200Z

(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
scaturr 2020-09-15T13:47:21.054400Z

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

scaturr 2020-09-15T13:47:26.054600Z

Thank you for the help πŸ™‡