From 3382e85c5be6fcf9bf79bf618eca7672b150543c Mon Sep 17 00:00:00 2001 From: meilier Date: Fri, 5 Aug 2022 01:00:34 +0800 Subject: [PATCH 3/6] wasmengine could pull public https' repository image --- src/function_store/local_store.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/function_store/local_store.rs b/src/function_store/local_store.rs index d68c451..2afcd96 100644 --- a/src/function_store/local_store.rs +++ b/src/function_store/local_store.rs @@ -1,5 +1,6 @@ use super::pull; use anyhow::{anyhow, Ok, Result}; +use oci_distribution::client::ClientConfig; use oci_distribution::{secrets::RegistryAuth, Client, Reference}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -100,11 +101,13 @@ impl FunctionStore { )); } - let mut client = Client::new(pull::build_client_config(true)); - let reference: Reference = image_name.parse().expect("Not a valid image reference"); + let mut client = Client::new(ClientConfig::default()); + let reference: Reference = image_name + .parse() + .map_err(|err| anyhow::format_err!("Not a valid image reference: {}", err))?; // pull the wasm image into the local func_store_path - pull::pull_wasm( + let pull_result = pull::pull_wasm( &mut client, &RegistryAuth::Anonymous, &reference, @@ -112,6 +115,24 @@ impl FunctionStore { ) .await; + if !pull_result.is_ok() { + let mut client = Client::new(pull::build_client_config(true)); + pull::pull_wasm( + &mut client, + &RegistryAuth::Anonymous, + &reference, + func_store_dir.as_str(), + ) + .await + .map_err(|err| { + anyhow::format_err!( + "Pull image both failed with https auth: {}, and insecure http: {}", + pull_result.unwrap_err(), + err + ) + })?; + } + // only one wasm module file should be in the func_store_dir if read_dir(func_store_dir.clone()).unwrap().count() != 1 { return Err(anyhow!( -- 2.27.0