audithook

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package audithook bridges Ledger lifecycle events to an audit trail backend.

It defines a local Recorder interface so the package does not import Chronicle directly. Callers inject a RecorderFunc adapter that bridges to Chronicle at wiring time.

Index

Constants

View Source
const (
	// Plan actions
	ActionPlanCreated  = "plan.created"
	ActionPlanUpdated  = "plan.updated"
	ActionPlanArchived = "plan.archived"

	// Subscription actions
	ActionSubscriptionCreated         = "subscription.created"
	ActionSubscriptionUpgraded        = "subscription.upgraded"
	ActionSubscriptionDowngraded      = "subscription.downgraded"
	ActionSubscriptionCanceled        = "subscription.canceled"
	ActionSubscriptionCancelScheduled = "subscription.cancel_scheduled"
	ActionSubscriptionExpired         = "subscription.expired"
	ActionSubscriptionRenewed         = "subscription.renewed"
	ActionSubscriptionTrialEnded      = "subscription.trial_ended"

	// Usage actions
	ActionUsageIngested = "usage.ingested"
	ActionUsageFlushed  = "usage.flushed"

	// Entitlement actions
	ActionEntitlementChecked = "entitlement.checked"
	ActionEntitlementDenied  = "entitlement.denied"
	ActionQuotaExceeded      = "quota.exceeded"
	ActionSoftLimitReached   = "soft_limit.reached"

	// Invoice actions
	ActionInvoiceGenerated = "invoice.generated"
	ActionInvoiceFinalized = "invoice.finalized"
	ActionInvoicePaid      = "invoice.paid"
	ActionInvoiceFailed    = "invoice.failed"
	ActionInvoiceVoided    = "invoice.voided"
	ActionInvoicePastDue   = "invoice.past_due"

	// Provider actions
	ActionProviderSync     = "provider.sync"
	ActionWebhookReceived  = "webhook.received"
	ActionWebhookProcessed = "webhook.processed"
)

Action constants for audit events.

View Source
const (
	ResourcePlan         = "plan"
	ResourceSubscription = "subscription"
	ResourceUsage        = "usage"
	ResourceEntitlement  = "entitlement"
	ResourceInvoice      = "invoice"
	ResourceProvider     = "provider"
	ResourceWebhook      = "webhook"
)

Resource constants for audit events.

View Source
const (
	CategoryBilling      = "billing"
	CategorySubscription = "subscription"
	CategoryUsage        = "usage"
	CategoryAccess       = "access"
	CategoryPayment      = "payment"
	CategoryIntegration  = "integration"
)

Category constants for audit events.

View Source
const (
	SeverityInfo     = "info"
	SeverityWarning  = "warning"
	SeverityError    = "error"
	SeverityCritical = "critical"
)

Severity levels for audit events.

View Source
const (
	OutcomeSuccess = "success"
	OutcomeFailure = "failure"
	OutcomePartial = "partial"
)

Outcome values for audit events.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditEvent

type AuditEvent struct {
	Action     string         `json:"action"`
	Resource   string         `json:"resource"`
	Category   string         `json:"category"`
	ResourceID string         `json:"resource_id,omitempty"`
	Metadata   map[string]any `json:"metadata,omitempty"`
	Outcome    string         `json:"outcome"`
	Severity   string         `json:"severity"`
	Reason     string         `json:"reason,omitempty"`
}

AuditEvent is a local representation of an audit event. It mirrors chronicle/audit.Event but avoids a module dependency.

type Extension

type Extension struct {
	// contains filtered or unexported fields
}

Extension bridges Ledger lifecycle events to an audit trail backend.

func New

func New(r Recorder, opts ...Option) *Extension

New creates an Extension that emits audit events through the provided Recorder.

func (*Extension) Name

func (e *Extension) Name() string

Name implements plugin.Plugin.

func (*Extension) OnEntitlementChecked

func (e *Extension) OnEntitlementChecked(_ context.Context, _ interface{}) error

OnEntitlementChecked implements plugin.OnEntitlementChecked.

func (*Extension) OnInvoiceFailed

func (e *Extension) OnInvoiceFailed(ctx context.Context, inv interface{}, err error) error

OnInvoiceFailed implements plugin.OnInvoiceFailed.

func (*Extension) OnInvoiceFinalized

