mirror of
https://github.com/house-of-vanity/khm.git
synced 2025-08-21 14:27:14 +00:00
Fix GUI feature declaration
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2672,7 +2672,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "khm"
|
||||
version = "0.6.3"
|
||||
version = "0.7.1"
|
||||
dependencies = [
|
||||
"actix-web",
|
||||
"base64 0.21.7",
|
||||
|
@@ -1,5 +1,9 @@
|
||||
#[cfg(feature = "gui")]
|
||||
mod state;
|
||||
#[cfg(feature = "gui")]
|
||||
mod ui;
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
pub use state::*;
|
||||
#[cfg(feature = "gui")]
|
||||
pub use ui::*;
|
||||
|
@@ -12,6 +12,7 @@ pub struct SshKey {
|
||||
}
|
||||
|
||||
/// Test connection to KHM server
|
||||
#[cfg(feature = "gui")]
|
||||
pub async fn test_connection(
|
||||
host: String,
|
||||
flow: String,
|
||||
@@ -52,6 +53,7 @@ pub async fn test_connection(
|
||||
}
|
||||
|
||||
/// Fetch all SSH keys including deprecated ones
|
||||
#[cfg(feature = "gui")]
|
||||
pub async fn fetch_keys(
|
||||
host: String,
|
||||
flow: String,
|
||||
@@ -95,6 +97,7 @@ pub async fn fetch_keys(
|
||||
}
|
||||
|
||||
/// Deprecate a key for a specific server
|
||||
#[cfg(feature = "gui")]
|
||||
pub async fn deprecate_key(
|
||||
host: String,
|
||||
flow: String,
|
||||
@@ -133,6 +136,7 @@ pub async fn deprecate_key(
|
||||
}
|
||||
|
||||
/// Restore a key for a specific server
|
||||
#[cfg(feature = "gui")]
|
||||
pub async fn restore_key(
|
||||
host: String,
|
||||
flow: String,
|
||||
@@ -171,6 +175,7 @@ pub async fn restore_key(
|
||||
}
|
||||
|
||||
/// Delete a key permanently for a specific server
|
||||
#[cfg(feature = "gui")]
|
||||
pub async fn delete_key(
|
||||
host: String,
|
||||
flow: String,
|
||||
@@ -212,6 +217,7 @@ pub async fn delete_key(
|
||||
}
|
||||
|
||||
/// Bulk deprecate multiple servers
|
||||
#[cfg(feature = "gui")]
|
||||
pub async fn bulk_deprecate_servers(
|
||||
host: String,
|
||||
flow: String,
|
||||
@@ -244,6 +250,7 @@ pub async fn bulk_deprecate_servers(
|
||||
}
|
||||
|
||||
/// Bulk restore multiple servers
|
||||
#[cfg(feature = "gui")]
|
||||
pub async fn bulk_restore_servers(
|
||||
host: String,
|
||||
flow: String,
|
||||
@@ -276,6 +283,7 @@ pub async fn bulk_restore_servers(
|
||||
}
|
||||
|
||||
/// Perform manual sync operation
|
||||
#[cfg(feature = "gui")]
|
||||
pub async fn perform_manual_sync(settings: KhmSettings) -> Result<String, String> {
|
||||
match perform_sync(&settings).await {
|
||||
Ok(keys_count) => Ok(format!(
|
||||
@@ -288,6 +296,7 @@ pub async fn perform_manual_sync(settings: KhmSettings) -> Result<String, String
|
||||
|
||||
// Helper functions
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
fn create_http_client() -> Result<Client, String> {
|
||||
Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(30))
|
||||
@@ -296,6 +305,7 @@ fn create_http_client() -> Result<Client, String> {
|
||||
.map_err(|e| format!("Failed to create HTTP client: {}", e))
|
||||
}
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
fn add_auth_if_needed(
|
||||
request: reqwest::RequestBuilder,
|
||||
basic_auth: &str,
|
||||
@@ -312,6 +322,7 @@ fn add_auth_if_needed(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
fn check_response_status(response: &reqwest::Response) -> Result<(), String> {
|
||||
let status = response.status().as_u16();
|
||||
|
||||
@@ -336,6 +347,7 @@ fn check_response_status(response: &reqwest::Response) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
fn check_html_response(body: &str) -> Result<(), String> {
|
||||
if body.trim_start().starts_with("<!DOCTYPE") || body.trim_start().starts_with("<html") {
|
||||
return Err("Server returned HTML page instead of JSON. This usually means authentication is required or the endpoint is incorrect.".to_string());
|
||||
@@ -343,6 +355,7 @@ fn check_html_response(body: &str) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
fn parse_api_response(body: &str, default_message: &str) -> Result<String, String> {
|
||||
if let Ok(json_response) = serde_json::from_str::<serde_json::Value>(body) {
|
||||
if let Some(message) = json_response.get("message").and_then(|v| v.as_str()) {
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#[cfg(feature = "gui")]
|
||||
mod client;
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
pub use client::*;
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#[cfg(feature = "gui")]
|
||||
mod settings;
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
pub use settings::*;
|
||||
|
@@ -1,9 +1,15 @@
|
||||
#[cfg(feature = "gui")]
|
||||
use dirs::home_dir;
|
||||
#[cfg(feature = "gui")]
|
||||
use log::{debug, error, info};
|
||||
#[cfg(feature = "gui")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cfg(feature = "gui")]
|
||||
use std::fs;
|
||||
#[cfg(feature = "gui")]
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct KhmSettings {
|
||||
pub host: String,
|
||||
@@ -14,6 +20,7 @@ pub struct KhmSettings {
|
||||
pub auto_sync_interval_minutes: u32,
|
||||
}
|
||||
|
||||
#[cfg(feature = "gui")]
|
||||
impl Default for KhmSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -28,6 +35,7 @@ impl Default for KhmSettings {
|
||||
}
|
||||
|
||||
/// Get default known_hosts file path based on OS
|
||||
#[cfg(feature = "gui")]
|
||||
fn get_default_known_hosts_path() -> String {
|
||||
if let Some(home) = home_dir() {
|
||||
let ssh_dir = home.join(".ssh");
|
||||
@@ -39,6 +47,7 @@ fn get_default_known_hosts_path() -> String {
|
||||
}
|
||||
|
||||
/// Get configuration file path
|
||||
#[cfg(feature = "gui")]
|
||||
pub fn get_config_path() -> PathBuf {
|
||||
let mut path = home_dir().expect("Could not find home directory");
|
||||
path.push(".khm");
|
||||
@@ -48,6 +57,7 @@ pub fn get_config_path() -> PathBuf {
|
||||
}
|
||||
|
||||
/// Load settings from configuration file
|
||||
#[cfg(feature = "gui")]
|
||||
pub fn load_settings() -> KhmSettings {
|
||||
let path = get_config_path();
|
||||
match fs::read_to_string(&path) {
|
||||
@@ -72,6 +82,7 @@ pub fn load_settings() -> KhmSettings {
|
||||
}
|
||||
|
||||
/// Save settings to configuration file
|
||||
#[cfg(feature = "gui")]
|
||||
pub fn save_settings(settings: &KhmSettings) -> Result<(), std::io::Error> {
|
||||
let path = get_config_path();
|
||||
let json = serde_json::to_string_pretty(settings)?;
|
||||
@@ -81,6 +92,7 @@ pub fn save_settings(settings: &KhmSettings) -> Result<(), std::io::Error> {
|
||||
}
|
||||
|
||||
/// Expand path with ~ substitution
|
||||
#[cfg(feature = "gui")]
|
||||
pub fn expand_path(path: &str) -> String {
|
||||
if path.starts_with("~/") {
|
||||
if let Some(home) = home_dir() {
|
||||
@@ -91,6 +103,7 @@ pub fn expand_path(path: &str) -> String {
|
||||
}
|
||||
|
||||
/// Perform sync operation using KHM client logic
|
||||
#[cfg(feature = "gui")]
|
||||
pub async fn perform_sync(settings: &KhmSettings) -> Result<usize, std::io::Error> {
|
||||
use crate::Args;
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#[cfg(feature = "gui")]
|
||||
use log::info;
|
||||
|
||||
// Modules
|
||||
#[cfg(feature = "gui")]
|
||||
mod admin;
|
||||
mod api;
|
||||
mod common;
|
||||
|
Reference in New Issue
Block a user