MCPcopy Create free account
hub / github.com/cargo-lambda/cargo-lambda / download_example

Function download_example

crates/cargo-lambda-invoke/src/lib.rs:303–334  ·  view source on GitHub ↗
(
    name: &str,
    cache: Option<PathBuf>,
    authority: Option<&str>,
)

Source from the content-addressed store, hash-verified

301}
302
303async fn download_example(
304 name: &str,
305 cache: Option<PathBuf>,
306 authority: Option<&str>,
307) -> Result<String> {
308 let authority = authority.unwrap_or(EXAMPLES_URL);
309 let target = format!("{authority}/{name}");
310
311 tracing::debug!(?target, "downloading remote example");
312 let response = reqwest::get(&target)
313 .await
314 .into_diagnostic()
315 .wrap_err("error dowloading example data")?;
316
317 if response.status() != StatusCode::OK {
318 Err(InvokeError::ExampleDownloadFailed(target, response).into())
319 } else {
320 let content = response
321 .text()
322 .await
323 .into_diagnostic()
324 .wrap_err("error reading example data")?;
325
326 if let Some(cache) = cache {
327 tracing::debug!(?cache, "storing example in cache");
328 create_dir_all(cache.parent().unwrap()).into_diagnostic()?;
329 let mut dest = File::create(cache).into_diagnostic()?;
330 copy(&mut content.as_bytes(), &mut dest).into_diagnostic()?;
331 }
332 Ok(content)
333 }
334}
335
336fn parse_invoke_ip_address(address: &str) -> Result<String> {
337 let invoke_address = IpAddr::from_str(address).map_err(|e| miette::miette!(e))?;

Callers 3

runMethod · 0.85
test_download_exampleFunction · 0.85

Calls 1

createFunction · 0.85

Tested by 2

test_download_exampleFunction · 0.68