cloud_terrastodon_azure 0.35.1

Helpers for interacting with Azure for the Cloud Terrastodon project
use cloud_terrastodon_azure_types::Account;
use cloud_terrastodon_command::CacheKey;
use cloud_terrastodon_command::CommandBuilder;
use cloud_terrastodon_command::CommandKind;
use std::path::PathBuf;
use std::time::Duration;

pub async fn az_account_list() -> eyre::Result<Vec<Account>> {
    let mut cmd = CommandBuilder::new(CommandKind::AzureCLI);
    cmd.args(["account", "list", "--output", "json"]);
    cmd.cache(CacheKey {
        valid_for: Duration::from_secs(30),
        path: PathBuf::from_iter(["az", "account", "list"]),
    });
    let rtn = cmd.run().await?;
    Ok(rtn)
}

#[cfg(test)]
mod test {
    use crate::az_account_list;
    use cloud_terrastodon_command::CacheKey;
    use cloud_terrastodon_command::CommandBuilder;
    use cloud_terrastodon_command::CommandKind;
    use std::path::PathBuf;
    use std::time::Duration;

    #[tokio::test]
    pub async fn it_works() -> eyre::Result<()> {
        let accounts = az_account_list().await?;
        assert_ne!(accounts.as_slice(), []);
        Ok(())
    }

    #[tokio::test]
    pub async fn it_works_raw() -> eyre::Result<()> {
        let mut cmd = CommandBuilder::new(CommandKind::AzureCLI);
        cmd.args(["account", "list", "--output", "json"]);
        cmd.cache(CacheKey {
            valid_for: Duration::from_secs(30),
            path: PathBuf::from_iter(["az", "account", "list"]),
        });
        let rtn = cmd.run_raw().await?;
        assert!(rtn.status == 0);
        Ok(())
    }
}