domain

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package domain manages workspace-owned domains: registration, DNS-verified ownership, and the default TLS policy routes inherit. It is the first-class owned-hostname resource (distinct from the declarative Route kind).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = errors.New("domain not found")
	ErrNameTaken    = errors.New("this domain is already registered in the workspace")
	ErrNameRequired = errors.New("domain name is required")
	ErrInvalidName  = errors.New("invalid domain name")
	// ErrNameImmutable means a caller tried to rename an existing domain. The name
	// is fixed at creation; delete and re-create to change it.
	ErrNameImmutable = errors.New("the domain name cannot be changed; delete the domain and add it again")
	// ErrVerificationFailed means the expected TXT record was not found.
	ErrVerificationFailed = errors.New("DNS verification record not found")
	// ErrProviderNotFound means the linked DNS provider does not exist in the
	// workspace (or no automator is wired).
	ErrProviderNotFound = errors.New("DNS provider not found in this workspace")
	// ErrDomainBanned means the domain has been banned by a platform admin and
	// cannot be verified or served.
	ErrDomainBanned = errors.New("this domain has been banned by a platform administrator")
	// ErrDomainClaimed means the hostname is already verified by another workspace
	// (or overlaps a verified wildcard elsewhere). At most one workspace may own a
	// verified domain platform-wide, so its routes can't collide with another
	// tenant's. Registration stays open; only verification is exclusive.
	ErrDomainClaimed = errors.New("this domain is already verified by another workspace")
)

Functions

This section is empty.

Types

type DNSAutomator

type DNSAutomator interface {
	// ProviderExists reports whether a provider id belongs to the workspace.
	ProviderExists(workspaceID, providerID uint) bool
	// EnsureVerificationRecord creates the ownership TXT for a provider-connected
	// domain (no-op when the domain has no provider).
	EnsureVerificationRecord(ctx context.Context, d *models.Domain) error
	// CleanupDomain removes the managed records for a deleted domain.
	CleanupDomain(ctx context.Context, d *models.Domain) error
}

DNSAutomator drives the records Miabi manages for a provider-connected domain. Injected (nil = manual only): the verification TXT is created automatically and the ledger is cleaned up on delete. Implemented by the dnsprovider service.

type Input

type Input struct {
	Name     string
	TLSMode  models.DomainTLSMode
	Wildcard bool
}

Input is the create/update payload for a domain.

type ProxyResyncer

type ProxyResyncer interface {
	SyncWorkspaceProxy(ctx context.Context, workspaceID uint) error
}

ProxyResyncer re-renders a workspace's gateway config. The domain service calls it when ownership changes (verified ⇄ unverified) so the workspace's routes go live or offline without further action. Implemented by the route service; injected after construction (nil-safe).

type Service

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

Service manages domains.

func NewService

func NewService(repo *repositories.DomainRepository) *Service

NewService wires the domain service.

func (*Service) Ban

func (s *Service) Ban(ctx context.Context, workspaceID, id uint, reason string) (*models.Domain, error)

Ban blocks a domain platform-wide (a platform-admin action, e.g. for abuse). A banned domain is never served — its routes are forced offline on the next re-sync, triggered here — and it can no longer be verified. Verification state is left intact so an unban restores the prior status.

func (*Service) Create

func (s *Service) Create(workspaceID uint, in Input) (*models.Domain, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, workspaceID, id uint) error

func (*Service) ForceVerify

func (s *Service) ForceVerify(ctx context.Context, workspaceID, id uint) (*models.Domain, error)

ForceVerify marks a domain verified without a DNS check — a platform-admin override for private-DNS or otherwise unreachable zones. It clears any prior failure state and re-syncs the workspace so the domain's routes go live. Use sparingly: it bypasses the ownership proof Verify enforces.

func (*Service) Get

func (s *Service) Get(workspaceID, id uint) (*models.Domain, error)

func (*Service) List

func (s *Service) List(workspaceID uint) ([]models.Domain, error)

func (*Service) Reverify

func (s *Service) Reverify(ctx context.Context) error

Reverify re-checks ownership for every verified, manually-managed domain and un-verifies any whose TXT record has been missing for verifyMissThreshold consecutive runs (transient DNS failures are absorbed by the threshold). On an un-verify it re-syncs the workspace so the domain's routes drop offline. Provider-automated domains are skipped — the DNS reconcile cron reasserts their records. Intended to be driven by a periodic job.

func (*Service) SetDNSAutomator

func (s *Service) SetDNSAutomator(a DNSAutomator)

SetDNSAutomator wires DNS automation for provider-connected domains (nil-safe; nil leaves the manual copy-paste flow as the only path).

func (*Service) SetDNSProvider

func (s *Service) SetDNSProvider(workspaceID, id uint, providerID *uint) (*models.Domain, error)

SetDNSProvider links (or, with nil, unlinks) a connected DNS provider to a domain so ownership verification (and later app records) is automated. A nil providerID reverts the domain to the manual copy-paste flow.

func (*Service) SetProxyResyncer

func (s *Service) SetProxyResyncer(r ProxyResyncer)

SetProxyResyncer wires the gateway re-sync triggered on a verification change (nil-safe; nil disables the automatic route go-live/offline).

func (*Service) Unban

func (s *Service) Unban(ctx context.Context, workspaceID, id uint) (*models.Domain, error)

Unban lifts a domain ban and re-syncs the workspace so its routes can serve again (subject to the normal verification/privilege gate).

func (*Service) Update

func (s *Service) Update(workspaceID, id uint, in Input) (*models.Domain, error)

func (*Service) Verify

func (s *Service) Verify(ctx context.Context, workspaceID, id uint) (*models.Domain, error)

Verify checks the domain's ownership TXT record and, on success, marks it verified. For a provider-connected domain it first creates the TXT itself (idempotent) and retries the lookup briefly to absorb propagation, so no manual DNS step is needed. The lookup reads live DNS, so re-verification is idempotent.

Jump to

Keyboard shortcuts

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