Skip to content

Draft: Implement generic approach for configuration validation

Sami Hiltunen requested to merge smh-config-proto into master

Gitaly is gaining a new command soon to validate its configuration. Doing so, we want to validate as much of the config as possible, so the user doesn't have to run the tool multiple times to fix validation errors one by one. We also need to report the field which encounters the validation error so the user knows which field is invalid. Finally, the returned information has to be accessible in a structured manner so we can print out information in an easy to consume manner. This helps with integrating the validation tool to for example Omnibus in manner which allows ominbus to print out the keys in a correct manner for its own configuration syntax.

Doing all this is somewhat painful in Gitaly as things are. Each validation function needs to be wired manually and the validation functionality is not easily composable. This commit aims to alleviate these problems by implementing helpers for configuration validation.

The Validate function walks the given object, invoking validation on each field automatically. It also correctly reports the path of the invalid field if there is validation failure. Validation is performed invoking the Validate method on types that implement it. To facilitate adding validation on fields which don't necessarily need a custom type, Field type implements a generic validated field.

Related to #4650 (closed)

Merge request reports