pub mod client;
pub mod credentials;
pub mod encryption;
#[allow(unused_imports)]
pub use client::CloudClient;
#[allow(unused_imports)]
pub use credentials::{Credentials, CredentialsStore};
#[allow(unused_imports)]
pub use encryption::{decrypt_data, derive_key, encrypt_data};
pub const DEFAULT_CLOUD_URL: &str = "https://app.lore.varalys.com";
pub const KEYRING_SERVICE: &str = "lore-cloud";
pub const KEYRING_API_KEY_USER: &str = "api-key";
pub const KEYRING_ENCRYPTION_KEY_USER: &str = "encryption-key";
#[derive(Debug, thiserror::Error)]
pub enum CloudError {
#[error("Not logged in. Run 'lore login' first.")]
NotLoggedIn,
#[error("Authentication failed: {0}")]
#[allow(dead_code)]
AuthFailed(String),
#[error("Cloud API error: {0}")]
#[allow(dead_code)]
ApiError(String),
#[error("HTTP request failed: {0}")]
HttpError(#[from] reqwest::Error),
#[error("Encryption error: {0}")]
EncryptionError(String),
#[error("Credential storage error: {0}")]
KeyringError(String),
#[error("Encryption key not set. Run 'lore cloud push' to set up encryption.")]
#[allow(dead_code)]
NoEncryptionKey,
#[error("OAuth state mismatch - possible CSRF attack")]
#[allow(dead_code)]
StateMismatch,
#[error("Login timed out waiting for browser authentication")]
#[allow(dead_code)]
LoginTimeout,
#[error("Server error ({status}): {message}")]
ServerError { status: u16, message: String },
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cloud_error_display_not_logged_in() {
let err = CloudError::NotLoggedIn;
assert!(err.to_string().contains("Not logged in"));
}
#[test]
fn test_cloud_error_display_auth_failed() {
let err = CloudError::AuthFailed("invalid token".to_string());
assert!(err.to_string().contains("invalid token"));
}
#[test]
fn test_cloud_error_display_server_error() {
let err = CloudError::ServerError {
status: 500,
message: "Internal error".to_string(),
};
assert!(err.to_string().contains("500"));
assert!(err.to_string().contains("Internal error"));
}
#[test]
fn test_default_cloud_url() {
assert_eq!(DEFAULT_CLOUD_URL, "https://app.lore.varalys.com");
}
#[test]
fn test_keyring_constants() {
assert_eq!(KEYRING_SERVICE, "lore-cloud");
assert_eq!(KEYRING_API_KEY_USER, "api-key");
assert_eq!(KEYRING_ENCRYPTION_KEY_USER, "encryption-key");
}
}