Public source validation / validate (push) Failing after 3m8s
39 lines
873 B
Go
39 lines
873 B
Go
package host
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// RawSource is the narrow read-only boundary implemented by an authenticated
|
|
// agent or another approved host telemetry source. It returns one bounded
|
|
// source snapshot; it cannot execute arbitrary host commands.
|
|
type RawSource interface {
|
|
Snapshot(context.Context) (RawSnapshot, error)
|
|
}
|
|
|
|
type Adapter struct {
|
|
Source RawSource
|
|
Limits Limits
|
|
Policy Policy
|
|
Now func() time.Time
|
|
}
|
|
|
|
func (a Adapter) Snapshot(ctx context.Context) (Snapshot, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return Snapshot{}, err
|
|
}
|
|
if a.Source == nil {
|
|
return UnknownSnapshot(time.Now().UTC(), "host", "agent", "source_unavailable"), nil
|
|
}
|
|
raw, err := a.Source.Snapshot(ctx)
|
|
if err != nil {
|
|
return Snapshot{}, err
|
|
}
|
|
now := time.Now().UTC()
|
|
if a.Now != nil {
|
|
now = a.Now()
|
|
}
|
|
return Normalize(raw, now, a.Limits, a.Policy)
|
|
}
|