Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP-51391: Implement handling for /repository/enabled #6083

Open
wants to merge 1 commit into
base: feature/easier-pool-join
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ocaml/xapi-consts/constants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ let get_updates_uri = "/updates" (* ocaml/xapi/repository.ml *)

let put_bundle_uri = "/bundle" (* ocaml/xapi/xapi_pool.ml *)

let enabled_repo_uri_prefix = "/enabled"

let default_usb_speed = -1.

let use_compression = "use_compression"
Expand Down
69 changes: 33 additions & 36 deletions ocaml/xapi/repository.ml
Original file line number Diff line number Diff line change
Expand Up @@ -519,42 +519,39 @@ let get_repository_handler (req : Http.Request.t) s _ =
if Fileserver.access_forbidden req s then
Http_svr.response_forbidden ~req s
else
let can_be_authorized =
try
Xapi_http.with_context "get_repository_handler" req s (fun _ -> ()) ;
true
with _ -> false
in
let internal_repo_access_only =
let __context =
Context.make ~origin:(Http (req, s)) "get_repository_handler"
in
Pool_features.is_enabled ~__context Features.Internal_repo_access
in
match (can_be_authorized, internal_repo_access_only) with
| false, true ->
error
"Invalid secret for authorization when Internal_repo_access is \
enabled" ;
Http_svr.response_forbidden ~req s
| _ -> (
try
let len = String.length Constants.get_repository_uri in
match String.sub_to_end req.Request.uri len with
| uri_path ->
let root = !Xapi_globs.local_pool_repo_dir in
Fileserver.response_file s (Helpers.resolve_uri_path ~root ~uri_path)
| exception e ->
let msg =
Printf.sprintf "Failed to get path from uri': %s"
(ExnHelper.string_of_exn e)
in
raise Api_errors.(Server_error (internal_error, [msg]))
with e ->
error "Failed to serve for request on uri %s: %s" req.Request.uri
(ExnHelper.string_of_exn e) ;
Http_svr.response_forbidden ~req s
)
try
Xapi_http.with_context "get_repository_handler" req s (fun __context ->
let uri_paths = String.split '/' req.Request.uri in
let uri_path =
match uri_paths with
| "" :: prefix :: repo :: rst_path
when prefix = String.sub_to_end Constants.get_repository_uri 1 ->
let repo_name =
if
repo = String.sub_to_end Constants.enabled_repo_uri_prefix 1
then
let enabled_repo =
get_single_enabled_update_repository ~__context
in
get_remote_repository_name ~__context ~self:enabled_repo
else
repo
in
String.concat "/" (repo_name :: rst_path)
| _ ->
let msg =
Printf.sprintf "Failed to get path from uri: %s"
req.Request.uri
in
raise Api_errors.(Server_error (internal_error, [msg]))
in
let root = !Xapi_globs.local_pool_repo_dir in
Fileserver.response_file s (Helpers.resolve_uri_path ~root ~uri_path)
)
with e ->
error "Failed to serve for request on uri %s: %s" req.Request.uri
(ExnHelper.string_of_exn e) ;
Http_svr.response_forbidden ~req s

let consolidate_updates_of_hosts ~repository_name ~updates_info ~hosts =
Hashtbl.fold
Expand Down
Loading