Skip to content

Commit

Permalink
do_dispatch and rback check
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBuica committed Jul 30, 2024
1 parent 1aed403 commit 55cae2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ocaml/xapi/rbac.ml
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@ let is_access_allowed ~__context ~session_id ~permission =
(* Execute fn if rbac access is allowed for action, otherwise fails. *)
let nofn () = ()

let ( let@ ) f x = f x

let check ?(extra_dmsg = "") ?(extra_msg = "") ?args ?(keys = []) ~__context ~fn
session_id action =
let@ _ =
Tracing.with_child_trace ~name:__FUNCTION__ (Context.tracing_of __context)
in
let permission = permission_of_action action ?args ~keys in
if is_access_allowed ~__context ~session_id ~permission then (
(* allow access to action *)
Expand Down
6 changes: 6 additions & 0 deletions ocaml/xapi/server_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ let dispatch_exn_wrapper f =
let code, params = ExnHelper.error_of_exn exn in
API.response_of_failure code params

let ( let@ ) f x = f x

let do_dispatch ?session_id ?forward_op ?self:_ supports_async called_fn_name
op_fn marshaller fd http_req label sync_ty generate_task_for =
let parent = Http_svr.traceparent_of_request http_req in
let@ span = Tracing.with_child_trace ~name:__FUNCTION__ parent in
(* if the call has been forwarded to us, then they are responsible for completing the task, so we don't need to complete it *)
let called_async = sync_ty <> `Sync in
if called_async && not supports_async then
Expand All @@ -131,6 +135,7 @@ let do_dispatch ?session_id ?forward_op ?self:_ supports_async called_fn_name
~supports_async ~label ~http_req ~fd ()
in
let sync () =
let@ _ = Tracing.with_child_trace ~name:__FUNCTION__ span in
let need_complete = not (Context.forwarded_task __context) in
exec_with_context ~__context ~need_complete ~called_async
?f_forward:forward_op ~marshaller op_fn
Expand All @@ -142,6 +147,7 @@ let do_dispatch ?session_id ?forward_op ?self:_ supports_async called_fn_name
ignore
(Thread.create
(fun () ->
let@ _ = Tracing.with_child_trace ~name:__FUNCTION__ span in
exec_with_context ~__context ~need_complete ~called_async
?f_forward:forward_op ~marshaller op_fn
)
Expand Down

0 comments on commit 55cae2a

Please sign in to comment.