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

Application validation crate/API #1625

Open
fibonacci1729 opened this issue Jun 29, 2023 · 4 comments
Open

Application validation crate/API #1625

fibonacci1729 opened this issue Jun 29, 2023 · 4 comments

Comments

@fibonacci1729
Copy link
Contributor

Currently, the Spin CLI validates a Spin Application by applying various checks on a well-formed manifest, such as whether the correct key-value stores are enumerated, whether variables marked required are provided during deploy, and most recently, @itowlson put together #1623 to correct #1622.

It would be ideal if we could factor out a validation crate that could be shared by Spin, the cloud-plugin, and cloud. This issue is to start the conversation regarding the shape and contents of this shared code (i.e. what kind of checks make the most sense to be commonized).

@fibonacci1729
Copy link
Contributor Author

cc @itowlson @lann @tschneidereit

@itowlson
Copy link
Contributor

(I know we chatted about this elsewhere, but just to capture it.)

I'm sceptical of a specific, separate "validation" crate. I'd rather that validation rules lived with the stuff they're supposed to be validating, because "what is valid" is part of the nature of that stuff, not an external piece of knowledge that the stuff can consult. (For example, other parts of the stuff's code may rely on the concept of "what is valid", though if the external service did parsing rather than validating, that could mitigate that. But then the external service needs more knowledge of the type it needs to produce, and bang, circular dependency.) The problem then is how other code can consult the "what is valid" rules.

My preference here would be to allow selective imports, so a crate that needs to validate config keys can get hold of the Key type and use its validation rules, without having to pull in the whole config crate (and similarly for e.g. host names and the outbound-http crate). This keeps types cohesive while hopefully breaking dependencies.

As you note, care is also needed about what can be shared because the validations we perform in Spin and the cloud plugin are different. So we cannot clearly say "this is what it means for a manifest to be valid" - conceptually we have kind of a pipeline of:

Can we even read the damn thing
-> Is it syntactically valid (are key names or host names well formed, do component triggers match the app trigger)
-> Does it conform to the rules of this environment (e.g. cloud might disallow SMTP ports in host names, or non-default store names; local Spin doesn't need to check for incumbent variable definitions)

At the moment this pipeline is fuzzy (at best!) and not readily accessible - the cloud plugin (per the old deploy implementation) finds itself dealing with the raw on-disk manifest format all the way up the pipeline, I think because the full "validated load" does too much. It would be great to have the loader handle the first two stages of the pipeline, so that Spin, cloud, and other plugins could simply layer their environment-specific validations on top of that, and not be concerned about how the loader gets hold of the validation logic.

Thanks for raising this! I hope these rambling thoughts are useful.

@lann
Copy link
Collaborator

lann commented Jun 30, 2023

My preference here would be to allow selective imports

Could you clarify what you mean by this? Feature flags?

@itowlson
Copy link
Contributor

itowlson commented Jul 2, 2023

Yes, features.

@michelleN michelleN moved this to 🆕 Triage Needed in Spin Triage Jul 17, 2023
@michelleN michelleN moved this from 🆕 Triage Needed to 📋 Investigating / Open for Comment in Spin Triage Jul 19, 2023
@michelleN michelleN moved this to 🆕 New in Spin 2.0 Sep 27, 2023
@itowlson itowlson changed the title Spin Application Validation Application validation crate/API Oct 2, 2023
@melissaklein24 melissaklein24 moved this from 🆕 New to Post Release in Spin 2.0 Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📋 Investigating / Open for Comment
Status: Post Release
Development

No branches or pull requests

3 participants