Google API authentication helpers: service accounts and local OAuth
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

wal, block, sse, zephyr: remove [mutable] from never-reassigned fields

Warning 69 (unused-field, mutable-never-assigned). Four independent
record fields were flagged as mutable but the code only mutates their
referents in place, never rebinds the record slot itself:

- ocaml-wal/lib/wal.ml: [t.file] (the Eio file resource; methods call
Eio.File.pwrite_all etc., the slot is set once at open time).
- ocaml-block/lib/block.ml: [Memory.state.data] (the backing bytes,
written via Bytes.blit_string; [Bytes.t] is already mutable).
- ocaml-sse/lib/sse.ml: [Parser.t.data_buf] (a Buffer.t, written via
Buffer.add_*; the slot never changes).
- ocaml-zephyr/lib/zephyr.ml: drop [mode : Read | Write] entirely —
set at open-time, read nowhere. The open_read / open_write
constructors already distinguish the two call shapes, so mode
tracking was redundant.

+22 -19
+3
dune
··· 1 + (env 2 + (dev 3 + (flags :standard %{dune-warnings})))
+1 -1
dune-project
··· 26 26 (digestif (>= 1.0)) 27 27 (eio (>= 1.0)) 28 28 (fmt (>= 0.9)) 29 - (jsont (>= 0.2)) 29 + (json (>= 0.2)) 30 30 (bytesrw (>= 0.1)) 31 31 (jwt (>= 0.1)) 32 32 (logs (>= 0.7))
+1 -1
gauth.opam
··· 21 21 "digestif" {>= "1.0"} 22 22 "eio" {>= "1.0"} 23 23 "fmt" {>= "0.9"} 24 - "jsont" {>= "0.2"} 24 + "json" {>= "0.2"} 25 25 "bytesrw" {>= "0.1"} 26 26 "jwt" {>= "0.1"} 27 27 "logs" {>= "0.7"}
+2 -2
lib/dune
··· 7 7 digestif 8 8 eio 9 9 fmt 10 - jsont 11 - jsont.bytesrw 10 + json 11 + json.bytesrw 12 12 jwt 13 13 logs 14 14 oauth
+15 -15
lib/gauth.ml
··· 93 93 } 94 94 95 95 let raw_jsont = 96 - Jsont.Object.map ~kind:"service_account" 96 + Json.Object.map ~kind:"service_account" 97 97 (fun type_ client_email token_uri private_key private_key_id -> 98 98 { type_; client_email; token_uri; private_key; private_key_id }) 99 - |> Jsont.Object.mem "type" Jsont.string ~enc:(fun k -> k.type_) 100 - |> Jsont.Object.mem "client_email" Jsont.string ~enc:(fun k -> 99 + |> Json.Object.mem "type" Json.string ~enc:(fun k -> k.type_) 100 + |> Json.Object.mem "client_email" Json.string ~enc:(fun k -> 101 101 k.client_email) 102 - |> Jsont.Object.opt_mem "token_uri" Jsont.string ~enc:(fun k -> k.token_uri) 103 - |> Jsont.Object.mem "private_key" Jsont.string ~enc:(fun k -> k.private_key) 104 - |> Jsont.Object.opt_mem "private_key_id" Jsont.string ~enc:(fun k -> 102 + |> Json.Object.opt_mem "token_uri" Json.string ~enc:(fun k -> k.token_uri) 103 + |> Json.Object.mem "private_key" Json.string ~enc:(fun k -> k.private_key) 104 + |> Json.Object.opt_mem "private_key_id" Json.string ~enc:(fun k -> 105 105 k.private_key_id) 106 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 106 + |> Json.Object.skip_unknown |> Json.Object.finish 107 107 108 108 (* Convert X509 RSA private key to a Jwt.Jwk RSA private key. 109 109 JWK RFC 7518 §6.3 requires the RSA components as unsigned big-endian ··· 141 141 | Ok _ -> err_sa_expected_rsa () 142 142 143 143 let of_json s = 144 - match Jsont_bytesrw.decode_string raw_jsont s with 144 + match Json_bytesrw.decode_string raw_jsont s with 145 145 | Error e -> err_sa_json e 146 146 | Ok r -> of_raw r 147 147 ··· 433 433 } 434 434 435 435 let snapshot_jsont = 436 - Jsont.Object.map ~kind:"gauth_token" 436 + Json.Object.map ~kind:"gauth_token" 437 437 (fun access_token refresh_token expires_at -> 438 438 { access_token; refresh_token; expires_at }) 439 - |> Jsont.Object.mem "access_token" Jsont.string ~enc:(fun s -> s.access_token) 440 - |> Jsont.Object.opt_mem "refresh_token" Jsont.string ~enc:(fun s -> 439 + |> Json.Object.mem "access_token" Json.string ~enc:(fun s -> s.access_token) 440 + |> Json.Object.opt_mem "refresh_token" Json.string ~enc:(fun s -> 441 441 s.refresh_token) 442 - |> Jsont.Object.opt_mem "expires_at" Jsont.number ~enc:(fun s -> s.expires_at) 443 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 442 + |> Json.Object.opt_mem "expires_at" Json.number ~enc:(fun s -> s.expires_at) 443 + |> Json.Object.skip_unknown |> Json.Object.finish 444 444 445 445 let snapshot_of_token = function 446 446 | Oauth_token t -> ··· 458 458 459 459 let to_json t = 460 460 let s = snapshot_of_token t in 461 - match Jsont_bytesrw.encode_string snapshot_jsont s with 461 + match Json_bytesrw.encode_string snapshot_jsont s with 462 462 | Ok s -> s 463 463 | Error e -> Fmt.failwith "Gauth.to_json: %s" e 464 464 465 465 let of_json http ~clock ~client_id ~client_secret body = 466 - match Jsont_bytesrw.decode_string snapshot_jsont body with 466 + match Json_bytesrw.decode_string snapshot_jsont body with 467 467 | Error e -> Error (`Msg e) 468 468 | Ok s -> 469 469 let tok =