[F] Webhook issues

This commit is contained in:
2026-05-09 23:44:18 +00:00
parent 44b1865b15
commit 260f42b973
13 changed files with 411 additions and 112 deletions
+6 -18
View File
@@ -1,10 +1,8 @@
use std::fmt::Display;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::sync::mpsc;
use std::thread;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use std::time::Duration;
use anyhow::{Context, Result, anyhow};
use console::{Term, style};
@@ -284,7 +282,7 @@ fn prompt_webhook_setup_styled(config: &mut Config, theme: &ColorfulTheme) -> Re
config.webhook = Some(WebhookConfig {
install: true,
url,
secret: TokenConfig::Value(generate_webhook_secret()),
secret: TokenConfig::Value(generate_webhook_secret()?),
full_sync_interval_minutes,
reachability_check_interval_minutes: Some(15),
});
@@ -1340,25 +1338,15 @@ fn validate_url(value: &str) -> std::result::Result<(), String> {
}
}
fn generate_webhook_secret() -> String {
fn generate_webhook_secret() -> Result<String> {
let mut bytes = [0_u8; 32];
if File::open("/dev/urandom")
.and_then(|mut file| file.read_exact(&mut bytes))
.is_err()
{
let nanos = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|duration| duration.as_nanos())
.unwrap_or_default();
for (index, byte) in bytes.iter_mut().enumerate() {
*byte = ((nanos >> ((index % 16) * 8)) & 0xff) as u8;
}
}
getrandom::fill(&mut bytes)
.map_err(|error| anyhow!("failed to generate webhook secret: {error}"))?;
let mut output = String::with_capacity(bytes.len() * 2);
for byte in bytes {
output.push_str(&format!("{byte:02x}"));
}
output
Ok(output)
}
#[cfg(test)]