54 lines
1.3 KiB
Markdown
54 lines
1.3 KiB
Markdown
|
|
# Platform Validators
|
||
|
|
|
||
|
|
Reusable validation functions for configuration values.
|
||
|
|
|
||
|
|
## Validators
|
||
|
|
|
||
|
|
### Port Validator (`port-validator.ncl`)
|
||
|
|
|
||
|
|
Validates port numbers:
|
||
|
|
- Valid range: 1024-65535 (excludes system ports < 1024)
|
||
|
|
- Checks for unreserved ports
|
||
|
|
- Predicate functions for validation
|
||
|
|
|
||
|
|
Functions:
|
||
|
|
- `is_valid_port(port)` - Returns bool
|
||
|
|
- `is_unreserved_port(port)` - Returns bool
|
||
|
|
- `validate_port(port)` - Returns {valid, error}
|
||
|
|
- `is_system_port(port)` - Returns bool
|
||
|
|
|
||
|
|
### Budget Validator (`budget-validator.ncl`)
|
||
|
|
|
||
|
|
Validates cost tracking configuration:
|
||
|
|
- Role budget limits (must be > 0)
|
||
|
|
- Threshold percentages (0-100)
|
||
|
|
- Budget windows (daily/weekly/monthly)
|
||
|
|
- Complete budget limit validation
|
||
|
|
|
||
|
|
Functions:
|
||
|
|
- `is_valid_budget(cents)` - Returns bool
|
||
|
|
- `is_valid_threshold(percent)` - Returns bool
|
||
|
|
- `is_valid_window(window)` - Returns bool
|
||
|
|
- `validate_role_limits(limits)` - Returns {valid, errors}
|
||
|
|
- `validate_threshold(percent)` - Returns {valid, error}
|
||
|
|
|
||
|
|
## Usage Pattern
|
||
|
|
|
||
|
|
```nickel
|
||
|
|
let port_validator = import "validators/port-validator.ncl" in
|
||
|
|
|
||
|
|
assert port_validator.is_valid_port 8080
|
||
|
|
|
||
|
|
let result = port_validator.validate_port 9001
|
||
|
|
if result.valid then
|
||
|
|
"Port OK"
|
||
|
|
else
|
||
|
|
"Port error: %{result.error}"
|
||
|
|
```
|
||
|
|
|
||
|
|
## References
|
||
|
|
|
||
|
|
- Parent: `../README.md`
|
||
|
|
- Constraints: `../constraints/README.md`
|
||
|
|
- Values: `../values/README.md`
|