Skip to content
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
3 changes: 3 additions & 0 deletions aws-s3/region.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions aws-s3/region.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
21 changes: 13 additions & 8 deletions cli/aws.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 21 additions & 6 deletions cli/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 <host>[:port]" in
Arg.(value & opt (some string) None & info ["minio"] ~docv:"MINIO" ~doc)
let region =
let minio =
let doc = "Connect to minio address <host>[:port]" in
Arg.(value & opt (some string) None & info ["minio"] ~docv:"MINIO" ~doc)
in
let garage =
let doc = "Connect to garage address <host>[: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 =
Expand All @@ -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 =
Expand Down