summaryrefslogtreecommitdiff
path: root/cli/tools/registry/provenance.rs
diff options
context:
space:
mode:
authorSean McArthur <sean@seanmonstar.com>2024-07-12 15:51:37 -0700
committerGitHub <noreply@github.com>2024-07-13 00:51:37 +0200
commitf6fd6619e708a515831f707438368d81b0c9aa56 (patch)
tree9c65c76613330a22c5a88c017752a9aa7e0951ac /cli/tools/registry/provenance.rs
parent2fca4f11fe22a5d49326b6bf5b3ef039403eb0df (diff)
refactor(fetch): reimplement fetch with hyper instead of reqwest (#24237)
This commit re-implements `ext/fetch` and all dependent crates using `hyper` and `hyper-util`, instead of `reqwest`. The reasoning is that we want to have greater control and access to low level `hyper` APIs when implementing `fetch` API as well as `node:http` module. --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tools/registry/provenance.rs')
-rw-r--r--cli/tools/registry/provenance.rs34
1 files changed, 22 insertions, 12 deletions
diff --git a/cli/tools/registry/provenance.rs b/cli/tools/registry/provenance.rs
index 622e483d6..ce3d6ff8a 100644
--- a/cli/tools/registry/provenance.rs
+++ b/cli/tools/registry/provenance.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+use crate::http_util;
use crate::http_util::HttpClient;
use super::api::OidcTokenResponse;
@@ -12,6 +13,8 @@ use deno_core::anyhow;
use deno_core::anyhow::bail;
use deno_core::error::AnyError;
use deno_core::serde_json;
+use deno_core::url::Url;
+use http_body_util::BodyExt;
use once_cell::sync::Lazy;
use p256::elliptic_curve;
use p256::pkcs8::AssociatedOid;
@@ -504,12 +507,12 @@ impl<'a> FulcioSigner<'a> {
let response = self
.http_client
- .post(url)
- .json(&request_body)
+ .post_json(url.parse()?, &request_body)?
.send()
.await?;
- let body: SigningCertificateResponse = response.json().await?;
+ let body: SigningCertificateResponse =
+ http_util::body_to_json(response).await?;
let key = body
.signed_certificate_embedded_sct
@@ -527,15 +530,23 @@ impl<'a> FulcioSigner<'a> {
bail!("No OIDC token available");
};
- let res = self
+ let mut url = req_url.parse::<Url>()?;
+ url.query_pairs_mut().append_pair("audience", aud);
+ let res_bytes = self
.http_client
- .get(&req_url)
- .bearer_auth(token)
- .query(&[("audience", aud)])
+ .get(url)?
+ .header(
+ http::header::AUTHORIZATION,
+ format!("Bearer {}", token)
+ .parse()
+ .map_err(http::Error::from)?,
+ )
.send()
.await?
- .json::<OidcTokenResponse>()
- .await?;
+ .collect()
+ .await?
+ .to_bytes();
+ let res: OidcTokenResponse = serde_json::from_slice(&res_bytes)?;
Ok(res.value)
}
}
@@ -685,11 +696,10 @@ async fn testify(
let url = format!("{}/api/v1/log/entries", *DEFAULT_REKOR_URL);
let res = http_client
- .post(&url)
- .json(&proposed_intoto_entry)
+ .post_json(url.parse()?, &proposed_intoto_entry)?
.send()
.await?;
- let body: RekorEntry = res.json().await?;
+ let body: RekorEntry = http_util::body_to_json(res).await?;
Ok(body)
}