Files
ITWorx-Pulse-Public/internal/host/adapter.go
T
ITWorx Pulse release export bd774932d5
Public source validation / validate (push) Failing after 3m8s
Publish ITWorx Pulse source
2026-09-03 02:09:19 +02:00

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)
}