| 181 | |
| 182 | #[tracing::instrument(target = "cargo_lambda")] |
| 183 | async fn download_zip_template(url: &str, template_root: &Path) -> Result<PathBuf> { |
| 184 | tracing::debug!("downloading template"); |
| 185 | |
| 186 | let response = reqwest::get(url).await.into_diagnostic()?; |
| 187 | if response.status() != reqwest::StatusCode::OK { |
| 188 | return Err(miette::miette!( |
| 189 | "error downloading template from {} - {}", |
| 190 | url, |
| 191 | response.text().await.into_diagnostic()? |
| 192 | )); |
| 193 | } |
| 194 | |
| 195 | let mut bytes = Cursor::new(response.bytes().await.into_diagnostic()?); |
| 196 | |
| 197 | let tmp_file = template_root.join("cargo-lambda-template.zip"); |
| 198 | let mut writer = File::create(&tmp_file) |
| 199 | .into_diagnostic() |
| 200 | .wrap_err_with(|| format!("unable to create file: {:?}", &tmp_file))?; |
| 201 | copy(&mut bytes, &mut writer).into_diagnostic()?; |
| 202 | |
| 203 | Ok(tmp_file) |
| 204 | } |
| 205 | |
| 206 | #[tracing::instrument(target = "cargo_lambda")] |
| 207 | fn unzip_template(file: &Path, path: &Path) -> Result<PathBuf> { |