mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-03 18:43:38 +01:00
I added Schema v26 content-free Infrastructure Map topology read telemetry for external live GET /api/agent/topology requests (total read days, CLI days, MCP days, anonymized days, and an explicit availability flag) alongside hardened opt-out zero-write boundaries, credential-binding checks, and read-only SQLite/config guards. Key changes: - Added a dedicated root-scoped daily tally store (infrastructure_map_topology_tally.json) with strict schema validation, fail-closed degraded sidecar accounting, and strict zero-write guarantees when telemetry is disabled by settings or PULSE_TELEMETRY=false. - Added X-Pulse-Agent-Surface attribution for pulse-cli and MCP clients while filtering out first-party browser traffic, mock-mode snapshots, and unverified monitor states. - Updated Settings payload preview, localization copy, shipped PRIVACY.md disclosure, integration specs, and schema parity tooling for Schema v26. - Hardened host/agent token hash binding, self-uninstall live authority and durable hash-scoped tombstones, Patrol investigation replay-floor provenance, bounded non-blocking regular-file config reads, and cold read-only legacy SQLite history queries.
98 lines
3.5 KiB
Go
98 lines
3.5 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/config"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/mock"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type reportingActivityRecorder interface {
|
|
RecordReportingActivity(config.ReportingActivityEvent) error
|
|
}
|
|
|
|
type reportingActivityConsentRecorder interface {
|
|
RecordReportingActivityWithRootConsent(*config.ConfigPersistence, config.ReportingActivityEvent, uint64) (bool, error)
|
|
}
|
|
|
|
func (h *ReportingHandlers) recordReportingActivity(event config.ReportingActivityEvent) {
|
|
if h == nil || mock.IsMockEnabled() || h.settingsStore == nil {
|
|
return
|
|
}
|
|
if consentRecorder, ok := h.settingsStore.(reportingActivityConsentRecorder); ok {
|
|
gen := config.TelemetryConsentGeneration()
|
|
if _, err := consentRecorder.RecordReportingActivityWithRootConsent(nil, event, gen); err != nil {
|
|
// No report, scope, recipient, schedule or error content enters this log.
|
|
log.Debug().Msg("Unable to retain aggregate reporting activity")
|
|
}
|
|
return
|
|
}
|
|
recorder, ok := h.settingsStore.(reportingActivityRecorder)
|
|
if !ok {
|
|
return
|
|
}
|
|
if settings, err := h.settingsStore.LoadSystemSettings(); err != nil {
|
|
return
|
|
} else if settings != nil && settings.TelemetryEnabled != nil && !*settings.TelemetryEnabled {
|
|
return
|
|
}
|
|
if err := recorder.RecordReportingActivity(event); err != nil {
|
|
// No report, scope, recipient, schedule or error content enters this log.
|
|
log.Debug().Msg("Unable to retain aggregate reporting activity")
|
|
}
|
|
}
|
|
|
|
func (h *ReportingHandlers) recordReportingDownload(r *http.Request, kind string, count int, err error, expected int) {
|
|
if r == nil || r.Method == http.MethodHead || r.Context().Err() != nil || err != nil || count != expected {
|
|
return
|
|
}
|
|
h.recordReportingActivity(config.ReportingActivityEvent{At: time.Now().UTC(), Kind: kind, Event: "generated"})
|
|
}
|
|
|
|
func reportingActivityDigest(value string) string {
|
|
sum := sha256.Sum256([]byte(value))
|
|
return hex.EncodeToString(sum[:])
|
|
}
|
|
|
|
func reportingActivityPeriod(schedule config.ReportSchedule, start, end time.Time, now time.Time) string {
|
|
if start.IsZero() || end.IsZero() {
|
|
anchor := now
|
|
if schedule.RunWindowEnd != nil {
|
|
anchor = *schedule.RunWindowEnd
|
|
}
|
|
var err error
|
|
start, end, err = reportScheduleWindow(schedule, anchor, schedule.RunManual)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
}
|
|
location, err := reportScheduleLocation(schedule.Cadence.Timezone)
|
|
if err != nil || !end.After(start) {
|
|
return ""
|
|
}
|
|
// Day boundaries describe the reporting window. A retry or same-day rerun
|
|
// cannot become repeat use merely because its clock time changed.
|
|
return reportingActivityDigest(start.In(location).Format(time.DateOnly) + "\x00" + end.In(location).Format(time.DateOnly))
|
|
}
|
|
|
|
func (h *ReportingHandlers) recordReportingSuccessfulPeriod(ctx context.Context, schedule config.ReportSchedule, period string, at time.Time) {
|
|
if schedule.ID == "" || period == "" || schedule.LastRunStatus != config.ReportScheduleLastRunOK {
|
|
return
|
|
}
|
|
key := reportingActivityDigest(GetOrgID(ctx) + "\x00" + schedule.Kind + "\x00" + schedule.ID)
|
|
h.recordReportingActivity(config.ReportingActivityEvent{At: at, Kind: schedule.Kind, Event: "successful_period", ScheduleKey: key, PeriodKey: period})
|
|
}
|
|
|
|
func (h *ReportingHandlers) recordReportingDeliveryFailure(kind string, status string, at time.Time) {
|
|
event := "delivery_failed"
|
|
if status == "unconfirmed" {
|
|
event = "delivery_unconfirmed"
|
|
}
|
|
h.recordReportingActivity(config.ReportingActivityEvent{At: at, Kind: kind, Event: event})
|
|
}
|