56 lines
2.1 KiB
Go
56 lines
2.1 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/v2/bson"
|
|
)
|
|
|
|
type AlertSettings struct {
|
|
Enabled bool `bson:"enabled" json:"enabled"`
|
|
WebhookURL string `bson:"webhook_url" json:"webhook_url"`
|
|
OfflineThresholdMinutes int `bson:"offline_threshold_minutes" json:"offline_threshold_minutes"`
|
|
}
|
|
|
|
type EmailSettings struct {
|
|
Enabled bool `bson:"enabled" json:"enabled"`
|
|
SMTPHost string `bson:"smtp_host" json:"smtp_host"`
|
|
SMTPPort int `bson:"smtp_port" json:"smtp_port"`
|
|
Username string `bson:"username" json:"username"`
|
|
Password string `bson:"password" json:"password"`
|
|
FromAddr string `bson:"from_addr" json:"from_addr"`
|
|
ToAddrs []string `bson:"to_addrs" json:"to_addrs"`
|
|
UseTLS bool `bson:"use_tls" json:"use_tls"`
|
|
}
|
|
|
|
type SecretsSettings struct {
|
|
ReadTokenHash string `bson:"read_token_hash,omitempty" json:"-"`
|
|
ReadTokenSet bool `bson:"-" json:"read_token_set"`
|
|
RotatedAt time.Time `bson:"rotated_at,omitempty" json:"rotated_at,omitempty"`
|
|
}
|
|
|
|
type Settings struct {
|
|
ID bson.ObjectID `bson:"_id,omitempty" json:"-"`
|
|
InstanceID string `bson:"instance_id" json:"instance_id"`
|
|
Alerts AlertSettings `bson:"alerts" json:"alerts"`
|
|
Email EmailSettings `bson:"email" json:"email"`
|
|
Secrets SecretsSettings `bson:"secrets" json:"secrets"`
|
|
|
|
WorkflowLogRetentionDays *int `bson:"workflow_log_retention_days,omitempty" json:"workflow_log_retention_days,omitempty"`
|
|
|
|
// LocalLoginEnabled is a pointer because it is absent on every settings
|
|
// document written before this feature existed, and a plain bool would read
|
|
// absent as disabled — turning off password login for the entire fleet at
|
|
// upgrade. Nil means enabled.
|
|
LocalLoginEnabled *bool `bson:"local_login_enabled,omitempty" json:"local_login_enabled,omitempty"`
|
|
}
|
|
|
|
// LocalLoginEnabled reads the setting with its absent-means-on default. Every
|
|
// caller must go through this rather than dereferencing the field.
|
|
func LocalLoginEnabled(s *Settings) bool {
|
|
if s == nil || s.LocalLoginEnabled == nil {
|
|
return true
|
|
}
|
|
return *s.LocalLoginEnabled
|
|
}
|