Documentation
¶
Index ¶
Constants ¶
const ValidationTTL = 48 * time.Hour
ValidationTTL is the time available to validate a custom domain registration.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Domain ¶
type Domain struct {
ID string `gorm:"unique;primaryKey;autoIncrement"`
Domain string `gorm:"unique"` // Domain records must be unique, this avoids domain reuse across accounts.
AccountID string `gorm:"index"`
TargetCluster string // The proxy cluster this domain should be validated against
Type Type `gorm:"-"`
Validated bool
ValidationExpiresAt *time.Time `gorm:"index"`
// SupportsCustomPorts is populated at query time for free domains from the
// proxy cluster capabilities. Not persisted.
SupportsCustomPorts *bool `gorm:"-"`
// RequireSubdomain is populated at query time. When true, the domain
// cannot be used bare and a subdomain label must be prepended. Not persisted.
RequireSubdomain *bool `gorm:"-"`
// SupportsCrowdSec is populated at query time from proxy cluster capabilities.
// Not persisted.
SupportsCrowdSec *bool `gorm:"-"`
// SupportsPrivate is populated at query time from proxy cluster capabilities. Not persisted.
SupportsPrivate *bool `gorm:"-"`
}
type Manager ¶
type Manager interface {
GetDomains(ctx context.Context, accountID, userID string) ([]*Domain, error)
CreateDomain(ctx context.Context, accountID, userID, domainName, targetCluster string) (*Domain, error)
DeleteDomain(ctx context.Context, accountID, userID, domainID string) error
ValidateDomain(ctx context.Context, accountID, userID, domainID string) error
GetClusterDomains() []string
}
type ValidationError ¶ added in v0.82.0
type ValidationError struct {
Reason ValidationReason
Message string
}
ValidationError is a validation failure whose message is safe to show to the user.
func NewValidationError ¶ added in v0.82.0
func NewValidationError(reason ValidationReason, format string, args ...any) *ValidationError
NewValidationError returns a ValidationError with a formatted message.
func (*ValidationError) Error ¶ added in v0.82.0
func (e *ValidationError) Error() string
Error returns the user-facing message.
type ValidationReason ¶ added in v0.82.0
type ValidationReason string
ValidationReason classifies why a custom domain failed validation.
const ( ValidationReasonCNAMENotFound ValidationReason = "cname_not_found" ValidationReasonCNAMEMismatch ValidationReason = "cname_mismatch" ValidationReasonLookupFailed ValidationReason = "lookup_failed" ValidationReasonExpired ValidationReason = "validation_expired" ValidationReasonNoTargetCluster ValidationReason = "no_target_cluster" )
type Validator ¶
type Validator struct {
Resolver resolver
}
func NewValidator ¶
func NewValidator(resolver resolver) *Validator
NewValidator initializes a validator with a specific DNS Resolver. If a Validator is used without specifying a Resolver, then it will use the net.DefaultResolver.
func (*Validator) IsValid ¶
IsValid looks up the CNAME record for the passed domain with a prefix and compares it against the acceptable domains. If the returned CNAME matches any accepted domain, it will return true, otherwise, including in the event of a DNS error, it will return false. The comparison is very simple, so wildcards will not match if included in the acceptable domain list.
func (*Validator) Validate ¶ added in v0.82.0
Validate validates a custom domain and returns the matched cluster address. On failure it returns a *ValidationError whose message is safe to show to the user.
func (*Validator) ValidateWithCluster ¶
func (v *Validator) ValidateWithCluster(ctx context.Context, domain string, accept []string) (string, bool)
ValidateWithCluster validates a custom domain and returns the matched cluster address. Returns the cluster address and true if valid, or empty string and false if invalid.