validators

package
v0.11.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxLabelValueLength      = 63
	MaxLabelNameLength       = 63
	MaxPrefixLength          = 253
	MaxAnnotationValueLength = 262144
)

These are default values, you can adjust them as you want

Variables

This section is empty.

Functions

func ARN added in v0.7.0

func ARN() validator.String

ARN validates that a string is an AWS ARN (loosely, but safely). Pattern source: adapted to allow typical ARN segments: arn:partition:service:region:account-id:resource We avoid being overly strict on service-specific resource formats while ensuring the ARN skeleton is correct.

func AWSRegion added in v0.8.0

func AWSRegion() validator.String

AWSRegion validates that a string is a valid AWS region code.

func AzureLocation added in v0.8.0

func AzureLocation() validator.String

AzureLocation validates that a string is a valid Azure location.

func Base32Validator added in v0.2.0

func Base32Validator() frameworkvalidator.String

Base32Validator returns a validator that verifies a string is Base32-encoded.

func Base64Validator

func Base64Validator() frameworkvalidator.String

Base64Validator returns a validator that verifies a string is Base64-encoded.

func Between added in v0.1.6

func Between(minStr, maxStr string) frameworkvalidator.String

Between returns a validator ensuring the value falls within an inclusive numeric range.

func CIDR added in v0.1.4

CIDR validates IPv4 and IPv6 CIDR blocks.

func CreditCard

func CreditCard() frameworkvalidator.String

CreditCard returns a schema.String validator which validates credit card numbers using the Luhn algorithm.

func CreditCardExpiry added in v0.11.2

func CreditCardExpiry() frameworkvalidator.String

CreditCardExpiry returns a schema.String validator which validates credit card expiry dates. It supports both MM/YY and MM/YYYY formats and ensures the date is not in the past.

func DateTime added in v0.1.6

func DateTime(layouts []string) frameworkvalidator.String

DateTime returns a schema.String validator enforcing ISO 8601 / RFC 3339 datetimes. Optional layouts may be provided to extend accepted formats.

func DefaultUsernameValidator added in v0.1.8

func DefaultUsernameValidator() frameworkvalidator.String

DefaultUsernameValidator returns the project defaults.

func Domain

func Domain() frameworkvalidator.String

Domain returns a schema.String validator which enforces valid domain format. The validator checks for proper domain format according to RFC 1123 and RFC 952.

func Email

func Email() frameworkvalidator.String

Email returns a schema.String validator which enforces RFC 5322 compliant emails.

func EvaluateBetween added in v0.1.6

func EvaluateBetween(value, minRaw, maxRaw string) (bool, *BetweenDiagnostic, *BetweenDiagnostic)

EvaluateBetween checks if a numeric string value falls within the specified inclusive range. It returns a success boolean and optional diagnostics for bounds or value errors.

func FQDN added in v0.2.1

FQDN returns a validator that ensures the value is a fully qualified domain name.

func GCPRegion added in v0.8.0

func GCPRegion() validator.String

GCPRegion validates that a string is a valid GCP region.

func GCPZone added in v0.9.0

func GCPZone() validator.String

GCPZone validates that a string is a valid GCP zone.

func Hex added in v0.2.0

Hex returns a validator ensuring the string contains only hexadecimal characters (0-9, a-f, A-F).

func Hostname added in v0.1.5

func Hostname() frameworkvalidator.String

Hostname returns a schema.String validator enforcing RFC 1123 hostname rules.

func IP added in v0.1.1

IP returns a schema.String validator that ensures the value is a valid IP address.

func Integer added in v0.2.0

func Integer() frameworkvalidator.String

Integer returns a validator ensuring the string represents a valid integer.

func IsLinkLocalIP added in v0.6.0

func IsLinkLocalIP(ip net.IP) bool

IsLinkLocalIP reports whether the IP is link-local (IPv4 169.254.0.0/16, IPv6 fe80::/10).

func IsReservedIP added in v0.6.0

func IsReservedIP(ip net.IP) bool

IsReservedIP reports whether the IP is from commonly reserved/non-routable ranges (loopback, documentation ranges, multicast, broadcast, CGNAT, etc.). This is not exhaustive but covers the most relevant ranges for public routing checks.

func JSON added in v0.1.1

JSON returns a schema.String validator that ensures the value encodes a JSON object.

func JWT added in v0.2.2

JWT validates that a string is a well-formed JSON Web Token (three base64url segments).

func MACAddress added in v0.1.5

func MACAddress() frameworkvalidator.String

MACAddress returns a schema.String validator that ensures the value is a valid MAC address.

func MIMEType added in v0.9.0

func MIMEType() frameworkvalidator.String

MIMEType returns a validator that verifies a string is a valid MIME type.

func MatchesRegex added in v0.1.2

