oxyde_cloud_cli/
api_key.rs

1use anyhow::{Context, Result};
2use keyring::Entry;
3
4#[inline(always)]
5pub fn api_key_entry() -> Result<Entry> {
6    Entry::new("oxyde-cloud", "api-key").context("Failed to create keyring entry for API key")
7}
8
9pub fn api_key() -> Result<String> {
10    if let Ok(api_key) = std::env::var("OXYDE_CLOUD_API_KEY") {
11        Ok(api_key)
12    } else {
13        api_key_entry()?.get_password().context(
14            "Failed to get API key from keyring. Make sure you're logged in with 'oxy login'",
15        )
16    }
17}