clavitor/clavis/clavis-vault/edition/edition.go

77 lines
3.0 KiB
Go

// Package edition provides build-time differentiation between Community and Commercial editions.
//
// Community Edition (default): No telemetry, no central management, self-hosted only.
// Commercial Edition (build tag: commercial): Telemetry, alerting, managed by clavitor.ai.
//
// Build instructions:
//
// Community: go build ./cmd/clavitor/
// Commercial: go build -tags commercial ./cmd/clavitor/
//
// Usage in code:
//
// edition.Current.AlertOperator(ctx, "auth_error", "message", details)
//
// To add commercial config at startup:
//
// edition.SetCommercialConfig(&edition.CommercialConfig{...})
package edition
import "context"
// Edition defines the interface for community vs commercial behavior.
type Edition interface {
// Name returns "community" or "commercial"
Name() string
// AlertOperator sends critical operational alerts.
// Community: logs to stderr with OPERATOR ALERT prefix.
// Commercial: POSTs to telemetry endpoint + logs locally.
AlertOperator(ctx context.Context, alertType, message string, details map[string]any)
// IsTelemetryEnabled returns true if this edition sends data to central servers.
IsTelemetryEnabled() bool
}
// Current is the edition implementation for this build.
// Set at init() time in community.go or commercial.go based on build tags.
var Current Edition
// CommercialConfig is defined in commercial.go (commercial build only).
// Stub here for API compatibility.
type CommercialConfig struct {
TelemetryHost string
TelemetryToken string
TelemetryFreq int
POPRegion string
ReplicationConfig *ReplicationConfig // Commercial-only: replication to backup POPs
}
// ReplicationConfig holds backup POP configuration (commercial only).
// Community Edition does not have replication functionality.
type ReplicationConfig struct {
PrimaryPOP string // e.g., "https://calgary.clavitor.ai"
BackupPOP string // e.g., "https://zurich.clavitor.ai"
AuthToken string // Bearer token for inter-POP auth
BatchSize int // Max entries per request (default 100)
PollInterval int // Seconds between polls (default 30)
}
// SetCommercialConfig is a no-op in community edition.
// Implemented in commercial.go for commercial builds.
var SetCommercialConfig func(cfg *CommercialConfig)
// StartReplication begins background replication (commercial only).
// Stub here - actual implementation in commercial.go.
var StartReplication func(ctx context.Context, dataDir string)
// SignalReplication wakes the replication worker (commercial only).
// Stub here - community edition does nothing.
var SignalReplication func()
// IsBackupMode returns false in community edition (always single-node).
// Stub here - actual implementation in backup_mode.go for commercial builds.
var IsBackupMode func() bool = func() bool { return false }
// IsBackupRequest returns false in community edition.
// Stub here - actual implementation in backup_mode.go for commercial builds.
var IsBackupRequest func(ctx context.Context) bool = func(ctx context.Context) bool { return false }