Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dinosaure committed May 4, 2020
1 parent 22cd974 commit e578856
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/async/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executables
(names hello_world receive_post)
(libraries cohttp-async base async_kernel))
(libraries mirage-crypto cohttp-async base async_kernel))

(alias
(name runtest)
Expand Down
39 changes: 20 additions & 19 deletions examples/async/s3_cp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

open Base
open Core
open Async_kernel
open Async
open Cohttp
open Cohttp_async

Expand Down Expand Up @@ -78,9 +78,9 @@ module Compat = struct
if is_hex(String.get s (i+1)) && is_hex(String.get s (i+2)) then
Buffer.add_char buf c
else
Buffer.add_bytes buf "%25"
Buffer.add_string buf "%25"
end
| _ -> Buffer.add_bytes buf (Printf.sprintf "%%%X" (Char.to_int c))
| _ -> Buffer.add_string buf (Printf.sprintf "%%%X" (Char.to_int c))
done;
Buffer.contents buf

Expand Down Expand Up @@ -108,7 +108,7 @@ module Compat = struct
URI.encoded_of_query encodes [""] as ?a=, and [] as ?a.
*)
Uri.query uri
|> List.sort ~cmp:ksrt
|> List.sort ~compare:ksrt
|> List.map
~f:(fun (k,v) -> (k, match v with [] -> [""] | x -> x))
|> Uri.encoded_of_query
Expand Down Expand Up @@ -180,7 +180,7 @@ module Auth = struct

let digest s =
(* string -> sha256 as a hex string *)
Nocrypto.Hash.(digest `SHA256 (Cstruct.of_string s))
Mirage_crypto.Hash.(digest `SHA256 (Cstruct.of_string s))
|> Compat.cstruct_to_hex_string

let make_amz_headers ?body time =
Expand Down Expand Up @@ -212,7 +212,7 @@ module Auth = struct
(* Sort query string in alphabetical order by key *)
let canonical_query = Compat.encode_query_string uri in
let sorted_headers = Header.to_list request.headers
|> List.sort ~cmp:ksrt in
|> List.sort ~compare:ksrt in
let canonical_headers = sorted_headers
|> List.fold ~init:"" ~f:(fun acc (k,v) ->
acc ^
Expand Down Expand Up @@ -244,7 +244,7 @@ module Auth = struct
Printf.sprintf "AWS4-HMAC-SHA256\n%s\n%s\n%s" time_str scope_str hashed_req

let make_signing_key ?date ~region ~service ~secret_access_key =
let mac k v = Nocrypto.Hash.(mac `SHA256
let mac k v = Mirage_crypto.Hash.(mac `SHA256
~key:k
(Cstruct.of_string v)) in
let date' = match date with
Expand All @@ -269,7 +269,7 @@ module Auth = struct
(string_of_region region)
(string_of_service service)
in
let signature = Nocrypto.Hash.(mac `SHA256
let signature = Mirage_crypto.Hash.(mac `SHA256
~key:signing_key
(Cstruct.of_string string_to_sign)) in
let auth_header = Printf.sprintf
Expand Down Expand Up @@ -343,7 +343,7 @@ let determine_paths src dst =
| (false, false) -> failwith "Use cp(1) :)"
| (true, true) -> failwith "Does not support copying from s3 to s3"

let run region_str aws_access_key aws_secret_key src dst () =
let main region_str aws_access_key aws_secret_key src dst () =
(* nb client does not support redirects or preflight 100 *)
let open S3 in
let region = region_of_string region_str in
Expand Down Expand Up @@ -376,14 +376,15 @@ let run region_str aws_access_key aws_secret_key src dst () =
end

let () =
Command.async
let open Async_command in
async_spec
~summary:"Simple command line client that copies files to/from S3"
Command.Spec.(empty
+> flag "-r" (optional_with_default "us-east-1" string)
~doc:"string AWS Region"
+> anon ("aws_access_key" %: string)
+> anon ("aws_secret_key" %: string)
+> anon ("src" %: string)
+> anon ("dst" %: string)
) run
|> Command.run
Spec.(empty
+> flag "-r" (optional_with_default "us-east-1" string)
~doc:"string AWS Region"
+> anon ("aws_access_key" %: string)
+> anon ("aws_secret_key" %: string)
+> anon ("src" %: string)
+> anon ("dst" %: string)
) main
|> run

0 comments on commit e578856

Please sign in to comment.