Skip to content
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

Mark a configuration as having passed validation before using it #172

Closed
iffyio opened this issue Jan 24, 2021 · 0 comments · Fixed by #207
Closed

Mark a configuration as having passed validation before using it #172

iffyio opened this issue Jan 24, 2021 · 0 comments · Fixed by #207
Labels
kind/cleanup Refactoring code, fixing up documentation, etc

Comments

@iffyio
Copy link
Collaborator

iffyio commented Jan 24, 2021

Some config fields have validation rules which we check on startup. For example, that a list of endpoints must be non-empty. However, when we later try to fetch that retrieve that list from the config we don't have any way to guarantee that the list is in fact non-empty.
This leads to either re-validating the list or trusting that validation did in-fact take place (and possibly panicking if the assumption is wrong).

Instead, we can have a ValidatedConfig type that is returned by the validation logic guaranteeing that validation took place. e.g Input config has the format

struct Config {
  endpoints: Vec<EndPoint>, // Serialized from disk, may or may not be empty.
}

while the returned, validated config has the same format but with a new type

struct ValidatedConfig {
  endpoints: Endpoints, // Endpoints is a type that guarantees that the internal list is non-empty.
}
@iffyio iffyio added good first issue Good for newcomers kind/cleanup Refactoring code, fixing up documentation, etc labels Jan 24, 2021
@iffyio iffyio removed the good first issue Good for newcomers label Feb 12, 2021
iffyio added a commit that referenced this issue Mar 7, 2021
A ValidatedConfig type is returned after validating a
config, so that any code that relies on config invariants do
not need to re-validate the config.

Fixes #172
markmandel added a commit that referenced this issue Mar 11, 2021
A ValidatedConfig type is returned after validating a
config, so that any code that relies on config invariants do
not need to re-validate the config.

Fixes #172

Co-authored-by: Mark Mandel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Refactoring code, fixing up documentation, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant