Documentation ¶
Index ¶
- Variables
- func CompareAttrValues(av attr.Value, op CompareOp, target interface{}, meta ...interface{}) error
- func ComparisonFailedError(actual interface{}, op CompareOp, target interface{}) error
- func DefaultComparisonFuncs() map[string]ComparisonFunc
- func IsComparisonFailedError(err error) bool
- func IsNoComparisonFuncRegisteredError(err error) bool
- func IsTypeConversionFailedError(err error) bool
- func IsUnexpectedAttributeValueTypeError(err error) bool
- func IsUnexpectedComparisonActualType(err error) bool
- func NewValidator(desc, md string, fn TestFunc, skipNull, skipUnknown bool) *baseAttributeValidator
- func NoComparisonFuncRegisteredError(op CompareOp, t interface{}) error
- func SetComparisonFunc(targetType interface{}, fn ComparisonFunc)
- func TypeConversionFailedError(err error) error
- func UnexpectedComparisonActualTypeError(scope string, actualActual interface{}, op CompareOp, ...) error
- func UnexpectedComparisonTargetTypeError(scope string, actualTarget interface{}, op CompareOp, ...) error
- type AttributeValidator
- func Compare(op CompareOp, target interface{}, meta ...interface{}) AttributeValidator
- func EnvVarValued() AttributeValidator
- func FileIsReadable() AttributeValidator
- func IsDurationString() AttributeValidator
- func IsURL() AttributeValidator
- func Length(minL, maxL int) AttributeValidator
- func MutuallyExclusiveSibling(siblingAttr string) AttributeValidator
- func MutuallyInclusiveSibling(siblingAttr string) AttributeValidator
- func RegexpMatch(r string) AttributeValidator
- func RegexpNotMatch(r string) AttributeValidator
- func Required() AttributeValidator
- type CompareOp
- type ComparisonFunc
- type TestFunc
- func CompareTest(op CompareOp, target interface{}, meta ...interface{}) TestFunc
- func LengthTest(minL, maxL int) TestFunc
- func MutuallyExclusiveSiblingTest(siblingAttr string) TestFunc
- func MutuallyInclusiveSiblingTest(siblingAttr string) TestFunc
- func RegexpMatchTest(r string) TestFunc
- func RegexpNotMatchTest(r string) TestFunc
- func RequiredTest() TestFunc
- func TestEnvVarValued() TestFunc
- func TestFileIsReadable() TestFunc
- func TestIsDurationString() TestFunc
- func TestIsURL() TestFunc
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoComparisonFuncRegistered = errors.New("no comparison func registered") ErrTypeConversionFailed = errors.New("type conversion failed") ErrComparisonFailed = errors.New("comparison failed") ErrUnexpectedComparisonTargetType = errors.New("unexpected comparison target value type") ErrUnexpectedComparisonActualType = errors.New("unexpected comparison actual value type") )
Functions ¶
func CompareAttrValues ¶
CompareAttrValues attempts to execute a comparison between the provided attribute value and the targeted value.
If there is no comparison function registered for the target type, an ErrNoComparisonFuncRegistered is returned.
If a function is registered and the comparison fails, an ErrComparisonFailed error will be returned
func ComparisonFailedError ¶ added in v1.0.0
func DefaultComparisonFuncs ¶
func DefaultComparisonFuncs() map[string]ComparisonFunc
DefaultComparisonFuncs returns the complete list of default comparison functions
func IsComparisonFailedError ¶ added in v1.0.0
func IsNoComparisonFuncRegisteredError ¶ added in v1.0.0
func IsTypeConversionFailedError ¶ added in v1.0.0
func IsUnexpectedAttributeValueTypeError ¶ added in v1.0.0
func IsUnexpectedComparisonActualType ¶ added in v1.0.0
func NewValidator ¶
func NoComparisonFuncRegisteredError ¶ added in v1.0.0
func SetComparisonFunc ¶
func SetComparisonFunc(targetType interface{}, fn ComparisonFunc)
SetComparisonFunc sets a comparison function to use for comparing attribute values to values of the specified type
func TypeConversionFailedError ¶ added in v1.0.0
func UnexpectedComparisonActualTypeError ¶ added in v1.0.0
Types ¶
type AttributeValidator ¶
type AttributeValidator interface { tfsdk.AttributeValidator WithDescription(string) AttributeValidator WithMarkdownDescription(string) AttributeValidator }
func Compare ¶
func Compare(op CompareOp, target interface{}, meta ...interface{}) AttributeValidator
Compare executes the specified comparison to the target value for an attribute.
Type comparisons
func EnvVarValued ¶
func EnvVarValued() AttributeValidator
EnvVarValued returns a validator that asserts a given attribute's value is the name of an environment variable that is valued at runtime
func FileIsReadable ¶
func FileIsReadable() AttributeValidator
FileIsReadable returns a validator that asserts a given attribute's value is a local file that is readable.
func IsDurationString ¶
func IsDurationString() AttributeValidator
IsDurationString returns a validator that asserts a given attribute's value is a valid time.Duration string
func IsURL ¶
func IsURL() AttributeValidator
IsURL returns a validator that asserts a given attribute value is parseable as a URL
func Length ¶
func Length(minL, maxL int) AttributeValidator
Length asserts an attribute's length is limited to the specified bounds. The allowed types are:
- string
- set
- map
- list
func MutuallyExclusiveSibling ¶
func MutuallyExclusiveSibling(siblingAttr string) AttributeValidator
MutuallyExclusiveSibling returns a validator that ensures that an attribute only carries a value when another sibling attribute does not.
Sibling is defined as another attribute that is at the same step depth as the source attribute
func MutuallyInclusiveSibling ¶
func MutuallyInclusiveSibling(siblingAttr string) AttributeValidator
func RegexpMatch ¶
func RegexpMatch(r string) AttributeValidator
RegexpMatch returns a validator that asserts an attribute's value matches the provided expression
func RegexpNotMatch ¶
func RegexpNotMatch(r string) AttributeValidator
RegexpNotMatch returns a validator that asserts an attribute's value does not match the provided expression
func Required ¶
func Required() AttributeValidator
Required returns a validator that asserts a field is configured with any value at all.
type ComparisonFunc ¶
type ComparisonFunc func(av attr.Value, op CompareOp, target interface{}, meta ...interface{}) error
ComparisonFunc executes a specific comparison of an attribute value to the targeted value. You are guaranteed that the target type will be the type or one of the types the function was registered with. If you register a single func with more than type target type, you must perform type assertion / conversion yourself.
The returned error is expected to be testable for type:
nil - Comparison succeeded ErrComparisonFailed - Must be returned when any comparison operation fails ErrTypeConversionFailed - Must be returned if the function performs an internal type conversion before comparison that errored any other error - Treated as unhandled error
To see the default list of functions, see DefaultComparisonFuncs.
To register a new function or overwrite an existing function, see SetComparisonFunc
func GetComparisonFunc ¶
func GetComparisonFunc(targetType interface{}) (ComparisonFunc, bool)
GetComparisonFunc attempts to return a previously registered comparison function for a specified op : type combination
type TestFunc ¶
type TestFunc func(context.Context, tfsdk.ValidateAttributeRequest, *tfsdk.ValidateAttributeResponse)
func CompareTest ¶
CompareTest executes a registered comparison function against the target attribute's value
func LengthTest ¶
LengthTest is an AttributeValidator implementation that attempts to find a length value appropriate for the attribute value type, asserting that it is within the specified bounds.
If either min or max is set to -1, then that value is unbounded and thus not verified.
func MutuallyExclusiveSiblingTest ¶
MutuallyExclusiveSiblingTest ensures that a given attribute is not valued when another one is, and vice versa.
func MutuallyInclusiveSiblingTest ¶
MutuallyInclusiveSiblingTest ensures that a given attribute is valued when a sibling attribute is also valued
func RegexpMatchTest ¶
RegexpMatchTest is an AttributeValidator implementation that will first attempt to convert the value of a field to a string, then see if that resulting string matches the provided expression.
func RegexpNotMatchTest ¶
RegexpNotMatchTest is an AttributeValidator implementation that will first attempt to convert the value of a field to a string, then see if that resulting string matches the provided expression.
func RequiredTest ¶
func RequiredTest() TestFunc
RequiredTest is an AttributeValidator implementation that will register an error if the attribute has no value of any kind
func TestEnvVarValued ¶
func TestEnvVarValued() TestFunc
TestEnvVarValued asserts that a given attribute value is the name of an environment variable that is valued at runtime
func TestFileIsReadable ¶
func TestFileIsReadable() TestFunc
TestFileIsReadable attempts to open and subsequently read a single byte from the file at the path specified by the attribute value.
func TestIsDurationString ¶
func TestIsDurationString() TestFunc
TestIsDurationString asserts that a given attribute's value is a valid time.Duration string