use hcloud::apis::configuration::Configuration;
use hcloud::apis::isos_api;
use std::env;
#[tokio::main]
async fn main() -> Result<(), String> {
let api_token = env::args()
.nth(1)
.ok_or("Please provide API token as command line parameter.")?;
let mut configuration = Configuration::new();
configuration.bearer_access_token = Some(api_token);
let mut isos = Vec::new();
let mut next_page = Some(1);
while next_page.is_some() {
let params = isos_api::ListIsosParams {
page: next_page,
per_page: Some(10), ..Default::default()
};
let response = isos_api::list_isos(&configuration, params)
.await
.map_err(|err| format!("API call to list_isos failed: {:?}", err))?;
isos.extend(response.isos);
next_page = response.meta.pagination.next_page
}
println!("Found {} ISOs. Listing IDs and names:", isos.len());
for iso in isos {
println!(
"{}: {}",
iso.id,
iso.name.unwrap_or("<unnamed>".to_string())
);
}
Ok(())
}