2021-07-08 15:50:25 -04:00
// Copyright (c) HashiCorp, Inc.
2021-08-30 19:02:48 -04:00
// SPDX-License-Identifier: BUSL-1.1
2023-02-02 17:15:17 -08:00
2021-06-06 07:57:24 -04:00
package event
import (
"fmt"
)
// EventerConfig supplies all the configuration needed to create/config an Eventer.
type EventerConfig struct {
2021-08-30 19:02:48 -04:00
AuditEnabled bool `hcl:"audit_enabled"` // AuditEnabled specifies if audit events should be emitted.
ObservationsEnabled bool `hcl:"observations_enabled"` // ObservationsEnabled specifies if observation events should be emitted.
SysEventsEnabled bool `hcl:"sysevents_enabled"` // SysEventsEnabled specifies if sysevents should be emitted.
2023-09-13 16:13:18 -07:00
TelemetryEnabled bool `hcl:"telemetry_enabled"` // TelemetryEnabled specifies if telemetry events should be emitted.
2021-08-30 19:02:48 -04:00
Sinks [] * SinkConfig `hcl:"-"` // Sinks are all the configured sinks
2023-04-14 20:01:14 -04:00
ErrorEventsDisabled bool `hcl:"-"` // ErrorEventsDisabled will disable error events from being emitted. This should only be used to turn off error events in tests.
2021-06-06 07:57:24 -04:00
}
2021-07-08 15:50:25 -04:00
// Validate will Validate the config. A config isn't required to have any
2021-06-06 07:57:24 -04:00
// sinks to be valid.
2021-07-08 15:50:25 -04:00
func ( c * EventerConfig ) Validate () error {
const op = "event.(EventerConfig).Validate"
2021-06-06 07:57:24 -04:00
for i , s := range c . Sinks {
2021-08-04 14:01:58 -04:00
if err := s . Validate (); err != nil {
2021-06-22 16:23:27 -05:00
return fmt . Errorf ( "%s: sink %d is invalid: %w" , op , i , err )
2021-06-06 07:57:24 -04:00
}
}
2023-09-13 16:13:18 -07:00
if ! c . ObservationsEnabled && c . TelemetryEnabled {
return fmt . Errorf ( "%s: telemetry events require observation event to be enabled: %w" , op , ErrInvalidParameter )
}
2021-06-06 07:57:24 -04:00
return nil
}