Documentation
¶
Index ¶
- func Decrypt(encoded, keyHex string, aad ...string) (string, error)
- func DecryptFromStorage(stored, keyHex string) (string, error)
- func Encrypt(plaintext, keyHex string, aad ...string) (string, error)
- func EncryptForStorage(plaintext, keyHex string) (string, error)
- func GenerateEncryptionKey() (string, error)
- func GenerateVAPIDKeys() (publicKey, privateKey string, err error)
- func IsEncryptedValue(value string) bool
- type AuthErrorAlert
- type NotificationChannels
- type NotificationConfig
- type NotificationEngine
- func (e *NotificationEngine) Check(status QuotaStatus)
- func (e *NotificationEngine) Config() NotificationConfig
- func (e *NotificationEngine) ConfigurePush() error
- func (e *NotificationEngine) ConfigureSMTP() error
- func (e *NotificationEngine) GetVAPIDPublicKey() string
- func (e *NotificationEngine) Reload() error
- func (e *NotificationEngine) SendAuthErrorNotification(alert AuthErrorAlert) bool
- func (e *NotificationEngine) SendTestEmail() error
- func (e *NotificationEngine) SendTestPush() error
- func (e *NotificationEngine) SetEncryptionKey(key string)
- func (e *NotificationEngine) SetLegacyEncryptionKey(key string)
- func (e *NotificationEngine) TestSMTPDiag() (string, error)
- type NotificationTypes
- type PushSender
- type PushSubscription
- type QuotaStatus
- type SMTPConfig
- type SMTPMailer
- type TestConnectionResult
- type ThresholdOverride
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
Decrypt decrypts a base64(nonce + ciphertext) string using AES-256-GCM. Optional aad must match the value used during encryption.
func DecryptFromStorage ¶
DecryptFromStorage checks for the encrypted prefix and decrypts if present. If no prefix is found, returns the value as-is (plaintext).
func Encrypt ¶
Encrypt encrypts plaintext using AES-256-GCM with the given hex key. Returns base64(nonce + ciphertext). Optional aad (Additional Authenticated Data) binds the ciphertext to a specific context.
func EncryptForStorage ¶
EncryptForStorage encrypts plaintext and returns it with the encrypted prefix. Format: "enc:" + base64(nonce + ciphertext)
func GenerateEncryptionKey ¶
GenerateEncryptionKey returns a random 32-byte key as a hex string (64 chars).
func GenerateVAPIDKeys ¶
GenerateVAPIDKeys creates a new ECDSA P-256 key pair and returns the public and private keys as base64url-encoded strings.
func IsEncryptedValue ¶
IsEncryptedValue checks if a string has the encrypted prefix.
Types ¶
type AuthErrorAlert ¶ added in v2.11.20
type AuthErrorAlert struct {
Provider string
Title string
Message string
AccountID string // For multi-account providers
IsRecovable bool // If false, requires manual re-authentication
}
AuthErrorAlert represents an authentication error for notification purposes.
type NotificationChannels ¶
NotificationChannels controls which delivery channels are active.
type NotificationConfig ¶
type NotificationConfig struct {
Warning float64 // global warning threshold (default 80)
Critical float64 // global critical threshold (default 95)
Overrides map[string]ThresholdOverride // per provider+quota overrides (legacy key: quota only)
Cooldown time.Duration // minimum time between notifications
Types NotificationTypes // which notification types are enabled
Channels NotificationChannels // which delivery channels are enabled
}
NotificationConfig holds threshold and delivery settings.
type NotificationEngine ¶
type NotificationEngine struct {
// contains filtered or unexported fields
}
NotificationEngine evaluates quota statuses and sends alerts via email and push.
func New ¶
func New(s *store.Store, logger *slog.Logger) *NotificationEngine
New creates a new NotificationEngine with default configuration.
func (*NotificationEngine) Check ¶
func (e *NotificationEngine) Check(status QuotaStatus)
Check evaluates a quota status against thresholds and sends notifications if needed. Runs synchronously -- no goroutines spawned.
func (*NotificationEngine) Config ¶
func (e *NotificationEngine) Config() NotificationConfig
Config returns a copy of the current notification config.
func (*NotificationEngine) ConfigurePush ¶
func (e *NotificationEngine) ConfigurePush() error
ConfigurePush initializes the push notification sender. Loads or generates VAPID keys, stored in the settings table as "vapid_keys".
func (*NotificationEngine) ConfigureSMTP ¶
func (e *NotificationEngine) ConfigureSMTP() error
ConfigureSMTP initializes or updates the SMTP mailer from DB settings. The handler stores SMTP config as a single JSON blob under key "smtp".
func (*NotificationEngine) GetVAPIDPublicKey ¶
func (e *NotificationEngine) GetVAPIDPublicKey() string
GetVAPIDPublicKey returns the VAPID public key for client-side push subscription.
func (*NotificationEngine) Reload ¶
func (e *NotificationEngine) Reload() error
Reload reads notification configuration from the settings table. The handler stores notifications as a single JSON blob under key "notifications".
func (*NotificationEngine) SendAuthErrorNotification ¶ added in v2.11.20
func (e *NotificationEngine) SendAuthErrorNotification(alert AuthErrorAlert) bool
SendAuthErrorNotification sends an auth error alert via email and/or push. Also creates an in-dashboard system alert for when the user logs in. Returns true if at least one notification was sent successfully.
func (*NotificationEngine) SendTestEmail ¶
func (e *NotificationEngine) SendTestEmail() error
SendTestEmail sends a test email to verify SMTP configuration.
func (*NotificationEngine) SendTestPush ¶
func (e *NotificationEngine) SendTestPush() error
SendTestPush sends a test push notification to all subscribed devices.
func (*NotificationEngine) SetEncryptionKey ¶
func (e *NotificationEngine) SetEncryptionKey(key string)
SetEncryptionKey sets the encryption key for decrypting sensitive data like SMTP passwords. The key should be a hex-encoded 32-byte string suitable for AES-256-GCM.
func (*NotificationEngine) SetLegacyEncryptionKey ¶ added in v2.11.18
func (e *NotificationEngine) SetLegacyEncryptionKey(key string)
SetLegacyEncryptionKey sets an optional fallback key used only for one-time migration of legacy encrypted SMTP passwords.
func (*NotificationEngine) TestSMTPDiag ¶ added in v2.11.30
func (e *NotificationEngine) TestSMTPDiag() (string, error)
TestSMTPDiag sends a test email and returns diagnostics from the connection. Uses a single SMTP connection for both diagnostics and delivery.
type NotificationTypes ¶
type NotificationTypes struct {
Warning bool `json:"warning"`
Critical bool `json:"critical"`
Reset bool `json:"reset"`
AuthError bool `json:"auth_error"` // Auth failure notifications
}
NotificationTypes controls which notification types are enabled.
type PushSender ¶
type PushSender struct {
// contains filtered or unexported fields
}
PushSender sends Web Push notifications using VAPID authentication.
func NewPushSender ¶
func NewPushSender(publicKeyB64, privateKeyB64, subject string) (*PushSender, error)
NewPushSender creates a PushSender from base64url-encoded VAPID keys.
func (*PushSender) Send ¶
func (p *PushSender) Send(sub PushSubscription, title, body string) error
Send encrypts and sends a push notification to a subscription endpoint.
type PushSubscription ¶
type PushSubscription struct {
Endpoint string `json:"endpoint"`
Keys struct {
P256dh string `json:"p256dh"`
Auth string `json:"auth"`
} `json:"keys"`
}
PushSubscription represents a browser push subscription.
type QuotaStatus ¶
type QuotaStatus struct {
Provider string
QuotaKey string
AccountID string // For multi-account providers (e.g., Codex)
Utilization float64
Limit float64
ResetOccurred bool
}
QuotaStatus represents the current state of a quota for notification evaluation.
type SMTPConfig ¶
type SMTPConfig struct {
Host string // SMTP server hostname
Port int // SMTP server port (25, 465, 587)
Username string // SMTP auth username
Password string // SMTP auth password (plaintext or decrypted)
Protocol string // "auto", "tls" (implicit TLS), "starttls" (explicit upgrade), "none" (plaintext)
FromAddr string // Sender email address
FromName string // Sender display name
ToAddrs []string // Recipient email addresses
}
SMTPConfig holds SMTP connection settings.
type SMTPMailer ¶
type SMTPMailer struct {
// contains filtered or unexported fields
}
SMTPMailer sends email notifications via SMTP.
func NewSMTPMailer ¶
func NewSMTPMailer(cfg SMTPConfig, logger *slog.Logger) *SMTPMailer
NewSMTPMailer creates a new SMTP mailer with the given config.
func (*SMTPMailer) Send ¶
func (m *SMTPMailer) Send(subject, body string) error
Send sends an email with the given subject and plaintext body.
func (*SMTPMailer) SendWithDiag ¶ added in v2.11.30
func (m *SMTPMailer) SendWithDiag(subject, body string) TestConnectionResult
SendWithDiag sends an email and returns diagnostics from the connection. Unlike TestConnectionDiag + Send, this uses a single SMTP connection.
func (*SMTPMailer) TestConnection ¶
func (m *SMTPMailer) TestConnection() error
TestConnection verifies SMTP connectivity and authentication.
func (*SMTPMailer) TestConnectionDiag ¶ added in v2.11.30
func (m *SMTPMailer) TestConnectionDiag() TestConnectionResult
TestConnectionDiag performs a full SMTP handshake and returns diagnostics.
type TestConnectionResult ¶ added in v2.11.30
TestConnectionResult holds diagnostic details from an SMTP connection test.
type ThresholdOverride ¶
type ThresholdOverride struct {
Warning float64 `json:"warning"`
Critical float64 `json:"critical"`
IsAbsolute bool `json:"is_absolute"`
DisableReset bool `json:"disable_reset"`
DisableWarning bool `json:"disable_warning"`
DisableCrit bool `json:"disable_critical"`
}
ThresholdOverride allows per-quota threshold customization.