func MatchesRegex(pattern string) frameworkvalidator.String

MatchesRegex returns a validation that checks input against the provided regular expression pattern.

func NewInListValidator added in v0.1.6

func NewInListValidator(values []string, ignoreCase bool) frameworkvalidator.String

NewInListValidator constructs a validator that allows only the provided values.

func NewInListValidatorWithMessage added in v0.5.0

func NewInListValidatorWithMessage(values []string, ignoreCase bool, message string) frameworkvalidator.String

NewInListValidatorWithMessage constructs a validator that allows only the provided values and returns a custom diagnostic message on validation failure. When message is empty, the default diagnostic is used.

func NewNotInListValidator added in v0.1.8

func NewNotInListValidator(values []string, ignoreCase bool) frameworkvalidator.String

NewNotInListValidator constructs a validator that fails when the value matches any disallowed value.

func NonNegativeNumber added in v0.10.0

func NonNegativeNumber() frameworkvalidator.String

NonNegativeNumber returns a validator that checks if a string represents a non-negative number (zero or greater).

func PasswordStrengthValidator added in v0.2.1

func PasswordStrengthValidator() frameworkvalidator.String

PasswordStrengthValidator validates passwords for minimal complexity.

func Phone

func Phone() frameworkvalidator.String

Phone returns a schema.String validator that ensures values follow the E.164 phone number format.

func PortNumber added in v0.6.0

func PortNumber() frameworkvalidator.String

PortNumber returns a validator ensuring a string represents a valid TCP/UDP port number (1..65535).

func PortRange added in v0.4.0

func PortRange() frameworkvalidator.String

PortRange returns a validator ensuring a string matches a valid TCP/UDP port range in the form "start-end" where 0 <= start <= end <= 65535.

func PositiveNumber added in v0.10.0

func PositiveNumber() frameworkvalidator.String

PositiveNumber returns a validator that checks if a string represents a positive number (greater than zero).

func PrivateIP added in v0.5.0

func PrivateIP() frameworkvalidator.String

PrivateIP returns a validator ensuring a string is an RFC1918 private IP address (IPv4 or IPv6 unique local address).

func PublicIP added in v0.6.0

func PublicIP() frameworkvalidator.String

PublicIP returns a validator ensuring a string is a public (non-private) IP address.

func ResourceName added in v0.11.0

func ResourceName() frameworkvalidator.String

ResourceName returns a validator ensuring a string matches Terraform resource naming conventions. Valid names must: - Start with a lowercase letter or underscore - Contain only lowercase letters, digits, underscores, and hyphens - Not be empty

func SSHPublicKeyValidator added in v0.2.0

func SSHPublicKeyValidator() frameworkvalidator.String

SSHPublicKeyValidator returns a validator that verifies an SSH public key in OpenSSH authorized_keys format.

func SemVer added in v0.1.1

func SemVer() frameworkvalidator.String

SemVer returns a schema.String validator ensuring semantic versioning per semver.org.

func SemVerRange added in v0.3.0

func SemVerRange() frameworkvalidator.String

SemVerRange returns a validator that ensures the string is a well-formed semantic version range expression like ">=1.0.0,<2.0.0".

func SizeBetween added in v0.10.0

func SizeBetween(min, max string) frameworkvalidator.String

SizeBetween returns a validator that checks if a string represents a numeric value within an inclusive range.

func Slug added in v0.9.0

Slug returns a validator that checks if a string is a valid slug. A valid slug consists of lowercase letters, digits, and hyphens. It must start and end with a letter or digit, and hyphens cannot be consecutive.

func StringContains added in v0.1.7

func StringContains(substrings []string, ignoreCase bool) frameworkvalidator.String

StringContains returns a validator that ensures the value contains one of the provided substrings.

func StringPrefix added in v0.1.8

func StringPrefix(prefixes []string, ignoreCase bool) frameworkvalidator.String

StringPrefix returns a validator ensuring a string starts with one of the provided prefixes.

func StringSuffix added in v0.1.7

func StringSuffix(suffixes ...string) frameworkvalidator.String

StringSuffix returns a validator that ensures a value ends with one of the provided suffixes.

func Subnet added in v0.6.0

func Subnet() frameworkvalidator.String

Subnet validates IPv4/IPv6 CIDR blocks where the IP equals the network address (subnet address).

func URI added in v0.5.0

URI returns a validator ensuring a string is a valid URI.

func URL added in v0.1.3

URL returns a schema.String validator that ensures the value is a well formed URL with scheme and host.

func UUID

UUID returns a schema.String validator which enforces RFC 4122 compliant UUIDs (versions 1-5).

func UUIDv4Only added in v0.9.0

func UUIDv4Only() frameworkvalidator.String

UUIDv4Only returns a schema.String validator which enforces UUID version 4 only.

