summaryrefslogtreecommitdiff
path: root/cli/tools/registry/provenance.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-07-18 00:37:31 +0100
committerGitHub <noreply@github.com>2024-07-18 01:37:31 +0200
commit7b33623b1d70803b43e511a58666a73dd0b2ed67 (patch)
tree2d900f2be67caebf6a886d6e06a340b095e636cc /cli/tools/registry/provenance.rs
parentf4b9d8586215fc07c28998e5d896fefa876139b7 (diff)
Reland "refactor(fetch): reimplement fetch with hyper instead of reqwest" (#24593)
Originally landed in https://github.com/denoland/deno/commit/f6fd6619e708a515831f707438368d81b0c9aa56. Reverted in https://github.com/denoland/deno/pull/24574. This reland contains a fix that sends "Accept: */*" header for calls made from "FileFetcher". Absence of this header made downloading source code from JSR broken. This is tested by ensuring this header is present in the test server that servers JSR packages. --------- Co-authored-by: Sean McArthur <sean@seanmonstar.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)
}