Skip to content

Commit

Permalink
Fix bugs in wrapper around gcloud rewrite
Browse files Browse the repository at this point in the history
Two things were working incorrectly:
- The objects were not using percent encoding, resulting in an
incorrect uri, and
- the response was incorrectly parsed due to an incorrect decoder
  • Loading branch information
benbellick committed Dec 18, 2024
1 parent d3995c0 commit 528b317
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/storage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type rewrite_object_response = {
kind : string;
total_bytes_rewritten : string; [@key "totalBytesRewritten"]
object_size : string; [@key "objectSize"]
done_ : bool;
done_ : bool; [@key "done"]
rewrite_token : string option; [@key "rewriteToken"] [@default None]
resource : Yojson.Safe.t option; [@default None]
}
Expand All @@ -111,11 +111,15 @@ let rewrite_object source_bucket source_object destination_bucket
Lwt.catch
(fun () ->
let uri =
let source_object = Uri.pct_encode source_object in
let destination_object = Uri.pct_encode destination_object in
Uri.make () ~scheme:"https" ~host:"storage.googleapis.com"
~path:
(Printf.sprintf "storage/v1/b/%s/o/%s/rewriteTo/b/%s/o/%s"
source_bucket source_object destination_bucket destination_object)
in
print_endline "important check hehre";
print_endline (Uri.to_string uri);
let headers =
Cohttp.Header.of_list
[
Expand All @@ -130,8 +134,11 @@ let rewrite_object source_bucket source_object destination_bucket
>>= fun (resp, body) ->
match Cohttp.Response.status resp with
| `OK ->
print_endline "we ok'd here";
Error.parse_body_json rewrite_object_response_of_yojson body |> Lwt.return
| status_code -> Error.of_response_status_code_and_body status_code body
| status_code ->
print_endline "we error'd here";
Error.of_response_status_code_and_body status_code body

[@@@warning "-39"]

Expand Down

0 comments on commit 528b317

Please sign in to comment.