func Username added in v0.1.8

func Username(minLength, maxLength int) frameworkvalidator.String

Username returns a validator enforcing ValidateFX username rules. Callers may customize the length bounds; characters are limited to ASCII letters, digits, and underscore to align with common username rules.

func ValidateAnnotationValue added in v0.11.2

func ValidateAnnotationValue(value string) error

func ValidateLabelKey added in v0.11.2

func ValidateLabelKey(key string) error

ValidateLabelKey validates a Kubernetes label key (with optional prefix/name format).

func ValidateLabelValue added in v0.11.2

func ValidateLabelValue(value string) error

Types

type BetweenDiagnostic added in v0.1.6

type BetweenDiagnostic struct {
	Summary string
	Detail  string
}

BetweenDiagnostic captures validation errors for invalid bounds or values.

type CIDROverlapValidator added in v0.3.0

type CIDROverlapValidator struct{}

CIDROverlapValidator validates that a set of CIDR blocks do not overlap. It returns an error if any two CIDR ranges intersect or if any entry is invalid.

func NewCIDROverlap added in v0.3.0

func NewCIDROverlap() *CIDROverlapValidator

NewCIDROverlap returns a new instance of the CIDR overlap validator.

func (*CIDROverlapValidator) Validate added in v0.3.0

func (v *CIDROverlapValidator) Validate(cidrs []string) error

Validate returns nil if no overlaps are found among the provided CIDR blocks.

type DependentValueValidator added in v0.11.0

type DependentValueValidator struct{}

DependentValueValidator validates that if a condition value is non-empty, then a dependent value must also be non-empty.

func NewDependentValue added in v0.11.0

func NewDependentValue() *DependentValueValidator

NewDependentValue creates a new validator that checks dependent value relationships.

func (DependentValueValidator) Description added in v0.11.0

Description returns a plain text description of the validator.

func (DependentValueValidator) MarkdownDescription added in v0.11.0

func (v DependentValueValidator) MarkdownDescription(ctx context.Context) string

MarkdownDescription returns a markdown formatted description of the validator.

func (DependentValueValidator) Validate added in v0.11.0

func (DependentValueValidator) Validate(conditionValue, dependentValue string) error

Validate performs the validation on the given values. Returns an error if conditionValue is non-empty but dependentValue is empty.

type IPRangeSizeValidator added in v0.7.0

type IPRangeSizeValidator struct {
	Min int
	Max int
}

IPRangeSizeValidator ensures a CIDR prefix length falls within [Min, Max].

func NewIPRangeSizeValidator added in v0.7.0

func NewIPRangeSizeValidator(min, max int) IPRangeSizeValidator

NewIPRangeSizeValidator constructs a new validator with inclusive bounds.

func (IPRangeSizeValidator) Description added in v0.7.0

func (v IPRangeSizeValidator) Description(_ context.Context) string

func (IPRangeSizeValidator) MarkdownDescription added in v0.7.0

func (v IPRangeSizeValidator) MarkdownDescription(ctx context.Context) string

func (IPRangeSizeValidator) ValidateString added in v0.7.0

type ListLengthBetweenValidator added in v0.11.0

type ListLengthBetweenValidator struct {
	// contains filtered or unexported fields
}

ListLengthBetweenValidator validates that a list has a length between min and max (inclusive).

func NewListLengthBetween added in v0.11.0

func NewListLengthBetween(min, max int) *ListLengthBetweenValidator

NewListLengthBetween creates a new validator that checks list length is between min and max (inclusive).

func (*ListLengthBetweenValidator) Description added in v0.11.0

Description returns a plain text description of the validator.

func (*ListLengthBetweenValidator) MarkdownDescription added in v0.11.0

func (v *ListLengthBetweenValidator) MarkdownDescription(ctx context.Context) string

MarkdownDescription returns a markdown formatted description of the validator.

func (*ListLengthBetweenValidator) Validate added in v0.11.0

func (v *ListLengthBetweenValidator) Validate(values []string) error

Validate performs the validation on the given value.

func (*ListLengthBetweenValidator) ValidateList added in v0.11.0

ValidateList validates a list attribute value.

func (*ListLengthBetweenValidator) ValidateSet added in v0.11.0

ValidateSet validates a set attribute value.

type ListSubsetValidator added in v0.6.0

type ListSubsetValidator struct {
	// contains filtered or unexported fields
}

ListSubsetValidator validates that all elements of a provided list/set are contained in a reference allowlist. It accepts list(string) or set(string) inputs from Terraform callers.

func NewListSubset added in v0.6.0

func NewListSubset(allowed []string) *ListSubsetValidator

NewListSubset constructs a ListSubsetValidator with the allowed elements.

func (*ListSubsetValidator) Description added in v0.6.0

func (v *ListSubsetValidator) Description(_ context.Context) string

