Files
codegenerator/codegenerator/templates/rust_cli/impl_image_download.j2
Artem Goncharov 7721de37cf Address remaining panic in the generated code
Image download was missed in the previous change of eliminating panics
from the generated code.

Change-Id: I0f4c3cabe0fb091c5e2c40d55d8ffdfcabb05184
Signed-off-by: Artem Goncharov <artem.goncharov@gmail.com>
2025-11-17 15:58:02 +01:00

36 lines
1.4 KiB
Django/Jinja

let find_ep = find::Request::builder()
.id(&self.path.image_id)
.build()
.map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
let image_data: serde_json::Value = find(find_ep).query_async(client).await?;
let image_id = image_data["id"]
.as_str()
.ok_or_else(|| eyre::eyre!("image ID must be a string"))?
.to_string();
let image_name = image_data["name"]
.as_str()
.ok_or_else(|| eyre::eyre!("image name must be a string"))?
.to_string();
let ep = download::Request::builder()
.image_id(image_id)
.build()
.map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
let (headers, data) = ep.download_async(client).await?;
let size: u64 = headers
.get("content-length")
.and_then(|x| {
x.to_str()
.inspect_err(|e| {
tracing::warn!("content-length header cannot be treated as string: {}", e)
})
.ok()
})
.unwrap_or("0")
.parse()
.inspect_err(|e| tracing::warn!("content-length header mut represent u64 number: {}", e))
.unwrap_or_default();
download_file(self.file.clone().unwrap_or(image_name), size, data).await?;