mirror of
https://github.com/penpot/penpot.git
synced 2025-06-03 22:01:39 +02:00
✨ Add webhook trigger to audit events
This commit is contained in:
parent
3fe16bd8f9
commit
e203536506
2 changed files with 35 additions and 24 deletions
|
@ -108,6 +108,7 @@
|
||||||
[::ip-addr {:optional true} ::sm/text]
|
[::ip-addr {:optional true} ::sm/text]
|
||||||
[::props {:optional true} [:map-of :keyword :any]]
|
[::props {:optional true} [:map-of :keyword :any]]
|
||||||
[::context {:optional true} [:map-of :keyword :any]]
|
[::context {:optional true} [:map-of :keyword :any]]
|
||||||
|
[::tracked-at {:optional true} ::sm/inst]
|
||||||
[::webhooks/event? {:optional true} ::sm/boolean]
|
[::webhooks/event? {:optional true} ::sm/boolean]
|
||||||
[::webhooks/batch-timeout {:optional true} ::dt/duration]
|
[::webhooks/batch-timeout {:optional true} ::dt/duration]
|
||||||
[::webhooks/batch-key {:optional true}
|
[::webhooks/batch-key {:optional true}
|
||||||
|
@ -118,12 +119,12 @@
|
||||||
|
|
||||||
(defn prepare-event
|
(defn prepare-event
|
||||||
[cfg mdata params result]
|
[cfg mdata params result]
|
||||||
(let [resultm (meta result)
|
(let [resultm (meta result)
|
||||||
request (-> params meta ::http/request)
|
request (-> params meta ::http/request)
|
||||||
profile-id (or (::profile-id resultm)
|
profile-id (or (::profile-id resultm)
|
||||||
(:profile-id result)
|
(:profile-id result)
|
||||||
(::rpc/profile-id params)
|
(::rpc/profile-id params)
|
||||||
uuid/zero)
|
uuid/zero)
|
||||||
|
|
||||||
session-id (get params ::rpc/external-session-id)
|
session-id (get params ::rpc/external-session-id)
|
||||||
event-origin (get params ::rpc/external-event-origin)
|
event-origin (get params ::rpc/external-event-origin)
|
||||||
|
@ -135,14 +136,14 @@
|
||||||
|
|
||||||
(clean-props))
|
(clean-props))
|
||||||
|
|
||||||
token-id (::actoken/id request)
|
token-id (::actoken/id request)
|
||||||
context (-> (::context resultm)
|
context (-> (::context resultm)
|
||||||
(assoc :external-session-id session-id)
|
(assoc :external-session-id session-id)
|
||||||
(assoc :external-event-origin event-origin)
|
(assoc :external-event-origin event-origin)
|
||||||
(assoc :access-token-id (some-> token-id str))
|
(assoc :access-token-id (some-> token-id str))
|
||||||
(d/without-nils))
|
(d/without-nils))
|
||||||
|
|
||||||
ip-addr (inet/parse-request request)]
|
ip-addr (inet/parse-request request)]
|
||||||
|
|
||||||
{::type (or (::type resultm)
|
{::type (or (::type resultm)
|
||||||
(::rpc/type cfg))
|
(::rpc/type cfg))
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.http.client :as http]
|
[app.http.client :as http]
|
||||||
|
[app.loggers.audit :as audit]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[app.worker :as wrk]
|
[app.worker :as wrk]
|
||||||
[clojure.data.json :as json]
|
[clojure.data.json :as json]
|
||||||
|
@ -67,18 +68,27 @@
|
||||||
(defmethod ig/init-key ::process-event-handler
|
(defmethod ig/init-key ::process-event-handler
|
||||||
[_ cfg]
|
[_ cfg]
|
||||||
(fn [{:keys [props] :as task}]
|
(fn [{:keys [props] :as task}]
|
||||||
(l/dbg :hint "process webhook event" :name (:name props))
|
|
||||||
|
|
||||||
(when-let [items (lookup-webhooks cfg props)]
|
(let [items (lookup-webhooks cfg props)
|
||||||
(l/trc :hint "webhooks found for event" :total (count items))
|
event {::audit/profile-id (:profile-id props)
|
||||||
(db/tx-run! cfg (fn [cfg]
|
::audit/name "webhook"
|
||||||
(doseq [item items]
|
::audit/type "trigger"
|
||||||
(wrk/submit! (-> cfg
|
::audit/props {:name (get props :name)
|
||||||
(assoc ::wrk/task :run-webhook)
|
:event-id (get props :id)
|
||||||
(assoc ::wrk/queue :webhooks)
|
:total-affected (count items)}}]
|
||||||
(assoc ::wrk/max-retries 3)
|
|
||||||
(assoc ::wrk/params {:event props
|
(audit/insert! cfg event)
|
||||||
:config item})))))))))
|
|
||||||
|
(when items
|
||||||
|
(l/trc :hint "webhooks found for event" :total (count items))
|
||||||
|
(db/tx-run! cfg (fn [cfg]
|
||||||
|
(doseq [item items]
|
||||||
|
(wrk/submit! (-> cfg
|
||||||
|
(assoc ::wrk/task :run-webhook)
|
||||||
|
(assoc ::wrk/queue :webhooks)
|
||||||
|
(assoc ::wrk/max-retries 3)
|
||||||
|
(assoc ::wrk/params {:event props
|
||||||
|
:config item}))))))))))
|
||||||
;; --- RUN
|
;; --- RUN
|
||||||
|
|
||||||
(declare interpret-exception)
|
(declare interpret-exception)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue