Improve internal naming of setup/props

This reverts commit a6f70c77cb.
This commit is contained in:
Andrey Antukh 2024-03-14 10:29:21 +01:00
parent 75d0648065
commit 91118bec70
19 changed files with 77 additions and 63 deletions

View file

@ -22,6 +22,7 @@
[app.loggers.audit :as audit] [app.loggers.audit :as audit]
[app.main :as-alias main] [app.main :as-alias main]
[app.rpc.commands.profile :as profile] [app.rpc.commands.profile :as profile]
[app.setup :as-alias setup]
[app.tokens :as tokens] [app.tokens :as tokens]
[app.util.json :as json] [app.util.json :as json]
[app.util.time :as dt] [app.util.time :as dt]
@ -413,7 +414,7 @@
::props])) ::props]))
(defn get-info (defn get-info
[{:keys [provider ::main/props] :as cfg} {:keys [params] :as request}] [{:keys [provider ::setup/props] :as cfg} {:keys [params] :as request}]
(when-let [error (get params :error)] (when-let [error (get params :error)]
(ex/raise :type :internal (ex/raise :type :internal
:code :error-on-retrieving-code :code :error-on-retrieving-code
@ -508,7 +509,7 @@
(if profile (if profile
(let [sxf (session/create-fn cfg (:id profile)) (let [sxf (session/create-fn cfg (:id profile))
token (or (:invitation-token info) token (or (:invitation-token info)
(tokens/generate (::main/props cfg) (tokens/generate (::setup/props cfg)
{:iss :auth {:iss :auth
:exp (dt/in-future "15m") :exp (dt/in-future "15m")
:profile-id (:id profile)})) :profile-id (:id profile)}))
@ -536,7 +537,7 @@
:iss :prepared-register :iss :prepared-register
:is-active true :is-active true
:exp (dt/in-future {:hours 48})) :exp (dt/in-future {:hours 48}))
token (tokens/generate (::main/props cfg) info) token (tokens/generate (::setup/props cfg) info)
params (d/without-nils params (d/without-nils
{:token token {:token token
:fullname (:fullname info)}) :fullname (:fullname info)})
@ -551,7 +552,7 @@
(defn- auth-handler (defn- auth-handler
[cfg {:keys [params] :as request}] [cfg {:keys [params] :as request}]
(let [props (audit/extract-utm-params params) (let [props (audit/extract-utm-params params)
state (tokens/generate (::main/props cfg) state (tokens/generate (::setup/props cfg)
{:iss :oauth {:iss :oauth
:invitation-token (:invitation-token params) :invitation-token (:invitation-token params)
:props props :props props
@ -618,7 +619,7 @@
[_] [_]
(s/keys :req [::session/manager (s/keys :req [::session/manager
::http/client ::http/client
::main/props ::setup/props
::db/pool ::db/pool
::providers])) ::providers]))

View file

@ -23,6 +23,7 @@
[app.metrics :as mtx] [app.metrics :as mtx]
[app.rpc :as-alias rpc] [app.rpc :as-alias rpc]
[app.rpc.doc :as-alias rpc.doc] [app.rpc.doc :as-alias rpc.doc]
[app.setup :as-alias setup]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[integrant.core :as ig] [integrant.core :as ig]
[promesa.exec :as px] [promesa.exec :as px]
@ -136,7 +137,7 @@
::rpc/routes ::rpc/routes
::rpc.doc/routes ::rpc.doc/routes
::oidc/routes ::oidc/routes
::main/props ::setup/props
::assets/routes ::assets/routes
::debug/routes ::debug/routes
::db/pool ::db/pool

View file

@ -10,6 +10,7 @@
[app.config :as cf] [app.config :as cf]
[app.db :as db] [app.db :as db]
[app.main :as-alias main] [app.main :as-alias main]
[app.setup :as-alias setup]
[app.tokens :as tokens] [app.tokens :as tokens]
[ring.request :as rreq])) [ring.request :as rreq]))
@ -42,7 +43,7 @@
(defn- wrap-soft-auth (defn- wrap-soft-auth
"Soft Authentication, will be executed synchronously on the undertow "Soft Authentication, will be executed synchronously on the undertow
worker thread." worker thread."
[handler {:keys [::main/props]}] [handler {:keys [::setup/props]}]
(letfn [(handle-request [request] (letfn [(handle-request [request]
(try (try
(let [token (get-token request) (let [token (get-token request)

View file

@ -13,6 +13,7 @@
[app.db.sql :as sql] [app.db.sql :as sql]
[app.http.client :as http] [app.http.client :as http]
[app.main :as-alias main] [app.main :as-alias main]
[app.setup :as-alias setup]
[app.tokens :as tokens] [app.tokens :as tokens]
[app.worker :as-alias wrk] [app.worker :as-alias wrk]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
@ -30,7 +31,7 @@
(defmethod ig/pre-init-spec ::routes [_] (defmethod ig/pre-init-spec ::routes [_]
(s/keys :req [::http/client (s/keys :req [::http/client
::main/props ::setup/props
::db/pool])) ::db/pool]))
(defmethod ig/init-key ::routes (defmethod ig/init-key ::routes
@ -106,7 +107,7 @@
[cfg headers] [cfg headers]
(let [tdata (get headers "x-penpot-data")] (let [tdata (get headers "x-penpot-data")]
(when-not (str/empty? tdata) (when-not (str/empty? tdata)
(let [result (tokens/verify (::main/props cfg) {:token tdata :iss :profile-identity})] (let [result (tokens/verify (::setup/props cfg) {:token tdata :iss :profile-identity})]
(:profile-id result))))) (:profile-id result)))))
(defn- parse-notification (defn- parse-notification

View file

@ -55,8 +55,8 @@
convention." convention."
([cfg-or-client request] ([cfg-or-client request]
(let [client (resolve-client cfg-or-client)] (let [client (resolve-client cfg-or-client)]
(send! client request {}))) (send! client request {:sync? true})))
([cfg-or-client request options] ([cfg-or-client request options]
(let [client (resolve-client cfg-or-client)] (let [client (resolve-client cfg-or-client)]
(send! client request options)))) (send! client request (merge {:sync? true} options)))))

View file

@ -20,6 +20,7 @@
[app.rpc.commands.auth :as auth] [app.rpc.commands.auth :as auth]
[app.rpc.commands.files-create :refer [create-file]] [app.rpc.commands.files-create :refer [create-file]]
[app.rpc.commands.profile :as profile] [app.rpc.commands.profile :as profile]
[app.setup :as-alias setup]
[app.srepl.helpers :as srepl] [app.srepl.helpers :as srepl]
[app.storage :as-alias sto] [app.storage :as-alias sto]
[app.storage.tmp :as tmp] [app.storage.tmp :as tmp]
@ -340,7 +341,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- resend-email-notification (defn- resend-email-notification
[{:keys [::db/pool ::main/props] :as cfg} {:keys [params] :as request}] [{:keys [::db/pool ::setup/props] :as cfg} {:keys [params] :as request}]
(when-not (contains? params :force) (when-not (contains? params :force)
(ex/raise :type :validation (ex/raise :type :validation

View file

@ -15,6 +15,7 @@
[app.db.sql :as sql] [app.db.sql :as sql]
[app.http.session.tasks :as-alias tasks] [app.http.session.tasks :as-alias tasks]
[app.main :as-alias main] [app.main :as-alias main]
[app.setup :as-alias setup]
[app.tokens :as tokens] [app.tokens :as tokens]
[app.util.time :as dt] [app.util.time :as dt]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
@ -138,7 +139,7 @@
(declare ^:private gen-token) (declare ^:private gen-token)
(defn create-fn (defn create-fn
[{:keys [::manager ::main/props]} profile-id] [{:keys [::manager ::setup/props]} profile-id]
(us/assert! ::manager manager) (us/assert! ::manager manager)
(us/assert! ::us/uuid profile-id) (us/assert! ::us/uuid profile-id)
@ -196,7 +197,7 @@
(neg? (compare default-renewal-max-age elapsed))))) (neg? (compare default-renewal-max-age elapsed)))))
(defn- wrap-soft-auth (defn- wrap-soft-auth
[handler {:keys [::manager ::main/props]}] [handler {:keys [::manager ::setup/props]}]
(us/assert! ::manager manager) (us/assert! ::manager manager)
(letfn [(handle-request [request] (letfn [(handle-request [request]
(try (try

View file

@ -24,6 +24,7 @@
[app.main :as-alias main] [app.main :as-alias main]
[app.rpc :as-alias rpc] [app.rpc :as-alias rpc]
[app.rpc.retry :as rtry] [app.rpc.retry :as rtry]
[app.setup :as-alias setup]
[app.tokens :as tokens] [app.tokens :as tokens]
[app.util.services :as-alias sv] [app.util.services :as-alias sv]
[app.util.time :as dt] [app.util.time :as dt]
@ -261,7 +262,7 @@
(s/def ::tasks/uri ::us/string) (s/def ::tasks/uri ::us/string)
(defmethod ig/pre-init-spec ::tasks/archive-task [_] (defmethod ig/pre-init-spec ::tasks/archive-task [_]
(s/keys :req [::db/pool ::main/props ::http.client/client])) (s/keys :req [::db/pool ::setup/props ::http.client/client]))
(defmethod ig/init-key ::tasks/archive (defmethod ig/init-key ::tasks/archive
[_ cfg] [_ cfg]
@ -287,7 +288,7 @@
(px/sleep 100) (px/sleep 100)
(recur (+ total ^long n))) (recur (+ total ^long n)))
(when (pos? total) (when (pos? total)
(l/debug :hint "events archived" :total total))))))))) (l/dbg :hint "events archived" :total total)))))))))
(def ^:private sql:retrieve-batch-of-audit-log (def ^:private sql:retrieve-batch-of-audit-log
"select * "select *
@ -322,7 +323,7 @@
:context])) :context]))
(send [events] (send [events]
(let [token (tokens/generate (::main/props cfg) (let [token (tokens/generate (::setup/props cfg)
{:iss "authentication" {:iss "authentication"
:iat (dt/now) :iat (dt/now)
:uid uuid/zero}) :uid uuid/zero})
@ -331,11 +332,11 @@
"origin" (cf/get :public-uri) "origin" (cf/get :public-uri)
"cookie" (u/map->query-string {:auth-token token})} "cookie" (u/map->query-string {:auth-token token})}
params {:uri uri params {:uri uri
:timeout 6000 :timeout 12000
:method :post :method :post
:headers headers :headers headers
:body body} :body body}
resp (http.client/req! cfg params {:sync? true})] resp (http.client/req! cfg params)]
(if (= (:status resp) 204) (if (= (:status resp) 204)
true true
(do (do
@ -355,7 +356,7 @@
(map row->event)) (map row->event))
events (into [] xform rows)] events (into [] xform rows)]
(when-not (empty? events) (when-not (empty? events)
(l/trace :hint "archive events chunk" :uri uri :events (count events)) (l/trc :hint "archive events chunk" :uri uri :events (count events))
(when (send events) (when (send events)
(mark-as-archived conn rows) (mark-as-archived conn rows)
(count events))))))) (count events)))))))

View file

@ -221,7 +221,7 @@
{::db/pool (ig/ref ::db/pool)} {::db/pool (ig/ref ::db/pool)}
::http.awsns/routes ::http.awsns/routes
{::props (ig/ref ::setup/props) {::setup/props (ig/ref ::setup/props)
::db/pool (ig/ref ::db/pool) ::db/pool (ig/ref ::db/pool)
::http.client/client (ig/ref ::http.client/client)} ::http.client/client (ig/ref ::http.client/client)}
@ -262,7 +262,7 @@
::oidc/routes ::oidc/routes
{::http.client/client (ig/ref ::http.client/client) {::http.client/client (ig/ref ::http.client/client)
::db/pool (ig/ref ::db/pool) ::db/pool (ig/ref ::db/pool)
::props (ig/ref ::setup/props) ::setup/props (ig/ref ::setup/props)
::oidc/providers {:google (ig/ref ::oidc.providers/google) ::oidc/providers {:google (ig/ref ::oidc.providers/google)
:github (ig/ref ::oidc.providers/github) :github (ig/ref ::oidc.providers/github)
:gitlab (ig/ref ::oidc.providers/gitlab) :gitlab (ig/ref ::oidc.providers/gitlab)
@ -274,7 +274,7 @@
::db/pool (ig/ref ::db/pool) ::db/pool (ig/ref ::db/pool)
::rpc/routes (ig/ref ::rpc/routes) ::rpc/routes (ig/ref ::rpc/routes)
::rpc.doc/routes (ig/ref ::rpc.doc/routes) ::rpc.doc/routes (ig/ref ::rpc.doc/routes)
::props (ig/ref ::setup/props) ::setup/props (ig/ref ::setup/props)
::mtx/routes (ig/ref ::mtx/routes) ::mtx/routes (ig/ref ::mtx/routes)
::oidc/routes (ig/ref ::oidc/routes) ::oidc/routes (ig/ref ::oidc/routes)
::http.debug/routes (ig/ref ::http.debug/routes) ::http.debug/routes (ig/ref ::http.debug/routes)
@ -286,7 +286,7 @@
{::db/pool (ig/ref ::db/pool) {::db/pool (ig/ref ::db/pool)
::session/manager (ig/ref ::session/manager) ::session/manager (ig/ref ::session/manager)
::sto/storage (ig/ref ::sto/storage) ::sto/storage (ig/ref ::sto/storage)
::props (ig/ref ::setup/props)} ::setup/props (ig/ref ::setup/props)}
::http.ws/routes ::http.ws/routes
{::db/pool (ig/ref ::db/pool) {::db/pool (ig/ref ::db/pool)
@ -322,7 +322,7 @@
::rpc/climit (ig/ref ::rpc/climit) ::rpc/climit (ig/ref ::rpc/climit)
::rpc/rlimit (ig/ref ::rpc/rlimit) ::rpc/rlimit (ig/ref ::rpc/rlimit)
::setup/templates (ig/ref ::setup/templates) ::setup/templates (ig/ref ::setup/templates)
::props (ig/ref ::setup/props)} ::setup/props (ig/ref ::setup/props)}
:app.rpc.doc/routes :app.rpc.doc/routes
{:methods (ig/ref :app.rpc/methods)} {:methods (ig/ref :app.rpc/methods)}
@ -331,7 +331,7 @@
{::rpc/methods (ig/ref :app.rpc/methods) {::rpc/methods (ig/ref :app.rpc/methods)
::db/pool (ig/ref ::db/pool) ::db/pool (ig/ref ::db/pool)
::session/manager (ig/ref ::session/manager) ::session/manager (ig/ref ::session/manager)
::props (ig/ref ::setup/props)} ::setup/props (ig/ref ::setup/props)}
::wrk/registry ::wrk/registry
{::mtx/metrics (ig/ref ::mtx/metrics) {::mtx/metrics (ig/ref ::mtx/metrics)
@ -388,7 +388,7 @@
:app.tasks.telemetry/handler :app.tasks.telemetry/handler
{::db/pool (ig/ref ::db/pool) {::db/pool (ig/ref ::db/pool)
::http.client/client (ig/ref ::http.client/client) ::http.client/client (ig/ref ::http.client/client)
::props (ig/ref ::setup/props)} ::setup/props (ig/ref ::setup/props)}
[::srepl/urepl ::srepl/server] [::srepl/urepl ::srepl/server]
{::srepl/port (cf/get :urepl-port 6062) {::srepl/port (cf/get :urepl-port 6062)
@ -402,7 +402,7 @@
::setup/props ::setup/props
{::db/pool (ig/ref ::db/pool) {::db/pool (ig/ref ::db/pool)
::key (cf/get :secret-key) ::setup/key (cf/get :secret-key)
;; NOTE: this dependency is only necessary for proper initialization ordering, props ;; NOTE: this dependency is only necessary for proper initialization ordering, props
;; module requires the migrations to run before initialize. ;; module requires the migrations to run before initialize.
@ -412,7 +412,7 @@
{} {}
::audit.tasks/archive ::audit.tasks/archive
{::props (ig/ref ::setup/props) {::setup/props (ig/ref ::setup/props)
::db/pool (ig/ref ::db/pool) ::db/pool (ig/ref ::db/pool)
::http.client/client (ig/ref ::http.client/client)} ::http.client/client (ig/ref ::http.client/client)}

View file

@ -27,6 +27,7 @@
[app.rpc.helpers :as rph] [app.rpc.helpers :as rph]
[app.rpc.retry :as retry] [app.rpc.retry :as retry]
[app.rpc.rlimit :as rlimit] [app.rpc.rlimit :as rlimit]
[app.setup :as-alias setup]
[app.storage :as-alias sto] [app.storage :as-alias sto]
[app.util.services :as sv] [app.util.services :as sv]
[app.util.time :as dt] [app.util.time :as dt]
@ -248,7 +249,7 @@
::ldap/provider ::ldap/provider
::sto/storage ::sto/storage
::mtx/metrics ::mtx/metrics
::main/props] ::setup/props]
:opt [::climit :opt [::climit
::rlimit])) ::rlimit]))
@ -265,7 +266,7 @@
(defmethod ig/pre-init-spec ::routes [_] (defmethod ig/pre-init-spec ::routes [_]
(s/keys :req [::methods (s/keys :req [::methods
::db/pool ::db/pool
::main/props ::setup/props
::session/manager])) ::session/manager]))
(defmethod ig/init-key ::routes (defmethod ig/init-key ::routes

View file

@ -13,6 +13,7 @@
[app.rpc :as-alias rpc] [app.rpc :as-alias rpc]
[app.rpc.doc :as-alias doc] [app.rpc.doc :as-alias doc]
[app.rpc.quotes :as quotes] [app.rpc.quotes :as quotes]
[app.setup :as-alias setup]
[app.tokens :as tokens] [app.tokens :as tokens]
[app.util.services :as sv] [app.util.services :as sv]
[app.util.time :as dt] [app.util.time :as dt]
@ -23,7 +24,7 @@
(dissoc row :perms)) (dissoc row :perms))
(defn create-access-token (defn create-access-token
[{:keys [::db/conn ::main/props]} profile-id name expiration] [{:keys [::db/conn ::setup/props]} profile-id name expiration]
(let [created-at (dt/now) (let [created-at (dt/now)
token-id (uuid/next) token-id (uuid/next)
token (tokens/generate props {:iss "access-token" token (tokens/generate props {:iss "access-token"
@ -47,7 +48,7 @@
[{:keys [::db/pool] :as system} profile-id name expiration] [{:keys [::db/pool] :as system} profile-id name expiration]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(let [props (:app.setup/props system)] (let [props (:app.setup/props system)]
(create-access-token {::db/conn conn ::main/props props} (create-access-token {::db/conn conn ::setup/props props}
profile-id profile-id
name name
expiration)))) expiration))))

View file

@ -26,6 +26,7 @@
[app.rpc.commands.teams :as teams] [app.rpc.commands.teams :as teams]
[app.rpc.doc :as-alias doc] [app.rpc.doc :as-alias doc]
[app.rpc.helpers :as rph] [app.rpc.helpers :as rph]
[app.setup :as-alias setup]
[app.tokens :as tokens] [app.tokens :as tokens]
[app.util.services :as sv] [app.util.services :as sv]
[app.util.time :as dt] [app.util.time :as dt]
@ -88,7 +89,7 @@
(profile/strip-private-attrs)) (profile/strip-private-attrs))
invitation (when-let [token (:invitation-token params)] invitation (when-let [token (:invitation-token params)]
(tokens/verify (::main/props cfg) {:token token :iss :team-invitation})) (tokens/verify (::setup/props cfg) {:token token :iss :team-invitation}))
;; If invitation member-id does not matches the profile-id, we just proceed to ignore the ;; If invitation member-id does not matches the profile-id, we just proceed to ignore the
;; invitation because invitations matches exactly; and user can't login with other email and ;; invitation because invitations matches exactly; and user can't login with other email and
@ -133,7 +134,7 @@
(defn recover-profile (defn recover-profile
[{:keys [::db/pool] :as cfg} {:keys [token password]}] [{:keys [::db/pool] :as cfg} {:keys [token password]}]
(letfn [(validate-token [token] (letfn [(validate-token [token]
(let [tdata (tokens/verify (::main/props cfg) {:token token :iss :password-recovery})] (let [tdata (tokens/verify (::setup/props cfg) {:token token :iss :password-recovery})]
(:profile-id tdata))) (:profile-id tdata)))
(update-password [conn profile-id] (update-password [conn profile-id]
@ -170,7 +171,7 @@
:code :registration-disabled))) :code :registration-disabled)))
(when (contains? params :invitation-token) (when (contains? params :invitation-token)
(let [invitation (tokens/verify (::main/props cfg) {:token (:invitation-token params) :iss :team-invitation})] (let [invitation (tokens/verify (::setup/props cfg) {:token (:invitation-token params) :iss :team-invitation})]
(when-not (= (:email params) (:member-email invitation)) (when-not (= (:email params) (:member-email invitation))
(ex/raise :type :restriction (ex/raise :type :restriction
:code :email-does-not-match-invitation :code :email-does-not-match-invitation
@ -233,7 +234,7 @@
params (d/without-nils params) params (d/without-nils params)
token (tokens/generate (::main/props cfg) params)] token (tokens/generate (::setup/props cfg) params)]
(with-meta {:token token} (with-meta {:token token}
{::audit/profile-id uuid/zero}))) {::audit/profile-id uuid/zero})))
@ -340,7 +341,7 @@
(defn register-profile (defn register-profile
[{:keys [::db/conn] :as cfg} {:keys [token fullname] :as params}] [{:keys [::db/conn] :as cfg} {:keys [token fullname] :as params}]
(let [claims (tokens/verify (::main/props cfg) {:token token :iss :prepared-register}) (let [claims (tokens/verify (::setup/props cfg) {:token token :iss :prepared-register})
params (-> claims params (-> claims
(into params) (into params)
(assoc :fullname fullname)) (assoc :fullname fullname))
@ -357,7 +358,7 @@
(create-profile-rels! conn)))) (create-profile-rels! conn))))
invitation (when-let [token (:invitation-token params)] invitation (when-let [token (:invitation-token params)]
(tokens/verify (::main/props cfg) {:token token :iss :team-invitation}))] (tokens/verify (::setup/props cfg) {:token token :iss :team-invitation}))]
;; If profile is filled in claims, means it tries to register ;; If profile is filled in claims, means it tries to register
;; again, so we proceed to update the modified-at attr ;; again, so we proceed to update the modified-at attr
@ -377,7 +378,7 @@
;; email. ;; email.
(and (some? invitation) (= (:email profile) (:member-email invitation))) (and (some? invitation) (= (:email profile) (:member-email invitation)))
(let [claims (assoc invitation :member-id (:id profile)) (let [claims (assoc invitation :member-id (:id profile))
token (tokens/generate (::main/props cfg) claims) token (tokens/generate (::setup/props cfg) claims)
resp {:invitation-token token}] resp {:invitation-token token}]
(-> resp (-> resp
(rph/with-transform (session/create-fn cfg (:id profile))) (rph/with-transform (session/create-fn cfg (:id profile)))
@ -404,7 +405,7 @@
;; In all other cases, send a verification email. ;; In all other cases, send a verification email.
:else :else
(do (do
(send-email-verification! conn (::main/props cfg) profile) (send-email-verification! conn (::setup/props cfg) profile)
(rph/with-meta profile (rph/with-meta profile
{::audit/replace-props (audit/profile->props profile) {::audit/replace-props (audit/profile->props profile)
::audit/profile-id (:id profile)}))))) ::audit/profile-id (:id profile)})))))
@ -429,14 +430,14 @@
(defn request-profile-recovery (defn request-profile-recovery
[{:keys [::db/pool] :as cfg} {:keys [email] :as params}] [{:keys [::db/pool] :as cfg} {:keys [email] :as params}]
(letfn [(create-recovery-token [{:keys [id] :as profile}] (letfn [(create-recovery-token [{:keys [id] :as profile}]
(let [token (tokens/generate (::main/props cfg) (let [token (tokens/generate (::setup/props cfg)
{:iss :password-recovery {:iss :password-recovery
:exp (dt/in-future "15m") :exp (dt/in-future "15m")
:profile-id id})] :profile-id id})]
(assoc profile :token token))) (assoc profile :token token)))
(send-email-notification [conn profile] (send-email-notification [conn profile]
(let [ptoken (tokens/generate (::main/props cfg) (let [ptoken (tokens/generate (::setup/props cfg)
{:iss :profile-identity {:iss :profile-identity
:profile-id (:id profile) :profile-id (:id profile)
:exp (dt/in-future {:days 30})})] :exp (dt/in-future {:days 30})})]

View file

@ -18,6 +18,7 @@
[app.rpc.commands.profile :as profile] [app.rpc.commands.profile :as profile]
[app.rpc.doc :as-alias doc] [app.rpc.doc :as-alias doc]
[app.rpc.helpers :as rph] [app.rpc.helpers :as rph]
[app.setup :as-alias setup]
[app.tokens :as tokens] [app.tokens :as tokens]
[app.util.services :as sv] [app.util.services :as sv]
[clojure.spec.alpha :as s])) [clojure.spec.alpha :as s]))
@ -40,7 +41,7 @@
{::rpc/auth false {::rpc/auth false
::doc/added "1.15" ::doc/added "1.15"
::doc/module :auth} ::doc/module :auth}
[{:keys [::main/props ::ldap/provider] :as cfg} params] [{:keys [::setup/props ::ldap/provider] :as cfg} params]
(when-not provider (when-not provider
(ex/raise :type :restriction (ex/raise :type :restriction
:code :ldap-not-initialized :code :ldap-not-initialized

View file

@ -23,6 +23,7 @@
[app.rpc.climit :as climit] [app.rpc.climit :as climit]
[app.rpc.doc :as-alias doc] [app.rpc.doc :as-alias doc]
[app.rpc.helpers :as rph] [app.rpc.helpers :as rph]
[app.setup :as-alias setup]
[app.storage :as sto] [app.storage :as sto]
[app.tokens :as tokens] [app.tokens :as tokens]
[app.util.services :as sv] [app.util.services :as sv]
@ -296,12 +297,12 @@
(defn- request-email-change! (defn- request-email-change!
[{:keys [::conn] :as cfg} {:keys [profile email] :as params}] [{:keys [::conn] :as cfg} {:keys [profile email] :as params}]
(let [token (tokens/generate (::main/props cfg) (let [token (tokens/generate (::setup/props cfg)
{:iss :change-email {:iss :change-email
:exp (dt/in-future "15m") :exp (dt/in-future "15m")
:profile-id (:id profile) :profile-id (:id profile)
:email email}) :email email})
ptoken (tokens/generate (::main/props cfg) ptoken (tokens/generate (::setup/props cfg)
{:iss :profile-identity {:iss :profile-identity
:profile-id (:id profile) :profile-id (:id profile)
:exp (dt/in-future {:days 30})})] :exp (dt/in-future {:days 30})})]

View file

@ -26,6 +26,7 @@
[app.rpc.helpers :as rph] [app.rpc.helpers :as rph]
[app.rpc.permissions :as perms] [app.rpc.permissions :as perms]
[app.rpc.quotes :as quotes] [app.rpc.quotes :as quotes]
[app.setup :as-alias setup]
[app.storage :as sto] [app.storage :as sto]
[app.tokens :as tokens] [app.tokens :as tokens]
[app.util.services :as sv] [app.util.services :as sv]
@ -691,7 +692,7 @@
(defn- create-invitation-token (defn- create-invitation-token
[cfg {:keys [profile-id valid-until team-id member-id member-email role]}] [cfg {:keys [profile-id valid-until team-id member-id member-email role]}]
(tokens/generate (::main/props cfg) (tokens/generate (::setup/props cfg)
{:iss :team-invitation {:iss :team-invitation
:exp valid-until :exp valid-until
:profile-id profile-id :profile-id profile-id
@ -702,7 +703,7 @@
(defn- create-profile-identity-token (defn- create-profile-identity-token
[cfg profile] [cfg profile]
(tokens/generate (::main/props cfg) (tokens/generate (::setup/props cfg)
{:iss :profile-identity {:iss :profile-identity
:profile-id (:id profile) :profile-id (:id profile)
:exp (dt/in-future {:days 30})})) :exp (dt/in-future {:days 30})}))

View file

@ -18,6 +18,7 @@
[app.rpc.doc :as-alias doc] [app.rpc.doc :as-alias doc]
[app.rpc.helpers :as rph] [app.rpc.helpers :as rph]
[app.rpc.quotes :as quotes] [app.rpc.quotes :as quotes]
[app.setup :as-alias setup]
[app.tokens :as tokens] [app.tokens :as tokens]
[app.tokens.spec.team-invitation :as-alias spec.team-invitation] [app.tokens.spec.team-invitation :as-alias spec.team-invitation]
[app.util.services :as sv] [app.util.services :as sv]
@ -38,7 +39,7 @@
::doc/module :auth} ::doc/module :auth}
[{:keys [::db/pool] :as cfg} {:keys [token] :as params}] [{:keys [::db/pool] :as cfg} {:keys [token] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(let [claims (tokens/verify (::main/props cfg) {:token token}) (let [claims (tokens/verify (::setup/props cfg) {:token token})
cfg (assoc cfg :conn conn)] cfg (assoc cfg :conn conn)]
(process-token cfg params claims)))) (process-token cfg params claims))))

View file

@ -50,16 +50,15 @@
:cause cause)))) :cause cause))))
instance-id))) instance-id)))
(s/def ::main/key ::us/string) (s/def ::key ::us/string)
(s/def ::main/props (s/def ::props (s/map-of ::us/keyword some?))
(s/map-of ::us/keyword some?))
(defmethod ig/pre-init-spec ::props [_] (defmethod ig/pre-init-spec ::props [_]
(s/keys :req [::db/pool] (s/keys :req [::db/pool]
:opt [::main/key])) :opt [::key]))
(defmethod ig/init-key ::props (defmethod ig/init-key ::props
[_ {:keys [::db/pool ::main/key] :as cfg}] [_ {:keys [::db/pool ::key] :as cfg}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(db/xact-lock! conn 0) (db/xact-lock! conn 0)
(when-not key (when-not key

View file

@ -15,6 +15,7 @@
[app.db :as db] [app.db :as db]
[app.http.client :as http] [app.http.client :as http]
[app.main :as-alias main] [app.main :as-alias main]
[app.setup :as-alias setup]
[app.util.json :as json] [app.util.json :as json]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[integrant.core :as ig] [integrant.core :as ig]
@ -32,10 +33,10 @@
(defmethod ig/pre-init-spec ::handler [_] (defmethod ig/pre-init-spec ::handler [_]
(s/keys :req [::http/client (s/keys :req [::http/client
::db/pool ::db/pool
::main/props])) ::setup/props]))
(defmethod ig/init-key ::handler (defmethod ig/init-key ::handler
[_ {:keys [::db/pool ::main/props] :as cfg}] [_ {:keys [::db/pool ::setup/props] :as cfg}]
(fn [{:keys [send? enabled?] :or {send? true enabled? false}}] (fn [{:keys [send? enabled?] :or {send? true enabled? false}}]
(let [subs {:newsletter-updates (get-subscriptions-newsletter-updates pool) (let [subs {:newsletter-updates (get-subscriptions-newsletter-updates pool)
:newsletter-news (get-subscriptions-newsletter-news pool)} :newsletter-news (get-subscriptions-newsletter-news pool)}

View file

@ -102,7 +102,7 @@
(t/deftest test-parse-bounce-report (t/deftest test-parse-bounce-report
(let [profile (th/create-profile* 1) (let [profile (th/create-profile* 1)
props (:app.setup/props th/*system*) props (:app.setup/props th/*system*)
cfg {:app.main/props props} cfg {:app.setup/props props}
report (bounce-report {:token (tokens/generate props report (bounce-report {:token (tokens/generate props
{:iss :profile-identity {:iss :profile-identity
:profile-id (:id profile)})}) :profile-id (:id profile)})})
@ -118,7 +118,7 @@
(t/deftest test-parse-complaint-report (t/deftest test-parse-complaint-report
(let [profile (th/create-profile* 1) (let [profile (th/create-profile* 1)
props (:app.setup/props th/*system*) props (:app.setup/props th/*system*)
cfg {:app.main/props props} cfg {:app.setup/props props}
report (complaint-report {:token (tokens/generate props report (complaint-report {:token (tokens/generate props
{:iss :profile-identity {:iss :profile-identity
:profile-id (:id profile)})}) :profile-id (:id profile)})})
@ -132,7 +132,7 @@
(t/deftest test-parse-complaint-report-without-token (t/deftest test-parse-complaint-report-without-token
(let [props (:app.setup/props th/*system*) (let [props (:app.setup/props th/*system*)
cfg {:app.main/props props} cfg {:app.setup/props props}
report (complaint-report {:token ""}) report (complaint-report {:token ""})
result (#'awsns/parse-notification cfg report)] result (#'awsns/parse-notification cfg report)]
(t/is (= "complaint" (:type result))) (t/is (= "complaint" (:type result)))
@ -145,7 +145,7 @@
(let [profile (th/create-profile* 1) (let [profile (th/create-profile* 1)
props (:app.setup/props th/*system*) props (:app.setup/props th/*system*)
pool (:app.db/pool th/*system*) pool (:app.db/pool th/*system*)
cfg {:app.main/props props :app.db/pool pool} cfg {:app.setup/props props :app.db/pool pool}
report (bounce-report {:token (tokens/generate props report (bounce-report {:token (tokens/generate props
{:iss :profile-identity {:iss :profile-identity
:profile-id (:id profile)})}) :profile-id (:id profile)})})
@ -172,7 +172,7 @@
(let [profile (th/create-profile* 1) (let [profile (th/create-profile* 1)
props (:app.setup/props th/*system*) props (:app.setup/props th/*system*)
pool (:app.db/pool th/*system*) pool (:app.db/pool th/*system*)
cfg {:app.main/props props cfg {:app.setup/props props
:app.db/pool pool} :app.db/pool pool}
report (complaint-report {:token (tokens/generate props report (complaint-report {:token (tokens/generate props
{:iss :profile-identity {:iss :profile-identity
@ -202,7 +202,7 @@
(let [profile (th/create-profile* 1) (let [profile (th/create-profile* 1)
props (:app.setup/props th/*system*) props (:app.setup/props th/*system*)
pool (:app.db/pool th/*system*) pool (:app.db/pool th/*system*)
cfg {:app.main/props props :app.db/pool pool} cfg {:app.setup/props props :app.db/pool pool}
report (bounce-report {:email (:email profile) report (bounce-report {:email (:email profile)
:token (tokens/generate props :token (tokens/generate props
{:iss :profile-identity {:iss :profile-identity
@ -224,7 +224,7 @@
(let [profile (th/create-profile* 1) (let [profile (th/create-profile* 1)
props (:app.setup/props th/*system*) props (:app.setup/props th/*system*)
pool (:app.db/pool th/*system*) pool (:app.db/pool th/*system*)
cfg {:app.main/props props :app.db/pool pool} cfg {:app.setup/props props :app.db/pool pool}
report (complaint-report {:email (:email profile) report (complaint-report {:email (:email profile)
:token (tokens/generate props :token (tokens/generate props
{:iss :profile-identity {:iss :profile-identity