-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parameter-based provider-defined function validation (#971)
* Add `function/validator` package * Implement parameter validators in parameter types * Initial implementation of parameter validation logic * Refactor function parameter validators from `function/validator` package to `function` package. * Add parameter unit tests * Add parameter tests to arguments_data_test.go * Switch dynamic parameter test to use `DynamicTypeMust()` * Correct error handling and dynamic type test cases * Add variadic parameter test cases * Add variadic parameter support and test for `tfprotov6` * Add copyright headers * Resolve `forcetypeassert` linter errors * Resolve test failures from merge * Add changelog entries * Skip appending parameter value if validation fails * Support parameter validation for custom types * Refactor parameter validator interface names for clarity. * Add website documentation for parameter-based validation * Add copyright headers * Update changelog entries * Rename `Validate()` method in parameter validator interfaces to `ValidateParameter<Type>()` * Skip appending variadic values if there is an error in validation * Update website/docs/plugin/framework/validation.mdx Co-authored-by: Austin Valle <austinvalle@gmail.com> * Replace `create{type}Value` test helper functions with `New{Type}ValueMust` functions --------- Co-authored-by: Benjamin Bennett <ben.bennett@hashicorp.com> Co-authored-by: Austin Valle <austinvalle@gmail.com>
- Loading branch information
1 parent
f6057df
commit d36ac87
Showing
50 changed files
with
6,212 additions
and
22 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,7 @@ | ||
kind: FEATURES | ||
body: '`function`: Add `BoolParameterValidator`, `DynamicParameterValidator`, `Float64ParameterValidator`, `Int64ParameterValidator`, | ||
`ListParameterValidator`, `MapParameterValidator`, `NumberParameterValidator`, `ObjectParameterValidator`, `SetParameterValidator`, | ||
and `StringParameterValidator` interfaces for custom function parameter validation implementations.' | ||
time: 2024-04-05T18:39:17.640444-04:00 | ||
custom: | ||
Issue: "971" |
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,9 @@ | ||
kind: FEATURES | ||
body: '`function`: Add `ParameterWithBoolValidators`, `ParameterWithInt64Validators`, | ||
`ParameterWithFloat64Validators`, `ParameterWithDynamicValidators`, `ParameterWithListValidators`, | ||
`ParameterWithMapValidators`, `ParameterWithNumberValidators`, `ParameterWithObjectValidators`, | ||
`ParameterWithSetValidators`, and `ParameterWithStringValidators` interfaces to enable | ||
parameter-based validation support' | ||
time: 2024-04-05T18:45:27.979266-04:00 | ||
custom: | ||
Issue: "971" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package function | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
// BoolParameterValidator is a function validator for types.Bool parameters. | ||
type BoolParameterValidator interface { | ||
|
||
// ValidateParameterBool performs the validation. | ||
ValidateParameterBool(context.Context, BoolParameterValidatorRequest, *BoolParameterValidatorResponse) | ||
} | ||
|
||
// BoolParameterValidatorRequest is a request for types.Bool schema validation. | ||
type BoolParameterValidatorRequest struct { | ||
// ArgumentPosition contains the position of the argument for validation. | ||
// Use this position for any response diagnostics. | ||
ArgumentPosition int64 | ||
|
||
// Value contains the value of the argument for validation. | ||
Value types.Bool | ||
} | ||
|
||
// BoolParameterValidatorResponse is a response to a BoolParameterValidatorRequest. | ||
type BoolParameterValidatorResponse struct { | ||
// Error is a function error generated during validation of the Value. | ||
Error *FuncError | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package function | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
// DynamicParameterValidator is a function validator for types.Dynamic parameters. | ||
type DynamicParameterValidator interface { | ||
|
||
// ValidateParameterDynamic performs the validation. | ||
ValidateParameterDynamic(context.Context, DynamicParameterValidatorRequest, *DynamicParameterValidatorResponse) | ||
} | ||
|
||
// DynamicParameterValidatorRequest is a request for types.Dynamic schema validation. | ||
type DynamicParameterValidatorRequest struct { | ||
// ArgumentPosition contains the position of the argument for validation. | ||
// Use this position for any response diagnostics. | ||
ArgumentPosition int64 | ||
|
||
// Value contains the value of the argument for validation. | ||
Value types.Dynamic | ||
} | ||
|
||
// DynamicParameterValidatorResponse is a response to a DynamicParameterValidatorRequest. | ||
type DynamicParameterValidatorResponse struct { | ||
// Error is a function error generated during validation of the Value. | ||
Error *FuncError | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package function | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
// Float64ParameterValidator is a function validator for types.Float64 parameters. | ||
type Float64ParameterValidator interface { | ||
|
||
// ValidateParameterFloat64 performs the validation. | ||
ValidateParameterFloat64(context.Context, Float64ParameterValidatorRequest, *Float64ParameterValidatorResponse) | ||
} | ||
|
||
// Float64ParameterValidatorRequest is a request for types.Float64 schema validation. | ||
type Float64ParameterValidatorRequest struct { | ||
// ArgumentPosition contains the position of the argument for validation. | ||
// Use this position for any response diagnostics. | ||
ArgumentPosition int64 | ||
|
||
// Value contains the value of the argument for validation. | ||
Value types.Float64 | ||
} | ||
|
||
// Float64ParameterValidatorResponse is a response to a Float64ParameterValidatorRequest. | ||
type Float64ParameterValidatorResponse struct { | ||
// Error is a function error generated during validation of the Value. | ||
Error *FuncError | ||
} |
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.