1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//! Cross-section dependency validation.
//!
//! This module contains validation functions that check dependencies and relationships
//! between different configuration sections. These validators ensure that related
//! configuration values are consistent and compatible with each other.
use crate::;
/// Validate a port number for server configuration.
///
/// Port must be in the range 1-65535. While ports 1-1023 are privileged and may require
/// special permissions on some systems, they are still valid port numbers.
///
/// # Arguments
///
/// * `port` - The port number to validate
///
/// # Returns
///
/// `Ok(())` if the port is valid, or a `ValidationError` with details about valid ranges.
///
/// # Examples
///
/// ```rust
/// use kreuzberg::core::config_validation::validate_port;
///
/// assert!(validate_port(8000).is_ok());
/// assert!(validate_port(80).is_ok());
/// assert!(validate_port(1).is_ok());
/// assert!(validate_port(65535).is_ok());
/// assert!(validate_port(0).is_err());
/// ```
/// Validate a host/IP address string for server configuration.
///
/// Accepts valid IPv4 addresses (e.g., "127.0.0.1", "0.0.0.0"), valid IPv6 addresses
/// (e.g., "::1", "::"), and hostnames (e.g., "localhost", "example.com").
///
/// # Arguments
///
/// * `host` - The host/IP address string to validate
///
/// # Returns
///
/// `Ok(())` if the host is valid, or a `ValidationError` with details about valid formats.
///
/// # Examples
///
/// ```rust
/// use kreuzberg::core::config_validation::validate_host;
///
/// assert!(validate_host("127.0.0.1").is_ok());
/// assert!(validate_host("0.0.0.0").is_ok());
/// assert!(validate_host("::1").is_ok());
/// assert!(validate_host("::").is_ok());
/// assert!(validate_host("localhost").is_ok());
/// assert!(validate_host("example.com").is_ok());
/// assert!(validate_host("").is_err());
/// ```
/// Validate a CORS (Cross-Origin Resource Sharing) origin URL.
///
/// Accepts valid HTTP/HTTPS URLs (e.g., "https://example.com") or the wildcard "*"
/// to allow all origins. URLs must start with "http://" or "https://", or be exactly "*".
///
/// # Arguments
///
/// * `origin` - The CORS origin URL to validate
///
/// # Returns
///
/// `Ok(())` if the origin is valid, or a `ValidationError` with details about valid formats.
///
/// # Examples
///
/// ```rust
/// use kreuzberg::core::config_validation::validate_cors_origin;
///
/// assert!(validate_cors_origin("https://example.com").is_ok());
/// assert!(validate_cors_origin("http://localhost:3000").is_ok());
/// assert!(validate_cors_origin("*").is_ok());
/// assert!(validate_cors_origin("not-a-url").is_err());
/// assert!(validate_cors_origin("ftp://example.com").is_err());
/// ```
/// Validate an upload size limit for server configuration.
///
/// Upload size must be greater than 0 (measured in bytes).
///
/// # Arguments
///
/// * `size` - The maximum upload size in bytes to validate
///
/// # Returns
///
/// `Ok(())` if the size is valid, or a `ValidationError` with details about constraints.
///
/// # Examples
///
/// ```rust
/// use kreuzberg::core::config_validation::validate_upload_size;
///
/// assert!(validate_upload_size(1024).is_ok());
/// assert!(validate_upload_size(1_000_000).is_ok());
/// assert!(validate_upload_size(0).is_err());
/// ```