func (e *Extension) OnInvoiceFinalized(ctx context.Context, inv interface{}) error

OnInvoiceFinalized implements plugin.OnInvoiceFinalized.

func (*Extension) OnInvoiceGenerated

func (e *Extension) OnInvoiceGenerated(ctx context.Context, inv interface{}) error

OnInvoiceGenerated implements plugin.OnInvoiceGenerated.

func (*Extension) OnInvoicePaid

func (e *Extension) OnInvoicePaid(ctx context.Context, inv interface{}) error

OnInvoicePaid implements plugin.OnInvoicePaid.

func (*Extension) OnInvoicePastDue

func (e *Extension) OnInvoicePastDue(ctx context.Context, inv interface{}) error

OnInvoicePastDue implements plugin.OnInvoicePastDue.

func (*Extension) OnInvoiceVoided

func (e *Extension) OnInvoiceVoided(ctx context.Context, inv interface{}, reason string) error

OnInvoiceVoided implements plugin.OnInvoiceVoided.

func (*Extension) OnPlanArchived

func (e *Extension) OnPlanArchived(ctx context.Context, planID string) error

OnPlanArchived implements plugin.OnPlanArchived.

func (*Extension) OnPlanCreated

func (e *Extension) OnPlanCreated(ctx context.Context, _ interface{}) error

OnPlanCreated implements plugin.OnPlanCreated.

func (*Extension) OnPlanUpdated

func (e *Extension) OnPlanUpdated(ctx context.Context, _, _ interface{}) error

OnPlanUpdated implements plugin.OnPlanUpdated.

func (*Extension) OnQuotaExceeded

func (e *Extension) OnQuotaExceeded(ctx context.Context, tenantID, featureKey string, used, limit int64) error

OnQuotaExceeded implements plugin.OnQuotaExceeded.

func (*Extension) OnSubscriptionCancelScheduled

func (e *Extension) OnSubscriptionCancelScheduled(ctx context.Context, sub interface{}) error

OnSubscriptionCancelScheduled implements plugin.OnSubscriptionCancelScheduled. The operator's action is recorded when it is taken; subscription.canceled follows when the cancellation takes effect.

func (*Extension) OnSubscriptionCanceled

func (e *Extension) OnSubscriptionCanceled(ctx context.Context, sub interface{}) error

OnSubscriptionCanceled implements plugin.OnSubscriptionCanceled.

func (*Extension) OnSubscriptionChanged

func (e *Extension) OnSubscriptionChanged(ctx context.Context, sub, _, _ interface{}) error

OnSubscriptionChanged implements plugin.OnSubscriptionChanged.

func (*Extension) OnSubscriptionCreated

func (e *Extension) OnSubscriptionCreated(ctx context.Context, sub interface{}) error

OnSubscriptionCreated implements plugin.OnSubscriptionCreated.

func (*Extension) OnSubscriptionRenewed

func (e *Extension) OnSubscriptionRenewed(ctx context.Context, renewal interface{}) error

OnSubscriptionRenewed implements plugin.OnSubscriptionRenewed. The lifecycle clock fires it, so the context carries no operator; the tenant and app come from the subscription.

func (*Extension) OnSubscriptionTrialEnded

func (e *Extension) OnSubscriptionTrialEnded(ctx context.Context, sub interface{}) error

OnSubscriptionTrialEnded implements plugin.OnSubscriptionTrialEnded.

type Option

type Option func(*Extension)

Option configures an Extension.

func WithDisabledActions

func WithDisabledActions(actions ...string) Option

WithDisabledActions sets which actions to skip.

func WithEnabledActions

func WithEnabledActions(actions ...string) Option

WithEnabledActions sets which actions to audit. If not called, all actions are audited.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets the logger for the extension.

type Recorder

type Recorder interface {
	Record(ctx context.Context, event *AuditEvent) error
}

Recorder is the interface that audit backends must implement. This matches chronicle.Emitter but is defined locally so that the audit_hook package does not import Chronicle directly — callers inject the concrete *chronicle.Chronicle at wiring time.

type RecorderFunc

type RecorderFunc func(ctx context.Context, event *AuditEvent) error

RecorderFunc is an adapter to use a plain function as a Recorder.

func (RecorderFunc) Record

func (f RecorderFunc) Record(ctx context.Context, event *AuditEvent) error

Record implements Recorder.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL