Remove PostgreSQL support: pure SQLite architecture
BREAKING CHANGE: Remove all PostgreSQL functionality Changes: - Remove dependencies: tokio-postgres, postgres from Cargo.toml - Delete files: pg_client.rs (330 lines), sync.rs (370 lines), provider/pg.rs (300 lines) - Remove modules from lib.rs: pg_client, sync - Remove pg module from provider/mod.rs - Remove PostgreSQL sync code from server.rs (lines 126-165) - Remove auth_db field and with_sync() from auth.rs - Simplify SSH server to use SqliteProvider only - Convert sync API endpoints to return 410 Gone with error message - Remove [postgresql] config section from markbase.toml Rationale: - Simplify architecture by using SQLite exclusively - Remove complexity of PostgreSQL synchronization - Reduce dependencies and maintenance burden - SQLite is sufficient for MarkBase use case Code removed: ~1000 lines Files deleted: 3 Files modified: 8
This commit is contained in:
@@ -66,7 +66,6 @@ pub struct AdminLoginResponse {
|
||||
pub struct AuthState {
|
||||
pub sessions: Arc<Mutex<HashMap<String, Session>>>,
|
||||
pub users: Arc<Mutex<HashMap<String, User>>>,
|
||||
pub auth_db: Option<crate::sync::AuthDb>,
|
||||
pub admin_sessions: Arc<Mutex<HashMap<String, AdminSession>>>,
|
||||
pub provider: Option<Arc<dyn DataProvider>>,
|
||||
}
|
||||
@@ -95,19 +94,6 @@ impl AuthState {
|
||||
AuthState {
|
||||
sessions: Arc::new(Mutex::new(HashMap::new())),
|
||||
users: Arc::new(Mutex::new(users)),
|
||||
auth_db: None,
|
||||
admin_sessions: Arc::new(Mutex::new(HashMap::new())),
|
||||
provider: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_sync(auth_db_path: &str) -> Self {
|
||||
let auth_db = crate::sync::AuthDb::new(auth_db_path).ok();
|
||||
|
||||
AuthState {
|
||||
sessions: Arc::new(Mutex::new(HashMap::new())),
|
||||
users: Arc::new(Mutex::new(HashMap::new())),
|
||||
auth_db,
|
||||
admin_sessions: Arc::new(Mutex::new(HashMap::new())),
|
||||
provider: None,
|
||||
}
|
||||
@@ -117,7 +103,6 @@ impl AuthState {
|
||||
AuthState {
|
||||
sessions: Arc::new(Mutex::new(HashMap::new())),
|
||||
users: Arc::new(Mutex::new(HashMap::new())),
|
||||
auth_db: None,
|
||||
admin_sessions: Arc::new(Mutex::new(HashMap::new())),
|
||||
provider: Some(Arc::from(provider)),
|
||||
}
|
||||
@@ -158,30 +143,7 @@ impl AuthState {
|
||||
}
|
||||
|
||||
pub fn admin_login(&self, username: &str, password: &str) -> Option<AdminLoginResponse> {
|
||||
// Try auth_db first (legacy PostgreSQL sync)
|
||||
if let Some(auth_db) = &self.auth_db {
|
||||
match auth_db.get_admin(username) {
|
||||
Ok(Some(admin)) if admin.status == 1 => {
|
||||
if verify(password, &admin.password_hash).unwrap_or(false) {
|
||||
return self.create_admin_session(username, password);
|
||||
} else {
|
||||
log::warn!("Invalid password for admin {}", username);
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Ok(Some(_)) => {
|
||||
log::warn!("Admin {} is not active", username);
|
||||
return None;
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(e) => {
|
||||
log::error!("Failed to get admin {}: {}", username, e);
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: try provider
|
||||
// Use provider if available
|
||||
if let Some(provider) = &self.provider {
|
||||
match provider.get_user(username) {
|
||||
Ok(Some(user)) if user.status == 1 => {
|
||||
@@ -204,7 +166,7 @@ impl AuthState {
|
||||
}
|
||||
}
|
||||
|
||||
log::warn!("Admin {} not found (auth_db + provider)", username);
|
||||
log::warn!("Admin {} not found (provider)", username);
|
||||
None
|
||||
}
|
||||
|
||||
@@ -253,66 +215,13 @@ impl AuthState {
|
||||
}
|
||||
|
||||
pub fn login_with_sync(&self, username: &str, password: &str) -> Option<LoginResponse> {
|
||||
// Prefer provider over auth_db
|
||||
// Use provider if available
|
||||
if let Some(provider) = &self.provider {
|
||||
return self.login_with_provider(&**provider, username, password);
|
||||
}
|
||||
|
||||
if let Some(auth_db) = &self.auth_db {
|
||||
let user = match auth_db.get_user(username) {
|
||||
Ok(Some(user)) => user,
|
||||
Ok(None) => {
|
||||
log::warn!("User {} not found in auth database", username);
|
||||
return None;
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to get user {}: {}", username, e);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
if user.status != 1 {
|
||||
log::warn!("User {} is disabled", username);
|
||||
return None;
|
||||
}
|
||||
|
||||
if verify(password, &user.password_hash).unwrap_or(false) {
|
||||
let groups = auth_db.get_user_groups(username).unwrap_or_default();
|
||||
let permissions = user.permissions.clone();
|
||||
|
||||
let token = Uuid::new_v4().to_string();
|
||||
let now = Utc::now();
|
||||
let expires_at = now + Duration::hours(24);
|
||||
|
||||
let session = Session {
|
||||
token: token.clone(),
|
||||
user_id: username.to_string(),
|
||||
username: username.to_string(),
|
||||
created_at: now.format("%Y-%m-%dT%H:%M:%SZ").to_string(),
|
||||
expires_at: expires_at.format("%Y-%m-%dT%H:%M:%SZ").to_string(),
|
||||
groups: groups.clone(),
|
||||
permissions: permissions.clone(),
|
||||
};
|
||||
|
||||
let mut sessions = self.sessions.lock().unwrap();
|
||||
sessions.insert(token.clone(), session);
|
||||
|
||||
log::info!("User {} logged in successfully", username);
|
||||
|
||||
Some(LoginResponse {
|
||||
token,
|
||||
expires_at: expires_at.format("%Y-%m-%dT%H:%M:%SZ").to_string(),
|
||||
user_id: username.to_string(),
|
||||
groups,
|
||||
permissions,
|
||||
})
|
||||
} else {
|
||||
log::warn!("Invalid password for user {}", username);
|
||||
None
|
||||
}
|
||||
} else {
|
||||
self.login(username, password)
|
||||
}
|
||||
// Fallback to in-memory users
|
||||
self.login(username, password)
|
||||
}
|
||||
|
||||
fn login_with_provider(
|
||||
|
||||
Reference in New Issue
Block a user