upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-01-12 21:20:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-01-12 21:21:53 +0000
commit1948312d40f34fca868d1ef6d6d94e165c09738c (patch)
treef25f930785145023be6fe33e52904a5d8383a62d /src/http
parent82b56c37b26a2fac1a294873e539b19b9325dca6 (diff)
refactor(config): validate eagerly at startup and remove Result from runtime config methods
Refactors configuration validation to fail fast on fatal errors at startup while gracefully handling recoverable issues (e.g., malformed whitelist entries). Changes: - Add Config::validate() for eager validation called immediately after load - Remove Result<> from archive_config() and repository_config() methods - WhitelistEntry::parse_whitelist() skips invalid entries with warnings - Validate relay_owner_nsec format in Config::validate() - Update all call sites to remove Result handling from config getters Benefits: - Fatal config errors (incompatible settings) fail at startup, not runtime - Recoverable errors (bad whitelist entries) logged as warnings and skipped - No Result handling scattered throughout runtime code after validation - Config methods safe to call without error handling after validate() Testing: - Add 7 new tests for validation edge cases and error handling - Total config tests: 40 (up from 33) - All 320 library tests passing Breaking change: Config users must call config.validate() after Config::load() to ensure configuration is valid. This is enforced in main.rs.
Diffstat (limited to 'src/http')
-rw-r--r--src/http/nip11.rs33
1 files changed, 10 insertions, 23 deletions
diff --git a/src/http/nip11.rs b/src/http/nip11.rs
index ff7b8df..7c58175 100644
--- a/src/http/nip11.rs
+++ b/src/http/nip11.rs
@@ -56,16 +56,10 @@ pub struct RelayInformationDocument {
56impl RelayInformationDocument { 56impl RelayInformationDocument {
57 /// Create NIP-11 relay information document from configuration 57 /// Create NIP-11 relay information document from configuration
58 pub fn from_config(config: &Config) -> Self { 58 pub fn from_config(config: &Config) -> Self {
59 // Determine if archive mode is enabled 59 // Get validated configuration (config.validate() must be called at startup)
60 let archive_config = config.archive_config().ok(); 60 let archive_config = config.archive_config();
61 let archive_enabled = archive_config 61 let archive_enabled = archive_config.enabled();
62 .as_ref() 62 let archive_read_only = archive_config.read_only;
63 .map(|ac| ac.enabled())
64 .unwrap_or(false);
65 let archive_read_only = archive_config
66 .as_ref()
67 .map(|ac| ac.read_only)
68 .unwrap_or(false);
69 63
70 // Build supported_grasps list 64 // Build supported_grasps list
71 let mut supported_grasps = vec!["GRASP-01".to_string()]; 65 let mut supported_grasps = vec!["GRASP-01".to_string()];
@@ -75,22 +69,15 @@ impl RelayInformationDocument {
75 supported_grasps.push("GRASP-02".to_string()); 69 supported_grasps.push("GRASP-02".to_string());
76 70
77 // Build curation field for archive read-only mode or repository whitelist 71 // Build curation field for archive read-only mode or repository whitelist
78 let repository_config = config.repository_config().ok(); 72 let repository_config = config.repository_config();
79 let repository_whitelist_enabled = repository_config 73 let repository_whitelist_enabled = repository_config.enabled();
80 .as_ref()
81 .map(|rc| rc.enabled())
82 .unwrap_or(false);
83 74
84 let curation = if archive_read_only { 75 let curation = if archive_read_only {
85 // Archive read-only mode (GRASP-05 only) 76 // Archive read-only mode (GRASP-05 only)
86 if let Some(ref ac) = archive_config { 77 if archive_config.archive_all {
87 if ac.archive_all { 78 Some("Read-only sync of all repositories found on network".to_string())
88 Some("Read-only sync of all repositories found on network".to_string()) 79 } else if !archive_config.whitelist.is_empty() {
89 } else if !ac.whitelist.is_empty() { 80 Some("Read-only sync of whitelisted repositories and maintainers".to_string())
90 Some("Read-only sync of whitelisted repositories and maintainers".to_string())
91 } else {
92 None
93 }
94 } else { 81 } else {
95 None 82 None
96 } 83 }