From b6a225660f67a4e28ac0f765cdb2a473e747c70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Fri, 20 Feb 2026 21:27:10 +0100 Subject: [PATCH] Hack in support for Garage --- aws-s3/region.ml | 3 +++ aws-s3/region.mli | 2 ++ cli/aws.ml | 21 +++++++++++++-------- cli/cli.ml | 27 +++++++++++++++++++++------ 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/aws-s3/region.ml b/aws-s3/region.ml index 3b35e8c..a896929 100644 --- a/aws-s3/region.ml +++ b/aws-s3/region.ml @@ -78,6 +78,9 @@ let vendor ~region_name ?port ~host () = let minio ?port ~host () = vendor ~region_name:(to_string Us_east_1) ~host ?port () +let garage ?port ~host () = + vendor ~region_name:"garage" ~host ?port () + let backblaze ~region_name () = vendor ~region_name ?port:None diff --git a/aws-s3/region.mli b/aws-s3/region.mli index 78c42e4..eaa371c 100644 --- a/aws-s3/region.mli +++ b/aws-s3/region.mli @@ -26,6 +26,8 @@ val vendor : region_name:string -> ?port:int -> host:string -> unit -> t val minio : ?port:int -> host:string -> unit -> t +val garage : ?port:int -> host:string -> unit -> t + val backblaze : region_name:string -> unit -> t type endpoint = { diff --git a/cli/aws.ml b/cli/aws.ml index e288060..a535b0c 100644 --- a/cli/aws.ml +++ b/cli/aws.ml @@ -226,19 +226,24 @@ module Make(Io : Aws_s3.Types.Io) = struct let credentials = ok_exn credentials in S3.retry ~endpoint ~retries ~f:(S3.ls ?connect_timeout_ms:None ~confirm_requester_pays ?start_after ?continuation_token:None ~credentials ?max_keys ?prefix ~bucket) () >>=? ls_all ?max_keys - let exec ({ Cli.profile; https; minio; retries; ipv6; expect; confirm_requester_pays }, cmd) = + let exec ({ Cli.profile; https; region; retries; ipv6; expect; confirm_requester_pays }, cmd) = let inet = if ipv6 then `V6 else `V4 in let scheme = if https then `Https else `Http in (* TODO: Get the region from the CLI *) let region : Aws_s3.Region.t = - match minio with - | Some minio -> - let host, port = match String.split_on_char ~sep:':' minio with - | [host; port] -> host, Some (int_of_string port) - | [host] -> host, None - | _ -> failwith "Unable to parse minio address" - in + let host_port s = + match String.split_on_char ~sep:':' s with + | [host; port] -> host, Some (int_of_string port) + | [host] -> host, None + | _ -> failwith "Unable to parse region address" + in + match region with + | Some `Minio minio -> + let host, port = host_port minio in Aws_s3.Region.minio ?port ~host () + | Some `Garage garage -> + let host, port = host_port garage in + Aws_s3.Region.garage ?port ~host () | None -> Us_east_1 in let endpoint = Aws_s3.Region.endpoint ~inet ~scheme region in diff --git a/cli/cli.ml b/cli/cli.ml index d5199e9..b0bea0e 100644 --- a/cli/cli.ml +++ b/cli/cli.ml @@ -8,7 +8,7 @@ type actions = | Cp of { src: string; dest: string; first: int option; last: int option; multi: bool; chunk_size: int option} type options = - { profile: string option; minio: string option; https: bool; retries: int; ipv6: bool; expect: bool; confirm_requester_pays : bool } + { profile: string option; region: [ `Minio of string | `Garage of string ] option; https: bool; retries: int; ipv6: bool; expect: bool; confirm_requester_pays : bool } let parse exec = let profile = @@ -26,9 +26,24 @@ let parse exec = Arg.(value & opt bool false & info ["https"] ~docv:"HTTPS" ~doc) in - let minio = - let doc = "Connect to minio address [:port]" in - Arg.(value & opt (some string) None & info ["minio"] ~docv:"MINIO" ~doc) + let region = + let minio = + let doc = "Connect to minio address [:port]" in + Arg.(value & opt (some string) None & info ["minio"] ~docv:"MINIO" ~doc) + in + let garage = + let doc = "Connect to garage address [:port]" in + Arg.(value & opt (some string) None & info ["garage"] ~docv:"GARAGE" ~doc) + in + let open Term.Syntax in + let+ minio = minio and+ garage = garage in + match minio, garage with + | None, None -> None + | Some minio, None -> Some (`Minio minio) + | None, Some garage -> Some (`Garage garage) + | Some _, Some _ -> + Printf.eprintf "Options --minio and --garage are mutually exclusive. Exiting...\n%!"; + exit 254 in let ipv6 = @@ -54,8 +69,8 @@ let parse exec = in let common_opts = - let make profile minio https retries ipv6 expect confirm_requester_pays = { profile; minio; https; retries; ipv6; expect; confirm_requester_pays } in - Term.(const make $ profile $ minio $ https $ retries $ ipv6 $ expect $ confirm_requester_pays ) + let make profile region https retries ipv6 expect confirm_requester_pays = { profile; region; https; retries; ipv6; expect; confirm_requester_pays } in + Term.(const make $ profile $ region $ https $ retries $ ipv6 $ expect $ confirm_requester_pays ) in let bucket n =