Documentation
¶
Overview ¶
Package joindomains is the module for a Workspace's Join domains: a domain an Owner proves control of with a DNS TXT record so that, in a later step, Users with an address on it can join the Workspace. /site is a thin adapter over it.
It is one of the few holders of the raw *ent.Client (docs/architecture.md): a domain is verified by one Workspace across the Instance, so looking up who holds it, and moving it from the Workspace that held it to the one that now proves it, happens before and across Workspace scopes. Everything else goes through the caller's *ent.Scoped. The periodic re-check of verified domains (Due, Recheck) runs on the raw client too: a job lists the due domains of every Workspace and scopes to each one's Workspace only after its row is loaded.
Index ¶
- Constants
- Variables
- func HolderIn(ctx context.Context, c *ent.Client, domain string) (*ent.JoinDomain, error)
- func Verified(d *ent.JoinDomain) bool
- type Module
- func (m *Module) Add(ctx context.Context, s *ent.Scoped, raw string) (*ent.JoinDomain, error)
- func (m *Module) Due(ctx context.Context, limit int) ([]int64, error)
- func (m *Module) Holder(ctx context.Context, domain string) (*ent.JoinDomain, error)
- func (m *Module) List(ctx context.Context, s *ent.Scoped) ([]*ent.JoinDomain, error)
- func (m *Module) Recheck(ctx context.Context, id int64) (flipped bool, err error)
- func (m *Module) Remove(ctx context.Context, s *ent.Scoped, id int64) error
- func (m *Module) Verify(ctx context.Context, s *ent.Scoped, id int64) (*ent.JoinDomain, error)
- type Record
Constants ¶
const RecordLabel = "_sphericon-join."
RecordLabel is the label the TXT record sits under: _sphericon-join.<domain>.
Variables ¶
var ( // ErrAlreadyExists means the Workspace already has this domain. ErrAlreadyExists = errors.New("this domain is already added") // ErrRecordNotFound means the TXT record is not published (or carries another value). ErrRecordNotFound = errors.New("the TXT record was not found") // ErrHeldElsewhere means another Workspace has the domain verified and still publishes // its record. ErrHeldElsewhere = errors.New("another workspace has verified this domain") )
Functions ¶
func HolderIn ¶
HolderIn is Holder over a given client, so a transaction can read the holder it is about to join people to (the domain-join step of the accounts module). It reads the stored verification only and never looks at DNS.
func Verified ¶
func Verified(d *ent.JoinDomain) bool
Verified reports whether the domain is currently verified.
Types ¶
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module holds the shared collaborators; it is stateless otherwise.
func New ¶
func New(client *ent.Client, bus *events.Bus, lookup sending.TXTLookup, now func() time.Time, notify ownernotice.Notify) *Module
New builds the module. lookup is the injectable TXT resolver Sending domain verification uses; now is the clock the check times are stamped with; notify mails a Workspace's Owners when it loses a verified domain.
func (*Module) Add ¶
Add stores a pending claim of the domain with a fresh token. The domain is canonicalized (lower case, IDN as punycode); a malformed one is a *validation.Error, one the Workspace already has is ErrAlreadyExists. Another Workspace's claim, pending or verified, never blocks it.
func (*Module) Due ¶
Due returns up to limit ids of verified Join domains to re-check, across every Workspace, least-recently-checked first with never-checked ones before the rest (plain ascending order would put NULLs last in Postgres).
func (*Module) Holder ¶
Holder returns the Join domain row that has the domain verified, across every Workspace, or nil when none does. It is the Instance-wide lookup that runs before any Workspace scope exists.
func (*Module) Recheck ¶
Recheck re-reads a verified domain's TXT record. A record that is gone (or carries another value) reverts the domain to unverified at once, under the system actor, and mails the Workspace's Owners; it reports whether it did. A resolver failure is returned and changes nothing, so the job retries. A domain that is not verified (it changed since the job was queued) is left alone. Memberships are never touched.
func (*Module) Remove ¶
Remove deletes the claim, and only the claim: Memberships are never touched. An unknown id is ent's not-found error.
func (*Module) Verify ¶
Verify checks the TXT record live and verifies the domain when it is published. A domain another Workspace has verified is re-checked at the holder first: still published is ErrHeldElsewhere, gone moves the domain to this Workspace in one transaction, the holder's row becoming pending. An unpublished record is ErrRecordNotFound; a resolver failure is returned as is and changes nothing. A domain already verified here is returned as it is.