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
- type AuditEvent
- type Extension
- func (e *Extension) Name() string
- func (e *Extension) OnEntitlementChecked(_ context.Context, _ interface{}) error
- func (e *Extension) OnInvoiceFailed(ctx context.Context, inv interface{}, err error) error
- func (e *Extension) OnInvoiceFinalized(ctx context.Context, inv interface{}) error
- func (e *Extension) OnInvoiceGenerated(ctx context.Context, inv interface{}) error
- func (e *Extension) OnInvoicePaid(ctx context.Context, inv interface{}) error
- func (e *Extension) OnInvoicePastDue(ctx context.Context, inv interface{}) error
- func (e *Extension) OnInvoiceVoided(ctx context.Context, inv interface{}, reason string) error
- func (e *Extension) OnPlanArchived(ctx context.Context, planID string) error
- func (e *Extension) OnPlanCreated(ctx context.Context, _ interface{}) error
- func (e *Extension) OnPlanUpdated(ctx context.Context, _, _ interface{}) error
- func (e *Extension) OnQuotaExceeded(ctx context.Context, tenantID, featureKey string, used, limit int64) error
- func (e *Extension) OnSubscriptionCancelScheduled(ctx context.Context, sub interface{}) error
- func (e *Extension) OnSubscriptionCanceled(ctx context.Context, sub interface{}) error
- func (e *Extension) OnSubscriptionChanged(ctx context.Context, sub, _, _ interface{}) error
- func (e *Extension) OnSubscriptionCreated(ctx context.Context, sub interface{}) error
- func (e *Extension) OnSubscriptionRenewed(ctx context.Context, renewal interface{}) error
- func (e *Extension) OnSubscriptionTrialEnded(ctx context.Context, sub interface{}) error
- type Option
- type Recorder
- type RecorderFunc
Constants ¶
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.
const ( ResourcePlan = "plan" ResourceSubscription = "subscription" ResourceUsage = "usage" ResourceEntitlement = "entitlement" ResourceInvoice = "invoice" ResourceProvider = "provider" ResourceWebhook = "webhook" )
Resource constants for audit events.
const ( CategoryBilling = "billing" CategorySubscription = "subscription" CategoryUsage = "usage" CategoryAccess = "access" CategoryPayment = "payment" CategoryIntegration = "integration" )
Category constants for audit events.
const ( SeverityInfo = "info" SeverityWarning = "warning" SeverityError = "error" SeverityCritical = "critical" )
Severity levels for audit events.
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 (*Extension) OnEntitlementChecked ¶
OnEntitlementChecked implements plugin.OnEntitlementChecked.
func (*Extension) OnInvoiceFailed ¶
OnInvoiceFailed implements plugin.OnInvoiceFailed.
func (*Extension) OnInvoiceFinalized ¶
OnInvoiceFinalized implements plugin.OnInvoiceFinalized.
func (*Extension) OnInvoiceGenerated ¶
OnInvoiceGenerated implements plugin.OnInvoiceGenerated.
func (*Extension) OnInvoicePaid ¶
OnInvoicePaid implements plugin.OnInvoicePaid.
func (*Extension) OnInvoicePastDue ¶
OnInvoicePastDue implements plugin.OnInvoicePastDue.
func (*Extension) OnInvoiceVoided ¶
OnInvoiceVoided implements plugin.OnInvoiceVoided.
func (*Extension) OnPlanArchived ¶
OnPlanArchived implements plugin.OnPlanArchived.
func (*Extension) OnPlanCreated ¶
OnPlanCreated implements plugin.OnPlanCreated.
func (*Extension) OnPlanUpdated ¶
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 ¶
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 ¶
OnSubscriptionCanceled implements plugin.OnSubscriptionCanceled.
func (*Extension) OnSubscriptionChanged ¶
OnSubscriptionChanged implements plugin.OnSubscriptionChanged.
func (*Extension) OnSubscriptionCreated ¶
OnSubscriptionCreated implements plugin.OnSubscriptionCreated.
func (*Extension) OnSubscriptionRenewed ¶
OnSubscriptionRenewed implements plugin.OnSubscriptionRenewed. The lifecycle clock fires it, so the context carries no operator; the tenant and app come from the subscription.
type Option ¶
type Option func(*Extension)
Option configures an Extension.
func WithDisabledActions ¶
WithDisabledActions sets which actions to skip.
func WithEnabledActions ¶
WithEnabledActions sets which actions to audit. If not called, all actions are audited.
func WithLogger ¶
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.