Skip to content

Commit

Permalink
Log cleanup (#281)
Browse files Browse the repository at this point in the history
* Add names to interceptors

Co-authored-by: Iain Wood <iain.wood@flexiana.com>

* Remove spurious log message

Co-authored-by: Iain Wood <iain.wood@flexiana.com>

---------

Co-authored-by: Iain Wood <iain.wood@flexiana.com>
  • Loading branch information
gmsvalente and Iain Wood authored Feb 14, 2024
1 parent 57f4091 commit d19537c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/xiana/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@
driver, if succeeds associate its results into state response data.
Remember the entry query must be a sql-map, e.g:
{:select [:*] :from [:users]}."
{:leave
{:name ::db-access
:leave
(fn [{query-or-fn :query
db-queries :db-queries
:as state}]
Expand Down
6 changes: 4 additions & 2 deletions src/xiana/interceptor.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"Log interceptor.
Enter: Print 'Enter:' followed by the complete state map.
Leave: Print 'Leave:' followed by the complete state map."
{:enter (fn [state] (pprint ["Enter: " state]) state)
{:name ::log
:enter (fn [state] (pprint ["Enter: " state]) state)
:leave (fn [state] (pprint ["Leave: " state]) state)})

(def side-effect
Expand All @@ -33,7 +34,8 @@
"View interceptor.
Enter: nil. Leave: apply `:view` state key to state if it exists and
`:response` is absent."
{:leave
{:name ::view
:leave
(fn [{:keys [view response] :as state}]
(if (and (not (:body response)) view)
(view state)
Expand Down
11 changes: 5 additions & 6 deletions src/xiana/interceptor/queue.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
direction-enter? (= :enter direction)
exception (:error state)]

(log/debug (format "%s | %s | err?: %s | exception %s"
direction
(-> interceptors first :name)
direction-error?
exception))

(cond
;; just got an exception, executing all remaining interceptors backwards
(and exception (not direction-error?))
Expand All @@ -67,6 +61,11 @@
next-interceptors (if (and (:error state) (= :leave direction))
interceptors
(rest interceptors))]
(log/debug (format "%s | %s | err?: %s | exception %s"
direction
(-> interceptors first :name)
direction-error?
exception))
(recur state
next-interceptors
(when direction-enter? (conj backwards (first interceptors)))
Expand Down
3 changes: 2 additions & 1 deletion src/xiana/rbac.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
If it's not restricted do nothing,
if the given user has no rights, it throws ex-info with data {:status 403 :body \"Forbidden\"}.
On leave executes restriction function if any."
{:enter (fn [state]
{:name ::rbac
:enter (fn [state]
(let [operation-restricted (get-in state [:request-data :permission])
permits (and operation-restricted (permissions state))]
(cond
Expand Down

0 comments on commit d19537c

Please sign in to comment.