Fork me on GitHub
#duct
<
2020-09-15
>
scaturr12:09:49

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.

walterl13:09:53

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

scaturr13:09:50

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

scaturr13:09:15

(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)))

πŸ‘ 3
scaturr13:09:21

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

scaturr13:09:26

Thank you for the help πŸ™‡

jntn13:09:42

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?

scaturr13:09:01

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

scaturr13:09:23

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

scaturr13:09:59

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

scaturr13:09:31

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

scaturr13:09:56

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

scaturr13:09:20

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

scaturr13:09:41

(I believe this should work)

jntn13:09:19

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

jntn13:09:24

Have you implemented :protected with buddy?

scaturr13:09:56

No problem! I have not

jntn13:09:42

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

πŸ’― 3