93 lines
3.3 KiB
Go
93 lines
3.3 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 the replication configuration.
|
|
// In commercial edition, loaded from /etc/clavitor/replication.yaml
|
|
// In community edition, not used (replication not available).
|
|
type ReplicationConfig struct {
|
|
POPID string `yaml:"pop_id"`
|
|
Region string `yaml:"region"`
|
|
Role string `yaml:"role"` // "primary" or "backup"
|
|
|
|
BackupPOP struct {
|
|
ID string `yaml:"id"`
|
|
URL string `yaml:"url"`
|
|
AuthTokenFile string `yaml:"auth_token_file"`
|
|
} `yaml:"backup_pop"`
|
|
|
|
Auth struct {
|
|
TokenFile string `yaml:"token_file"`
|
|
MTLSCert string `yaml:"mtls_cert"`
|
|
MTLSKey string `yaml:"mtls_key"`
|
|
} `yaml:"auth"`
|
|
|
|
Replication struct {
|
|
BatchSize int `yaml:"batch_size"`
|
|
MaxRetries int `yaml:"max_retries"`
|
|
} `yaml:"replication"`
|
|
}
|
|
|
|
// 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 }
|