verifieddomain

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: GPL-3.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package verifieddomain is the domain model for tenant-scoped DNS-TXT domain-ownership verification. A verified row proves a tenant controls an email domain and is the trust boundary that gates SSO JIT auto-provisioning.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when no matching verified-domain row exists.
	ErrNotFound = fmt.Errorf("%w: verified domain not found", shared.ErrNotFound)
	// ErrAlreadyExists is returned when the tenant already has a row for the domain.
	ErrAlreadyExists = fmt.Errorf("%w: domain already added for this tenant", shared.ErrConflict)
	// ErrInvalidDomain is returned when a domain fails normalization/validation.
	ErrInvalidDomain = fmt.Errorf("%w: invalid domain", shared.ErrValidation)
	// ErrBlockedDomain is returned when a shared/public consumer domain is submitted;
	// such domains can never be owned by a single tenant.
	ErrBlockedDomain = fmt.Errorf("%w: shared/public domain cannot be verified", shared.ErrValidation)
)

Functions

func NormalizeDomain

func NormalizeDomain(raw string) (string, error)

NormalizeDomain lowercases, trims, strips a trailing dot / leading "@", and validates the shape of a DNS domain name. It rejects wildcards, whitespace, schemes, and paths so a domain claim is an exact hostname.

Types

type Repository

type Repository interface {
	Create(ctx context.Context, d *VerifiedDomain) error
	Update(ctx context.Context, d *VerifiedDomain) error
	Delete(ctx context.Context, tenantID, id shared.ID) error
	GetByID(ctx context.Context, tenantID, id shared.ID) (*VerifiedDomain, error)
	GetByTenantAndDomain(ctx context.Context, tenantID shared.ID, domain string) (*VerifiedDomain, error)
	ListByTenant(ctx context.Context, tenantID shared.ID) ([]*VerifiedDomain, error)
	// ListDueForRecheck returns verified rows whose last_checked_at is null or
	// older than `checkedBefore`, across all tenants, capped at `limit`. Used by
	// the background re-verify controller.
	ListDueForRecheck(ctx context.Context, checkedBefore time.Time, limit int) ([]*VerifiedDomain, error)
}

Repository defines persistence operations for verified domains. All tenant-scoped methods MUST filter by tenant_id (multi-tenant isolation).

type Status

type Status string

Status is the verification lifecycle state of a domain.

const (
	// StatusPending — the TXT record has not yet been observed.
	StatusPending Status = "pending"
	// StatusVerified — the expected TXT record was observed; the tenant owns it.
	StatusVerified Status = "verified"
	// StatusFailed — a previously verified record disappeared (lapsed/hijacked),
	// or verification was explicitly abandoned. Fail-closed: no JIT authority.
	StatusFailed Status = "failed"
)

func (Status) IsValid

func (s Status) IsValid() bool

IsValid reports whether s is a known status.

type VerifiedDomain

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

VerifiedDomain is a tenant's claim over an email domain, proven via DNS TXT.

func New

func New(id, tenantID shared.ID, domain, token string) (*VerifiedDomain, error)

New creates a pending VerifiedDomain. The domain is normalized and validated; callers must supply a non-empty verification token. It does NOT enforce the shared/public-domain blocklist — that policy lives in the service layer.

func Reconstruct

func Reconstruct(
	id, tenantID shared.ID,
	domain, token string,
	status Status,
	verifiedAt, lastCheckedAt *time.Time,
	createdAt, updatedAt time.Time,
) *VerifiedDomain

Reconstruct rebuilds a VerifiedDomain from persistence without validation.

func (*VerifiedDomain) CreatedAt

func (d *VerifiedDomain) CreatedAt() time.Time

func (*VerifiedDomain) Domain

func (d *VerifiedDomain) Domain() string

func (*VerifiedDomain) ID

func (d *VerifiedDomain) ID() shared.ID

Getters.

func (*VerifiedDomain) IsVerified

func (d *VerifiedDomain) IsVerified() bool

func (*VerifiedDomain) LastCheckedAt

func (d *VerifiedDomain) LastCheckedAt() *time.Time

func (*VerifiedDomain) MarkChecked

func (d *VerifiedDomain) MarkChecked(t time.Time)

MarkChecked records that a verification attempt ran at t without success. A still-pending domain stays pending; a previously verified domain whose record vanished is downgraded to failed (fail-closed). Never promotes to verified.

func (*VerifiedDomain) MarkVerified

func (d *VerifiedDomain) MarkVerified(t time.Time)

MarkVerified stamps the domain as verified at t and records the check time.

func (*VerifiedDomain) Status

func (d *VerifiedDomain) Status() Status

func (*VerifiedDomain) TenantID

func (d *VerifiedDomain) TenantID() shared.ID

func (*VerifiedDomain) UpdatedAt

func (d *VerifiedDomain) UpdatedAt() time.Time

func (*VerifiedDomain) VerificationToken

func (d *VerifiedDomain) VerificationToken() string

func (*VerifiedDomain) VerifiedAt

func (d *VerifiedDomain) VerifiedAt() *time.Time

Jump to

Keyboard shortcuts

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