Documentation ¶
Index ¶
- Variables
- func CompareAttrValues(ctx context.Context, av attr.Value, op CompareOp, target 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 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 CompareOp
- type ComparisonFunc
- type Generic
- func Compare(op CompareOp, target interface{}, meta ...interface{}) Generic
- func EnvVarValued() Generic
- func FileIsReadable() Generic
- func IsDurationString() Generic
- func IsURL() Generic
- func IsURLWith(requiredScheme string, requiredPort int) Generic
- func Length(minL, maxL int) Generic
- func MutuallyExclusiveSibling(siblingAttr string) Generic
- func MutuallyInclusiveSibling(siblingAttr string) Generic
- func NewGenericValidator(conf GenericConfig) Generic
- func RegexpMatch(r string) Generic
- func RegexpNotMatch(r string) Generic
- func Required() Generic
- func (g Generic) Description(ctx context.Context) string
- func (g Generic) MarkdownDescription(ctx context.Context) string
- func (g Generic) Validate(ctx context.Context, req GenericRequest, resp *GenericResponse)
- func (g Generic) ValidateBool(ctx context.Context, req validator.BoolRequest, resp *validator.BoolResponse)
- func (g Generic) ValidateFloat64(ctx context.Context, req validator.Float64Request, ...)
- func (g Generic) ValidateInt64(ctx context.Context, req validator.Int64Request, resp *validator.Int64Response)
- func (g Generic) ValidateList(ctx context.Context, req validator.ListRequest, resp *validator.ListResponse)
- func (g Generic) ValidateMap(ctx context.Context, req validator.MapRequest, resp *validator.MapResponse)
- func (g Generic) ValidateNumber(ctx context.Context, req validator.NumberRequest, ...)
- func (g Generic) ValidateObject(ctx context.Context, req validator.ObjectRequest, ...)
- func (g Generic) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse)
- func (g Generic) ValidateString(ctx context.Context, req validator.StringRequest, ...)
- type GenericConfig
- type GenericRequest
- func (r GenericRequest) BoolRequest() (validator.BoolRequest, bool)
- func (r GenericRequest) Float64Request() (validator.Float64Request, bool)
- func (r GenericRequest) Int64Request() (validator.Int64Request, bool)
- func (r GenericRequest) ListRequest() (validator.ListRequest, bool)
- func (r GenericRequest) MapRequest() (validator.MapRequest, bool)
- func (r GenericRequest) NumberRequest() (validator.NumberRequest, bool)
- func (r GenericRequest) ObjectRequest() (validator.ObjectRequest, bool)
- func (r GenericRequest) SetRequest() (validator.SetRequest, bool)
- func (r GenericRequest) StringRequest() (validator.StringRequest, bool)
- type GenericResponse
- func (r *GenericResponse) BoolResponse() (*validator.BoolResponse, bool)
- func (r *GenericResponse) Float64Response() (*validator.Float64Response, bool)
- func (r *GenericResponse) Int64Response() (*validator.Int64Response, bool)
- func (r *GenericResponse) ListResponse() (*validator.ListResponse, bool)
- func (r *GenericResponse) MapResponse() (*validator.MapResponse, bool)
- func (r *GenericResponse) Nil() bool
- func (r *GenericResponse) NumberResponse() (*validator.NumberResponse, bool)
- func (r *GenericResponse) ObjectResponse() (*validator.ObjectResponse, bool)
- func (r *GenericResponse) SetResponse() (*validator.SetResponse, bool)
- func (r *GenericResponse) StringResponse() (*validator.StringResponse, bool)
- 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(requireScheme string, requirePort int) 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 ¶
func CompareAttrValues(ctx context.Context, av attr.Value, op CompareOp, target interface{}, meta ...interface{}) error
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 ¶
func DefaultComparisonFuncs ¶
func DefaultComparisonFuncs() map[string]ComparisonFunc
DefaultComparisonFuncs returns the complete list of default comparison functions
func IsComparisonFailedError ¶
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
Types ¶
type ComparisonFunc ¶
type ComparisonFunc func(ctx context.Context, 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 Generic ¶
Generic a validator that can be applied to variable attribute types
func Compare ¶
Compare executes the specified comparison to the target value for an attribute.
Type comparisons
func EnvVarValued ¶
func EnvVarValued() Generic
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() Generic
FileIsReadable returns a validator that asserts a given attribute's value is a local file that is readable.
func IsDurationString ¶
func IsDurationString() Generic
IsDurationString returns a validator that asserts a given attribute's value is a valid time.Duration string
func IsURL ¶
func IsURL() Generic
IsURL returns a validator that asserts a given attribute's value(s) are parseable as an URL
func IsURLWith ¶ added in v3.0.2
IsURLWith returns a validator that asserts a given attribute's value(s) are parseable as an URL, and that it / they have a specific scheme and / or port
func Length ¶
Length asserts an attribute's length is limited to the specified bounds. The allowed types are:
- string
- set
- map
- list
func MutuallyExclusiveSibling ¶
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 NewGenericValidator ¶
func NewGenericValidator(conf GenericConfig) Generic
NewGenericValidator returns a type implementing every validator interface
func RegexpMatch ¶
RegexpMatch returns a validator that asserts an attribute's value matches the provided expression
func RegexpNotMatch ¶
RegexpNotMatch returns a validator that asserts an attribute's value does not match the provided expression
func Required ¶
func Required() Generic
Required returns a validator that asserts a field is configured with any value at all.
func (Generic) MarkdownDescription ¶
func (Generic) Validate ¶
func (g Generic) Validate(ctx context.Context, req GenericRequest, resp *GenericResponse)
func (Generic) ValidateBool ¶
func (g Generic) ValidateBool(ctx context.Context, req validator.BoolRequest, resp *validator.BoolResponse)
func (Generic) ValidateFloat64 ¶
func (g Generic) ValidateFloat64(ctx context.Context, req validator.Float64Request, resp *validator.Float64Response)
func (Generic) ValidateInt64 ¶
func (g Generic) ValidateInt64(ctx context.Context, req validator.Int64Request, resp *validator.Int64Response)
func (Generic) ValidateList ¶
func (g Generic) ValidateList(ctx context.Context, req validator.ListRequest, resp *validator.ListResponse)
func (Generic) ValidateMap ¶
func (g Generic) ValidateMap(ctx context.Context, req validator.MapRequest, resp *validator.MapResponse)
func (Generic) ValidateNumber ¶
func (g Generic) ValidateNumber(ctx context.Context, req validator.NumberRequest, resp *validator.NumberResponse)
func (Generic) ValidateObject ¶
func (g Generic) ValidateObject(ctx context.Context, req validator.ObjectRequest, resp *validator.ObjectResponse)
func (Generic) ValidateSet ¶
func (g Generic) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse)
func (Generic) ValidateString ¶
func (g Generic) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse)
type GenericConfig ¶
type GenericConfig struct { Description string MarkdownDescription string Describer validator.Describer TestFunc TestFunc SkipWhenNull bool SkipWhenUnknown bool }
GenericConfig describes the configuration of a Generic
type GenericRequest ¶
type GenericRequest struct { Path path.Path PathExpression path.Expression Config tfsdk.Config ConfigValue attr.Value // contains filtered or unexported fields }
func (GenericRequest) BoolRequest ¶
func (r GenericRequest) BoolRequest() (validator.BoolRequest, bool)
func (GenericRequest) Float64Request ¶
func (r GenericRequest) Float64Request() (validator.Float64Request, bool)
func (GenericRequest) Int64Request ¶
func (r GenericRequest) Int64Request() (validator.Int64Request, bool)
func (GenericRequest) ListRequest ¶
func (r GenericRequest) ListRequest() (validator.ListRequest, bool)
func (GenericRequest) MapRequest ¶
func (r GenericRequest) MapRequest() (validator.MapRequest, bool)
func (GenericRequest) NumberRequest ¶
func (r GenericRequest) NumberRequest() (validator.NumberRequest, bool)
func (GenericRequest) ObjectRequest ¶
func (r GenericRequest) ObjectRequest() (validator.ObjectRequest, bool)
func (GenericRequest) SetRequest ¶
func (r GenericRequest) SetRequest() (validator.SetRequest, bool)
func (GenericRequest) StringRequest ¶
func (r GenericRequest) StringRequest() (validator.StringRequest, bool)
type GenericResponse ¶
type GenericResponse struct { Diagnostics diag.Diagnostics // contains filtered or unexported fields }
func (*GenericResponse) BoolResponse ¶
func (r *GenericResponse) BoolResponse() (*validator.BoolResponse, bool)
func (*GenericResponse) Float64Response ¶
func (r *GenericResponse) Float64Response() (*validator.Float64Response, bool)
func (*GenericResponse) Int64Response ¶
func (r *GenericResponse) Int64Response() (*validator.Int64Response, bool)
func (*GenericResponse) ListResponse ¶
func (r *GenericResponse) ListResponse() (*validator.ListResponse, bool)
func (*GenericResponse) MapResponse ¶
func (r *GenericResponse) MapResponse() (*validator.MapResponse, bool)
func (*GenericResponse) Nil ¶
func (r *GenericResponse) Nil() bool
Nil will return true if the source validator response instance was nil
func (*GenericResponse) NumberResponse ¶
func (r *GenericResponse) NumberResponse() (*validator.NumberResponse, bool)
func (*GenericResponse) ObjectResponse ¶
func (r *GenericResponse) ObjectResponse() (*validator.ObjectResponse, bool)
func (*GenericResponse) SetResponse ¶
func (r *GenericResponse) SetResponse() (*validator.SetResponse, bool)
func (*GenericResponse) StringResponse ¶
func (r *GenericResponse) StringResponse() (*validator.StringResponse, bool)
type TestFunc ¶
type TestFunc func(context.Context, GenericRequest, *GenericResponse)
func CompareTest ¶
CompareTest executes a registered comparison function against the target attribute's value
func LengthTest ¶
LengthTest is an Generic 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 Generic 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 Generic 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 Generic 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