Documentation
¶
Index ¶
- func GetActor(ctx context.Context) string
- func GetCorrelationID(ctx context.Context) string
- func WithActor(ctx context.Context, actor string) context.Context
- func WithCorrelationID(ctx context.Context, correlationID string) context.Context
- type AuditEvent
- type Config
- type EventStatus
- type EventType
- type Logger
- type NoOpLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCorrelationID ¶
GetCorrelationID extracts the correlation ID from context. Returns empty string if no correlation ID is set.
Types ¶
type AuditEvent ¶
type AuditEvent struct {
// Timestamp is when the event occurred
Timestamp time.Time `json:"timestamp"`
// EventType categorizes the type of operation
EventType EventType `json:"event_type"`
// Actor is the user or service account that initiated the action
Actor string `json:"actor"`
// Resource identifies the target resource (e.g., "PR #123", "promotion-policy/prod")
Resource string `json:"resource"`
// Action describes what operation was performed (e.g., "merge", "trigger", "promote")
Action string `json:"action"`
// Status indicates whether the operation succeeded or failed
Status EventStatus `json:"status"`
// Metadata contains additional context-specific information
Metadata map[string]string `json:"metadata,omitempty"`
// CorrelationID links related events together for tracing
CorrelationID string `json:"correlation_id,omitempty"`
// Message provides human-readable description of the event
Message string `json:"message,omitempty"`
// Error contains error details if Status is Failed
Error string `json:"error,omitempty"`
}
AuditEvent represents a single auditable event in the system. Events are logged as structured JSON for analysis and compliance.
type Config ¶
type Config struct {
// BufferSize is the size of the event buffer channel.
// Default: 1000
BufferSize int
// FlushTimeout is the maximum time to wait when flushing events.
// Default: 5 seconds
FlushTimeout time.Duration
}
Config holds configuration for the audit logger.
type EventStatus ¶
type EventStatus string
EventStatus represents the outcome of an event
const ( // EventStatusSuccess indicates the operation succeeded EventStatusSuccess EventStatus = "success" // EventStatusFailed indicates the operation failed EventStatusFailed EventStatus = "failed" // EventStatusPending indicates the operation is in progress EventStatusPending EventStatus = "pending" // EventStatusSkipped indicates the operation was skipped EventStatusSkipped EventStatus = "skipped" )
type EventType ¶
type EventType string
EventType represents the type of audit event
const ( // EventTypePRMerged indicates a pull request was merged EventTypePRMerged EventType = "pr.merged" // EventTypePRQualified indicates a pull request was qualified EventTypePRQualified EventType = "pr.qualified" // EventTypePRDisqualified indicates a pull request was disqualified EventTypePRDisqualified EventType = "pr.disqualified" // EventTypePromotionTriggered indicates a promotion was triggered EventTypePromotionTriggered EventType = "promotion.triggered" // EventTypePromotionCompleted indicates a promotion completed EventTypePromotionCompleted EventType = "promotion.completed" // EventTypePromotionFailed indicates a promotion failed EventTypePromotionFailed EventType = "promotion.failed" // EventTypeExternalTestStarted indicates an external test execution started EventTypeExternalTestStarted EventType = "external_test.started" // EventTypeExternalTestCompleted indicates an external test execution completed EventTypeExternalTestCompleted EventType = "external_test.completed" // EventTypeExternalTestFailed indicates an external test execution failed EventTypeExternalTestFailed EventType = "external_test.failed" // EventTypeArgoCDSync indicates an ArgoCD sync operation was triggered EventTypeArgoCDSync EventType = "argocd.sync" // EventTypeArgoCDSyncCompleted indicates an ArgoCD sync completed EventTypeArgoCDSyncCompleted EventType = "argocd.sync_completed" // EventTypeArgoCDSyncFailed indicates an ArgoCD sync failed EventTypeArgoCDSyncFailed EventType = "argocd.sync_failed" // EventTypeConfigChanged indicates operator configuration was changed EventTypeConfigChanged EventType = "config.changed" // EventTypeConfigDeleted indicates operator configuration was deleted EventTypeConfigDeleted EventType = "config.deleted" // EventTypeAuthFailure indicates an authentication failure EventTypeAuthFailure EventType = "auth.failure" // EventTypeAuthSuccess indicates successful authentication EventTypeAuthSuccess EventType = "auth.success" // EventTypeWebhookReceived indicates a webhook was received EventTypeWebhookReceived EventType = "webhook.received" // EventTypeWebhookRejected indicates a webhook was rejected EventTypeWebhookRejected EventType = "webhook.rejected" )
type Logger ¶
type Logger interface {
// LogEvent records an audit event.
// Returns an error only if the event could not be queued for logging.
// The actual logging happens asynchronously.
LogEvent(ctx context.Context, event AuditEvent) error
// Close flushes any pending events and shuts down the logger.
// This should be called during graceful shutdown.
Close(ctx context.Context) error
}
Logger defines the interface for audit logging. Implementations must be non-blocking and handle errors gracefully.
func NewJSONLogger ¶
NewJSONLogger creates a new JSON audit logger that writes to stdout. Events are processed asynchronously to avoid blocking business logic. The logger must be closed with Close() during graceful shutdown.
func NewNoOpLogger ¶
func NewNoOpLogger() Logger
NewNoOpLogger creates a logger that discards all events.
type NoOpLogger ¶
type NoOpLogger struct{}
NoOpLogger is a no-op implementation of Logger for testing or disabling audit logging.
func (*NoOpLogger) Close ¶
func (n *NoOpLogger) Close(ctx context.Context) error
Close does nothing.
func (*NoOpLogger) LogEvent ¶
func (n *NoOpLogger) LogEvent(ctx context.Context, event AuditEvent) error
LogEvent discards the event.