diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2025-07-03 15:22:09 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2025-07-08 13:37:33 +0000 |
| commit | 4ae963f81abf2889628b7d47dae833626fd0664a (patch) | |
| tree | cc21403feb7c6b29f10db48bbfea2bf70de3e8f9 /syz-cluster/pkg | |
| parent | a7f206f0e4b264de8fb8b059d10c96beb8c6a3a4 (diff) | |
syz-cluster: support dashapi sender
Refactor the configuration to support both SMTP and dashapi-based email
sending functionality.
Diffstat (limited to 'syz-cluster/pkg')
| -rw-r--r-- | syz-cluster/pkg/app/config.go | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/syz-cluster/pkg/app/config.go b/syz-cluster/pkg/app/config.go index 66a30bd23..92a3535e0 100644 --- a/syz-cluster/pkg/app/config.go +++ b/syz-cluster/pkg/app/config.go @@ -23,6 +23,11 @@ type AppConfig struct { EmailReporting *EmailConfig `yaml:"emailReporting"` } +const ( + SenderSMTP = "smtp" + SenderDashapi = "dashapi" +) + type EmailConfig struct { // The public name of the system. Name string `yaml:"name"` @@ -30,14 +35,37 @@ type EmailConfig struct { DocsLink string `yaml:"docs"` // Contact email. SupportEmail string `yaml:"supportEmail"` - // The email from which to send the reports. + // The means to send the emails ("smtp", "dashapi"). Sender string `yaml:"sender"` + // Will be used if Sender is "smtp". + SMTP *SMTPConfig `yaml:"smtpConfig"` + // Will be used if Sender is "dashapi". + Dashapi *DashapiConfig `yaml:"dashapiConfig"` // Moderation requests will be sent there. ModerationList string `yaml:"moderationList"` // The list we listen on. ArchiveList string `yaml:"archiveList"` // Lore git archive to poll for incoming messages. LoreArchiveURL string `yaml:"loreArchiveURL"` + // The prefix which will be added to all reports' titles. + SubjectPrefix string `yaml:"subjectPrefix"` +} + +type SMTPConfig struct { + // The email from which to send the reports. + From string `yaml:"from"` +} + +type DashapiConfig struct { + // The URI at which the dashboard is accessible. + Addr string `yaml:"addr"` + // Client name to be used for authorization. + // OAuth will be used instead of a key. + Client string `yaml:"client"` + // The email from which to send the reports. + From string `yaml:"from"` + // The emails will be sent from "name+" + contextPrefix + ID + "@domain". + ContextPrefix string `yaml:"contextPrefix"` } // The project configuration is expected to be mounted at /config/config.yaml. @@ -92,7 +120,6 @@ func (c EmailConfig) Validate() error { for _, err := range []error{ ensureNonEmpty("name", c.Name), ensureEmail("supportEmail", c.SupportEmail), - ensureEmail("sender", c.Sender), ensureEmail("moderationList", c.ModerationList), ensureEmail("archiveList", c.ArchiveList), } { @@ -100,6 +127,45 @@ func (c EmailConfig) Validate() error { return err } } + if c.SMTP != nil { + if err := c.SMTP.Validate(); err != nil { + return err + } + } + if c.Dashapi != nil { + if err := c.Dashapi.Validate(); err != nil { + return err + } + } + switch c.Sender { + case SenderSMTP: + if c.SMTP == nil { + return fmt.Errorf("sender is %q, but smtpConfig is empty", SenderSMTP) + } + case SenderDashapi: + if c.Dashapi == nil { + return fmt.Errorf("sender is %q, but dashapiConfig is empty", SenderDashapi) + } + default: + return fmt.Errorf("invalid sender value, must be %q or %q", SenderSMTP, SenderDashapi) + } + return nil +} + +func (c SMTPConfig) Validate() error { + return ensureEmail("from", c.From) +} + +func (c DashapiConfig) Validate() error { + for _, err := range []error{ + ensureNonEmpty("addr", c.Addr), + ensureNonEmpty("client", c.Client), + ensureEmail("from", c.From), + } { + if err != nil { + return err + } + } return nil } |
