systemprompt_cloud/
logout.rs1use std::path::PathBuf;
10
11use crate::cli_session::SessionStore;
12use crate::error::CloudResult;
13use crate::paths::{CloudPath, CloudPaths};
14
15#[derive(Debug, Clone, Default)]
16pub struct ClearedCloudState {
17 pub credentials_path: Option<PathBuf>,
18 pub operator_credentials_path: Option<PathBuf>,
19 pub tenants_path: Option<PathBuf>,
20 pub tenant_sessions_removed: usize,
21}
22
23pub fn clear_cloud_state(cloud_paths: &CloudPaths) -> CloudResult<ClearedCloudState> {
24 let mut cleared = ClearedCloudState::default();
25
26 let credentials_path = cloud_paths.resolve(CloudPath::Credentials);
27 if credentials_path.exists() {
28 std::fs::remove_file(&credentials_path)?;
29 cleared.credentials_path = Some(credentials_path);
30 }
31
32 let operator_path = cloud_paths.resolve(CloudPath::OperatorCredentials);
33 if operator_path.exists() {
34 std::fs::remove_file(&operator_path)?;
35 cleared.operator_credentials_path = Some(operator_path);
36 }
37
38 let tenants_path = cloud_paths.resolve(CloudPath::Tenants);
39 if tenants_path.exists() {
40 std::fs::remove_file(&tenants_path)?;
41 cleared.tenants_path = Some(tenants_path);
42 }
43
44 let sessions_dir = cloud_paths.resolve(CloudPath::SessionsDir);
45 match SessionStore::load(&sessions_dir) {
46 Ok(Some(mut store)) => {
47 let removed = store.remove_tenant_sessions();
48 if removed > 0 {
49 store.save(&sessions_dir)?;
50 cleared.tenant_sessions_removed = removed;
51 }
52 },
53 Ok(None) => {},
54 Err(e) => {
55 tracing::warn!(error = %e, "Skipping session cleanup for unreadable session store");
56 },
57 }
58
59 Ok(cleared)
60}