-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: enrich field types in configuration structs #854
Merged
josecelano
merged 8 commits into
torrust:develop
from
josecelano:852-config-overhaul-replace-primitive-types-in-configuration-with-reacher-types
May 10, 2024
Merged
Refactor: enrich field types in configuration structs #854
josecelano
merged 8 commits into
torrust:develop
from
josecelano:852-config-overhaul-replace-primitive-types-in-configuration-with-reacher-types
May 10, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #854 +/- ##
===========================================
- Coverage 78.76% 78.75% -0.01%
===========================================
Files 168 169 +1
Lines 9291 9293 +2
===========================================
+ Hits 7318 7319 +1
- Misses 1973 1974 +1 ☔ View full report in Codecov by Sentry. |
josecelano
force-pushed
the
852-config-overhaul-replace-primitive-types-in-configuration-with-reacher-types
branch
from
May 10, 2024 12:54
6cafec5
to
7b3330a
Compare
josecelano
force-pushed
the
852-config-overhaul-replace-primitive-types-in-configuration-with-reacher-types
branch
from
May 10, 2024 13:02
7b3330a
to
7002f8a
Compare
If the next major config version the `TslConfig` shoud always contain valid file paths and the whole field should be optional in the parent strcut `HttpTracker`: ```rust pub struct HttpTracker { pub enabled: bool, pub bind_address: SocketAddr, pub ssl_enabled: bool, #[serde(flatten)] pub tsl_config: Optional<TslConfig>, } pub struct TslConfig { pub ssl_cert_path: PathBuf, pub ssl_key_path: PathBuf, } ``` That mean, the user could provide it or not, but if it's provided file paths can't be empty.
We are using `String` to represent a filepath. We are refactoring to enrich types in configuration. Filepath should be represented with `PathBuf` but it allows non UTF-8 chars, so it can't be serialized. Since we need to serialize config options (toml, json) is valid UTF-8 strings, we need a type that represents a valid fileptah but also is a valid UTF-8 strings. That makes impossible to use non-UTF8 fielpath. It seems that's a restriction accepted for a lot of projects including Rust `cargo`.
josecelano
force-pushed
the
852-config-overhaul-replace-primitive-types-in-configuration-with-reacher-types
branch
from
May 10, 2024 15:04
7002f8a
to
7a2f2a6
Compare
josecelano
force-pushed
the
852-config-overhaul-replace-primitive-types-in-configuration-with-reacher-types
branch
from
May 10, 2024 15:13
7a2f2a6
to
adc21f8
Compare
josecelano
force-pushed
the
852-config-overhaul-replace-primitive-types-in-configuration-with-reacher-types
branch
from
May 10, 2024 15:20
adc21f8
to
b545b33
Compare
ACK b545b33 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to: #790
Refactor: enrich field types in configuration structs.
This will cause the app to fail earlier while loading invalid configurations and simplify the code by reducing conversions to get the rich type from the primitive when it's used.
HealthCheckApi
UdpTracker
HttpTracker
HttpApi
Configuration
Output example when you provide an invalid socket address:
You get that error proving this config option:
The error contains all the information needed, although it could be more user-friendly. Maybe we can map that error to a simpler explanation like this: