1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Logout command - remove cloud service credentials.
//!
//! Deletes stored API keys and encryption keys from the keychain
//! and any fallback credential files.
use anyhow::{Context, Result};
use colored::Colorize;
use crate::cloud::credentials::CredentialsStore;
use crate::config::Config;
/// Arguments for the logout command.
#[derive(clap::Args)]
#[command(after_help = "EXAMPLES:\n \
lore logout Log out of Lore cloud")]
pub struct Args {}
/// Executes the logout command.
///
/// Removes all stored credentials and encryption keys.
pub fn run(_args: Args) -> Result<()> {
let config = Config::load()?;
let store = CredentialsStore::with_keychain(config.use_keychain);
// Check if logged in
match store.load().context("Failed to check login status")? {
Some(creds) => {
// Delete credentials
store.delete().context("Failed to delete credentials")?;
// Also delete encryption key
if let Err(e) = store.delete_encryption_key() {
tracing::debug!("Could not delete encryption key: {e}");
}
println!("Logged out from {} ({})", creds.email.cyan(), creds.plan);
}
None => {
println!("{}", "Not currently logged in.".yellow());
}
}
Ok(())
}
#[cfg(test)]
mod tests {
// Login/logout tests require credential storage which may not be available
// in all test environments. The functionality is tested through integration
// tests that can set up appropriate mocks.
}