dalec icon indicating copy to clipboard operation
dalec copied to clipboard

feat: Cue spec validation

Open adamperlin opened this issue 11 months ago • 2 comments

What this PR does / why we need it: Currently, Dalec specs are validated using a mixture of strict YAML unmarshalling and manual validation of the unmarshaled spec in Go code. This PR allows us to concretely specify a schema for Dalec specs using Cue, and then utilize Cue for almost all spec validation. This has a number of benefits:

  1. It removes the need for some of the currently existing validation code within Dalec, within which it is hard to account for every error case.
  2. It allows us to add new spec validations easily and declaratively, without changing Go validation code
  • As a proof of concept for this, the Cue spec included in this PR places additional restrictions on source names
  1. It gives us a model to use for generating templated YAML which is correct-by-construction. We can use the Cue spec included here to create templates which can be used for generating starter spec stubs for new Dalec users, as well as creating templates over subcomponents of the Dalec spec (i.e., reducing boilerplate for particular commonly used sources, and any number of other tasks).

I am opening this as a draft mostly for discussion. All the current test cases in the repo are passing. I do have some concerns with user friendliness, as cue's error messages aren't always the nicest and take a bit of getting used to. They do however nearly always point to the specific field (or lack of field) which is causing the issue.

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged): Fixes #132

Special notes for your reviewer:

adamperlin avatar Mar 08 '24 21:03 adamperlin