switchgear_testing/credentials/
mod.rs

1use anyhow::Context;
2use flate2::read::GzDecoder;
3use std::fs;
4use std::path::Path;
5use tar::Archive;
6
7pub mod db;
8pub mod lightning;
9
10pub fn download_credentials(credentials_dir: &Path, credentials_url: &str) -> anyhow::Result<()> {
11    let download_path = credentials_dir.join("credentials.tar.gz");
12    let response = ureq::get(credentials_url)
13        .call()
14        .with_context(|| format!("Downloading credentials from {}", credentials_url))?;
15
16    let bytes = response
17        .into_body()
18        .read_to_vec()
19        .with_context(|| format!("Downloading credentials from {}", credentials_url))?;
20
21    fs::write(&download_path, &bytes)
22        .with_context(|| format!("Downloading credentials from {}", credentials_url))?;
23
24    let tar_gz = fs::File::open(&download_path)
25        .with_context(|| format!("Downloading credentials from {}", credentials_url))?;
26
27    let tar = GzDecoder::new(tar_gz);
28    let mut archive = Archive::new(tar);
29    archive
30        .unpack(credentials_dir)
31        .with_context(|| format!("Downloading credentials from {}", credentials_url))?;
32    Ok(())
33}