Documentation
¶
Overview ¶
Package app holds the use cases of Arnakoff and the ports they consume. It depends on domain only (ADR 0002).
Index ¶
- Variables
- type Alert
- type Alerter
- type Case
- type Check
- type CheckOption
- type Checker
- type Clock
- type CompanyRegistry
- type DomainRegistry
- type FalseAlert
- type Jitter
- type Label
- type NoticeRegistry
- type Plan
- type Registries
- type Reloader
- type Scheduler
- type Score
- type Sleeper
- type SnapshotStore
- type SourceFetcher
- type SourceSync
- type Sync
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound means the registry answered that it holds no such entry: // an answer, not a failure. ErrNotFound = errors.New("not found in the registry") // ErrNotCovered means the registry does not cover this input, such as a // domain extension without an RDAP server. ErrNotCovered = errors.New("not covered by the registry") )
Registry errors, wrapped by the registry adapters and checked with errors.Is.
var ( ErrUnknownSource = errors.New("unknown source") ErrDuplicateSource = errors.New("duplicate source") )
Sync errors, checked with errors.Is.
var ErrInterval = errors.New("sync interval must be positive")
ErrInterval means a plan has no positive interval.
var ErrNoSnapshot = errors.New("no stored snapshot")
ErrNoSnapshot is returned by SnapshotStore.Load when it holds no snapshot of the source.
var ErrUnknownLabel = errors.New("unknown corpus label")
ErrUnknownLabel means a case is labelled neither scam nor legit.
Functions ¶
This section is empty.
Types ¶
type Alerter ¶ added in v0.19.0
Alerter tells the operator that a source could not be synced or reloaded. It reports its own failures: the caller has nothing to do about them.
type Check ¶ added in v0.23.0
type Check struct {
// contains filtered or unexported fields
}
Check consults the registries that cover an input, all at once, and reports the state of each. It is safe for concurrent use when the registries are.
func NewCheck ¶ added in v0.23.0
func NewCheck(r Registries, opts ...CheckOption) *Check
NewCheck returns a Check of the registries.
type CheckOption ¶ added in v0.24.0
type CheckOption func(*Check)
CheckOption configures a Check.
func WithTimeout ¶ added in v0.24.0
func WithTimeout(d time.Duration) CheckOption
WithTimeout bounds every check to d, or to the deadline of its context when that comes first.
type CompanyRegistry ¶ added in v0.23.0
type CompanyRegistry interface {
// Source names the registry in reports.
Source() domain.Source
// Lookup returns the company n identifies.
Lookup(ctx context.Context, n domain.SIREN) (domain.Company, error)
}
CompanyRegistry reads what the company register publishes about a company.
type DomainRegistry ¶ added in v0.23.0
type DomainRegistry interface {
// Source names the registry in reports.
Source() domain.Source
// Lookup returns the registration of d's registrable domain.
Lookup(ctx context.Context, d domain.Domain) (domain.Registration, error)
}
DomainRegistry reads what a domain registry publishes about a domain.
type FalseAlert ¶ added in v0.23.0
type FalseAlert struct {
// Input is the normalised input.
Input string
// Level is the most severe level it got.
Level domain.Level
}
FalseAlert is a legit case that got an attention or an alerte.
type Jitter ¶ added in v0.19.0
Jitter returns a random duration from 0 up to, but not including, max.
type NoticeRegistry ¶ added in v0.23.0
type NoticeRegistry interface {
// Source names the registry in reports.
Source() domain.Source
// Notices returns the notices about the company n identifies.
Notices(ctx context.Context, n domain.SIREN) ([]domain.Notice, error)
}
NoticeRegistry reads the legal notices published about a company.
type Registries ¶ added in v0.23.0
type Registries struct {
Domains DomainRegistry
Companies CompanyRegistry
Notices NoticeRegistry
}
Registries are the registries a Check consults; a nil one is left out of the reports.
func (Registries) Without ¶ added in v0.23.0
func (r Registries) Without(leave func(domain.Source) bool) Registries
Without returns r less the registries leave reports true for.
type Reloader ¶ added in v0.19.0
type Reloader struct {
// contains filtered or unexported fields
}
Reloader restores, at an interval, the snapshots the sync process stored, so that the API process serves them without a restart. It alerts when a source starts failing to reload, not again until it has recovered.
func NewReloader ¶ added in v0.19.0
NewReloader returns a Reloader of the sources of s, checking every interval.
type Scheduler ¶ added in v0.19.0
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler syncs each planned source at its interval, plus a jitter, and alerts on every sync that fails or is rejected.
func NewScheduler ¶ added in v0.19.0
func NewScheduler(s *Sync, sleeper Sleeper, alerter Alerter, jitter Jitter, plans ...Plan) (*Scheduler, error)
NewScheduler returns a Scheduler of plans, or ErrUnknownSource, ErrDuplicateSource or ErrInterval for a plan s cannot follow.
func (*Scheduler) Once ¶ added in v0.19.0
Once syncs each of sources once, or every planned source when none is given, alerts on each failure and joins the errors. It returns ErrUnknownSource without syncing anything when a source is not planned.
type Score ¶ added in v0.23.0
type Score struct {
// Scams is the number of scam cases.
Scams int
// ScamsAlerted counts the scams with at least one alerte.
ScamsAlerted int
// ScamsFlagged counts the scams with at least one attention or alerte.
ScamsFlagged int
// Legit is the number of legit cases.
Legit int
// LegitAlerted counts the legit cases with at least one alerte; it must
// stay 0.
LegitAlerted int
// FalseAlerts lists the legit cases with at least one attention or
// alerte, in corpus order.
FalseAlerts []FalseAlert
// their score proves less.
Unavailable int
}
Score counts the corpus cases each signal level reached.
type Sleeper ¶ added in v0.19.0
type Sleeper interface {
// Sleep returns after d, or with the error of ctx once it is done.
Sleep(ctx context.Context, d time.Duration) error
}
Sleeper pauses a scheduling loop; tests inject one that does not wait.
type SnapshotStore ¶
type SnapshotStore interface {
// Save durably replaces the stored snapshot of s.Source.
Save(ctx context.Context, s domain.Snapshot) error
// Load returns the stored snapshot of source, or ErrNoSnapshot.
Load(ctx context.Context, source domain.Source) (domain.Snapshot, error)
}
SnapshotStore keeps the last valid snapshot of each source across restarts and between the sync and API processes.
func DryRun ¶ added in v0.19.0
func DryRun(st SnapshotStore) SnapshotStore
DryRun returns a store that reads st and keeps nothing: a Sync on it, once restored, validates new snapshots against the stored ones without replacing them.
type SourceFetcher ¶
type SourceFetcher interface {
// Spec declares the source and what a sane file of it holds.
Spec() domain.SnapshotSpec
// Fetch downloads the source and parses it into a snapshot. Sync sets
// its FetchedAt.
Fetch(ctx context.Context) (domain.Snapshot, error)
}
SourceFetcher downloads and parses one upstream source.
type SourceSync ¶
type SourceSync struct {
Source domain.Source
// LastSuccess is when the snapshot in service was fetched, zero when
// none is.
LastSuccess time.Time
// LastFailure is when the last failed or rejected sync ran, zero when
// none did. It is kept after a later success.
LastFailure time.Time
// LastError is why that sync failed.
LastError error
// Rows is the number of rows of the snapshot in service.
Rows int
// Newest is the date of the most recent entry in service, zero when the
// source dates none.
Newest time.Time
}
SourceSync is the sync state of one source, as /v1/sources shows it.
type Sync ¶
type Sync struct {
// contains filtered or unexported fields
}
Sync downloads each source, validates the new snapshot against the connector's spec and the last valid one, stores it, then swaps it in for the readers. A rejected snapshot leaves the last valid one in service. It is safe for concurrent use.
func NewSync ¶
func NewSync(store SnapshotStore, clock Clock, fetchers ...SourceFetcher) (*Sync, error)
NewSync returns a Sync of the sources the fetchers declare, or ErrDuplicateSource when two declare the same one.
func (*Sync) Restore ¶
Restore puts in service the stored snapshot of every source when it is valid and newer than the one in service. It runs at startup, and in the API process to pick up what the sync process stored. A source with no stored snapshot is skipped; errors of the others are joined.
func (*Sync) Run ¶
Run syncs every source in turn and joins their errors: one source failing does not stop the others.
func (*Sync) Snapshot ¶
Snapshot returns the snapshot in service for source, if any. It is shared with every reader: treat it as read-only.
func (*Sync) States ¶
func (s *Sync) States() []SourceSync
States returns the sync state of every source, in declaration order.