feat(config): migrate configuration loading to config-rs #68

Merged
Lochnair merged 9 commits from feature/config into master 2026-08-07 09:10:14 +00:00
Lochnair commented 2026-08-07 08:45:12 +00:00 (Migrated from github.com)

Summary

This PR replaces the legacy hand-written configuration loader with a typed
Settings model using config-rs and Serde.

Key changes:

  • Configuration is now parsed/deserialized through config-rs + Serde instead of
    manually reading individual environment/UCI values.

  • Configuration sources are loaded in this order:

    1. UCI
    2. /etc/sqm-autorate-rust/config.toml
    3. environment variables

    Later sources override earlier ones.

  • Environment variables now mirror the nested settings structure using __ as
    the section separator, for example:
    SQMA_NETWORK__DOWNLOAD_BASE_KBITS and
    SQMA_ADVANCED_SETTINGS__DRY_RUN.
    The old flat environment variable names are not preserved.

  • UCI loading now reads the package generically and uses schema metadata derived
    from the Settings structs to map known UCI sections/options into config-rs.

  • Boolean settings accept both native booleans and common UCI values such as
    1/0, yes/no, on/off, and enabled/disabled.

  • Settings are validated before startup. Invalid values now produce errors
    instead of being silently corrected; suspicious but valid values may produce
    warnings.

  • Reflector lists are now parsed using the csv crate rather than manual string
    splitting.

  • The old Config type has been removed and runtime components now use the
    nested Settings structure directly.

  • UCI can be built vendored for development/cross-compilation, while
    Linux/OpenWrt remains the production-supported target.

## Summary This PR replaces the legacy hand-written configuration loader with a typed `Settings` model using config-rs and Serde. Key changes: - Configuration is now parsed/deserialized through config-rs + Serde instead of manually reading individual environment/UCI values. - Configuration sources are loaded in this order: 1. UCI 2. `/etc/sqm-autorate-rust/config.toml` 3. environment variables Later sources override earlier ones. - Environment variables now mirror the nested settings structure using `__` as the section separator, for example: `SQMA_NETWORK__DOWNLOAD_BASE_KBITS` and `SQMA_ADVANCED_SETTINGS__DRY_RUN`. The old flat environment variable names are not preserved. - UCI loading now reads the package generically and uses schema metadata derived from the `Settings` structs to map known UCI sections/options into config-rs. - Boolean settings accept both native booleans and common UCI values such as `1/0`, `yes/no`, `on/off`, and `enabled/disabled`. - Settings are validated before startup. Invalid values now produce errors instead of being silently corrected; suspicious but valid values may produce warnings. - Reflector lists are now parsed using the `csv` crate rather than manual string splitting. - The old `Config` type has been removed and runtime components now use the nested `Settings` structure directly. - UCI can be built vendored for development/cross-compilation, while Linux/OpenWrt remains the production-supported target.
github-advanced-security[bot] (Migrated from github.com) reviewed 2026-08-07 08:47:18 +00:00
@@ -0,0 +1,347 @@
// SPDX-FileCopyrightText: 2026-Present Nils Andreas Svee mailto:contact@lochnair.net (github @Lochnair)
github-advanced-security[bot] (Migrated from github.com) commented 2026-08-07 08:47:18 +00:00

clippy /

unneeded return statement

Show more details

## clippy / unneeded `return` statement [Show more details](https://github.com/Lochnair/sqm-autorate-rust/security/code-scanning/18)
github-advanced-security[bot] (Migrated from github.com) reviewed 2026-08-07 09:00:23 +00:00
@@ -0,0 +93,4 @@
impl FromStr for MeasurementType {
type Err = ConfigError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
github-advanced-security[bot] (Migrated from github.com) commented 2026-08-07 09:00:22 +00:00

clippy /

mismatched types

Show more details

## clippy / mismatched types [Show more details](https://github.com/Lochnair/sqm-autorate-rust/security/code-scanning/20)
github-advanced-security[bot] (Migrated from github.com) commented 2026-08-07 09:00:23 +00:00

clippy /

mismatched types

Show more details

## clippy / mismatched types [Show more details](https://github.com/Lochnair/sqm-autorate-rust/security/code-scanning/19)
Sign in to join this conversation.