Skip to content

Commit

Permalink
feat(initramfs): accept other media types
Browse files Browse the repository at this point in the history
We used to only accept the old ManifestV1 response type. However, most
images don't come with this manifest type anymore, but instead has a
ManifestV2 List / OCI Spec'd manifest.

This commit handles those manifests types:
- OCI List
- ManifestV2 List
- ManifestV2

Signed-off-by: Simon LUCIDO <simon.lucido@etu.umontpellier.fr>
Signed-off-by: Simon Lucido <simon34280@gmail.com>
  • Loading branch information
lucido-simon committed Jan 16, 2024
1 parent d24989b commit 8b7c0e9
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 43 deletions.
20 changes: 15 additions & 5 deletions initramfs/src/httpclient.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
use anyhow::{anyhow, Result};
use reqwest::{Client, Response};

pub async fn run_get_request(url: &str, token: Option<&str>) -> Result<Response> {
let res = match token {
pub async fn run_get_request(
url: &str,
token: Option<&String>,
headers: Vec<(String, String)>,
) -> Result<Response> {
let mut res = match token {
Some(token) => Client::new().get(url).bearer_auth(token),
None => Client::new().get(url),
};

for (key, value) in headers {
res = res.header(key, value);
}
.send()
.await
.map_err(|e| anyhow!(e).context(format!("Failed to run request to {}", url)))?;

let res = res
.send()
.await
.map_err(|e| anyhow!(e).context(format!("Failed to run request to {}", url)))?;

if !res.status().is_success() {
return Err(anyhow!(res.text().await.unwrap_or_default())
Expand Down
2 changes: 1 addition & 1 deletion initramfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
debug!("Running cli with arguments : {:?}", args);

let registry = Registry::new(&args.registry_url, &args.auth_url);
let mut registry = Registry::new(&args.registry_url, &args.auth_url);

info!("Downloading image {}", &args.image);
let image = registry.get_image(&args.image).await?;
Expand Down
Loading

0 comments on commit 8b7c0e9

Please sign in to comment.