-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type-based provider-defined function parameter validation (#968)
* Add ValidateableAttribute and ValidateableParameter interfaces * Deprecate xattr.TypeWithValidate * Modify function signature of ArgumentsData() to return a function.FuncError and add switch to handle validation.ValidateableParameter interface * Modify Data.SetAtPath to use switch statement to handle validation.ValidateableParameter interface * Modify Data.SetAtPathTransformFunc to use switch statement to handle validation.ValidateableParameter interface * Temporarily moving ValidateableAttribute interface to xattr package to avoid import cycle * Adding test coverage for list, map and set for SetAtPathTransformFunc * Adding test coverage for bool ValidateableParameter for fromproto5/6 ArgumentsData() * Adding switch statement for ValidateableAttribute to fwschemadata Data.ValueAtPaath() * Adding switch statements to internal/reflect/interfaces to handle ValidateableAttribute assertions * Fix usage of incorrect test type * Adding switch statements to internal/reflect/primitive to handle ValidateableAttribute assertions * Renaming interfaces * Add Equal() methods to ListValueWithValidateAttributeWarning and MapValueWithValidateAttributeWarning * Adding switch statements to reflect package FromMap() function to handle ValidateableAttribute assertions * Adding switch statements to reflect package FromInt(), FromUint(), FromFloat(), FromBigFloat(), and FromBigInt() functions to handle ValidateableAttribute assertions * Adding switch statements to reflect package FromPointer() function to handle ValidateableAttribute assertions * Adding switch statements to reflect package FromSlice() function to handle ValidateableAttribute assertions * Adding switch statements to reflect package FromStruct() function to handle ValidateableAttribute assertions * fromproto5+fromproto6: Add further test coverage for validation of function parameters in ArgumentsData() function * xfwfunction: Moving Definition.Parameter() method from function package to xfwfunction package Parameter() function * xfwfunction package is purely to avoid import cycles * fromproto5+fromproto6: Fix function error message in ArgumentsData() * website: Add documentation for usage of xattr.ValidateableAttribute and validation.ValidateableParameter * website: Add documentation for usage of xattr.ValidateableAttribute and validation.ValidateableParameter * Adding changelog entries * function: Remove unused Definition.Parameter() method * attr/xattr: Remove TODO * attr/xattr: Modify deprecation comment * fwschemadata: Reordering logging calls * fromproto5+fromproto6: Inline logic from Parameter() function in ArgumentsData() function * Remove value type-specific interfaces for <Type>ValuableWithValidateableAttribute and <Type>ValuableWithValidateableParameter * website: Adding documentation for parameter validation into parameters page * function: Moving ValidateableParameter interface to function package * Amend docs * Apply suggestions from code review Co-authored-by: Austin Valle <austinvalle@gmail.com> * fromproto5: Remove unused function * fromproto5+fromproto6: Remove unneeded case statements * fromproto5: Removing errant test case * attr/xattr: Modifying Validateable Go doc comment to highlight the implicit calling of ValidateAttribute --------- Co-authored-by: Austin Valle <austinvalle@gmail.com>
- Loading branch information
1 parent
541a7cb
commit 4a9b6a3
Showing
66 changed files
with
4,557 additions
and
615 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
kind: BREAKING CHANGES | ||
body: 'function: Removed `Definition` type `Parameter()` method' | ||
time: 2024-04-04T18:20:04.534677+01:00 | ||
custom: | ||
Issue: "968" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
kind: FEATURES | ||
body: 'attr/xattr: Added `ValidateableAttribute` interface for custom value type implementations' | ||
time: 2024-04-04T15:43:39.796606+01:00 | ||
custom: | ||
Issue: "968" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'function: Added `ValidateableParameter` interface for custom value | ||
type implementations' | ||
time: 2024-04-04T15:44:39.289946+01:00 | ||
custom: | ||
Issue: "968" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: NOTES | ||
body: 'attr/xattr: The `TypeWithValidate` interface has been deprecated in preference | ||
of the `ValidateableAttribute` interface. A `ValidatableParameter` interface has | ||
also been added to the `function` package' | ||
time: 2024-04-04T15:56:06.494328+01:00 | ||
custom: | ||
Issue: "968" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package xattr | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
) | ||
|
||
// ValidateableAttribute defines an interface for validating an attribute value. | ||
// The ValidateAttribute method is called implicitly by the framework when value | ||
// types from Terraform are converted into framework types. | ||
type ValidateableAttribute interface { | ||
// ValidateAttribute returns any warnings or errors generated during validation | ||
// of the attribute. It is generally used to check the data format and ensure | ||
// that it complies with the requirements of the Value. | ||
ValidateAttribute(context.Context, ValidateAttributeRequest, *ValidateAttributeResponse) | ||
} | ||
|
||
// ValidateAttributeRequest represents a request for the Value to call its | ||
// validation logic. An instance of this request struct is supplied as an | ||
// argument to the ValidateAttribute method. | ||
type ValidateAttributeRequest struct { | ||
// Path is the path to the attribute being validated. | ||
Path path.Path | ||
} | ||
|
||
// ValidateAttributeResponse represents a response to a ValidateAttributeRequest. | ||
// An instance of this response struct is supplied as an argument to the | ||
// ValidateAttribute method. | ||
type ValidateAttributeResponse struct { | ||
// Diagnostics is a collection of warnings or errors generated during | ||
// validation of the Value. | ||
Diagnostics diag.Diagnostics | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.