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

all: Implement function parameter validation interfaces #238

Merged
merged 12 commits into from
Oct 17, 2024

Conversation

austinvalle
Copy link
Member

@austinvalle austinvalle commented Oct 14, 2024

Closes #235

This PR implements function parameter validation interfaces to all of our common "value-based" validators. Most of the changes are straightforward as the parameter interface only differs from the original because the error handling is different (diag.Diagnostics vs. function.FuncError) and the context provided is different (Config data and path expressions vs. ArgumentPosition).

There are a few exceptions where I didn't implement the parameter interfaces:

  • IsRequired - This validator is only useful with blocks, which aren't applicable for provider functions.
  • The schema validators (ExactlyOneOf, ConflictsWith, etc.) - these validators can only operate on schema-based data that supports paths, which aren't applicable for provider functions.
  • Validators that accept the validator package interfaces as input (All, Any, etc.) - these validators are a little awkward to implement and probably require a little more thought on whether we should duplicate them or just do type assertions internally.
  • The entire objectvalidator package - after the above exceptions, there were no value-based validators here to implement.

Other Notes

  • There are a couple validators that previously returned nil when invalid data was given to create the validator with. This would cause a panic with terraform-plugin-framework and is undefined behavior (really should return an error, but to keep the API clean, we can't return one)
    • I opt'd to just move this data check to happen when the validator is run, which should still be early enough and more explicit then the original panic behavior. An example of one of these validators is stringvalidator.LengthBetween

@austinvalle austinvalle added the enhancement New feature or request label Oct 14, 2024
@austinvalle austinvalle added this to the v0.14.0 milestone Oct 14, 2024
@austinvalle austinvalle requested a review from a team as a code owner October 14, 2024 16:48
Copy link
Contributor

@SBGoods SBGoods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

listvalidator/unique_values.go Show resolved Hide resolved
@austinvalle austinvalle merged commit aa6a2de into main Oct 17, 2024
6 checks passed
@austinvalle austinvalle deleted the av/function-validators branch October 17, 2024 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support parameter-based validator interfaces <Type>ParameterValidator
2 participants