func (*ListSubsetValidator) MarkdownDescription added in v0.6.0

func (v *ListSubsetValidator) MarkdownDescription(ctx context.Context) string

func (*ListSubsetValidator) ValidateList added in v0.6.0

func (*ListSubsetValidator) ValidateSet added in v0.6.0

type ListUniqueValidator added in v0.11.0

type ListUniqueValidator struct{}

ListUniqueValidator validates that all elements in a list are unique.

func NewListUnique added in v0.11.0

func NewListUnique() *ListUniqueValidator

NewListUnique creates a new validator that checks all list elements are unique.

func (ListUniqueValidator) Description added in v0.11.0

func (ListUniqueValidator) Description(_ context.Context) string

Description returns a plain text description of the validator.

func (ListUniqueValidator) MarkdownDescription added in v0.11.0

func (v ListUniqueValidator) MarkdownDescription(ctx context.Context) string

MarkdownDescription returns a markdown formatted description of the validator.

func (ListUniqueValidator) Validate added in v0.11.0

func (ListUniqueValidator) Validate(values []string) error

Validate performs the validation on the given values.

func (ListUniqueValidator) ValidateList added in v0.11.0

ValidateList validates a list attribute value.

func (ListUniqueValidator) ValidateSet added in v0.11.0

ValidateSet validates a set attribute value. Note: Sets are inherently unique, so this always passes.

type MapKeysMatchValidator added in v0.10.0

type MapKeysMatchValidator struct {
	// contains filtered or unexported fields
}

MapKeysMatchValidator validates that map keys match a set of allowed or required keys.

func NewMapKeysMatch added in v0.10.0

func NewMapKeysMatch(allowedKeys, requiredKeys []string) *MapKeysMatchValidator

NewMapKeysMatch creates a validator that checks map keys against allowed and required sets. If allowedKeys is empty, all keys are allowed. If requiredKeys is provided, those keys must be present.

func (*MapKeysMatchValidator) Validate added in v0.10.0

func (v *MapKeysMatchValidator) Validate(keys []string) error

Validate checks if the provided map keys satisfy the allowed/required constraints.

type MutuallyExclusiveValidator added in v0.10.0

type MutuallyExclusiveValidator struct{}

MutuallyExclusiveValidator validates that only one of the provided values is set (non-null/non-empty).

func NewMutuallyExclusive added in v0.10.0

func NewMutuallyExclusive() *MutuallyExclusiveValidator

NewMutuallyExclusive creates a new MutuallyExclusiveValidator.

func (*MutuallyExclusiveValidator) Validate added in v0.10.0

func (v *MutuallyExclusiveValidator) Validate(values []string) error

Validate returns nil when exactly one of the provided values is set. A value is considered "set" if it is non-empty.

type NonEmptyListValidator added in v0.10.0

type NonEmptyListValidator struct{}

NonEmptyListValidator validates that a list is not empty.

func NewNonEmptyList added in v0.10.0

func NewNonEmptyList() *NonEmptyListValidator

NewNonEmptyList creates a new NonEmptyListValidator.

func (*NonEmptyListValidator) Validate added in v0.10.0

func (v *NonEmptyListValidator) Validate(values []string) error

Validate returns nil when the provided list is not empty.

type SetEqualsValidator added in v0.1.8

type SetEqualsValidator struct {
	// contains filtered or unexported fields
}

SetEqualsValidator compares two lists of strings for set equality (order-independent, unique elements). The validator holds the expected list and validates an input list against it.

func NewSetEquals added in v0.1.8

func NewSetEquals(expected []string) *SetEqualsValidator

NewSetEquals creates a new SetEqualsValidator from the expected values.

func (*SetEqualsValidator) Validate added in v0.1.8

func (v *SetEqualsValidator) Validate(values []string) error

Validate returns nil when the provided list has the same unique elements as the expected list. Duplicates in either slice are ignored for comparison purposes.

type StringLengthValidator added in v0.1.4

type StringLengthValidator struct {
	Min *int
	Max *int
}

StringLengthValidator enforces minimum and/or maximum string length. If min or max are nil, that side of validation is skipped.

func NewStringLengthValidator added in v0.1.4

func NewStringLengthValidator(minLen, maxLen *int) StringLengthValidator

NewStringLengthValidator creates a new instance.

func (StringLengthValidator) Description added in v0.1.4

func (v StringLengthValidator) Description(_ context.Context) string

Description returns a human-readable description of the validator.

func (StringLengthValidator) MarkdownDescription added in v0.1.4

func (v StringLengthValidator) MarkdownDescription(ctx context.Context) string

MarkdownDescription returns a Markdown formatted description of the validator.

func (StringLengthValidator) ValidateString added in v0.1.4

ValidateString performs the actual validation logic.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL