oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "errors"
5 "log/slog"
6
7 "amadan.net/oficina/equipo/internal/equipo/push"
8 "amadan.net/rastrillo/rastrillo/mail"
9)
10
11// Mailer builds the sign-in sender. Call it only where Equipo serves (main's
12// run): a CARLOS seed or one-shot runs with no control socket, and the agent
13// strips CARLOS_MAIL from it, so mail.FromCarlos there would refuse once the
14// app is switched to submission. The runner and tool proxy binaries never
15// send mail.
16//
17// EQUIPO_ALLOW_LOGGED_MAIL keeps its rule: when LoadConfig admitted it
18// (loopback or a staging origin), every message is logged, whatever channel
19// is configured. Otherwise mail.FromCarlos picks submission when
20// CARLOS_MAIL=submit, else CARLOS_SMTP_*, and refuses with neither, or with
21// submission half set up (no socket, token or CARLOS_MAIL_FROM). It reads
22// the process environment, as mail.FromCarlos does, so cfg must come from
23// LoadConfig(os.Getenv).
24func Mailer(cfg Config, logger *slog.Logger) (mail.Sender, error) {
25 if cfg.AllowLoggedMail {
26 return mail.Logged(logger), nil
27 }
28 if !cfg.MailConfigured {
29 // LoadConfig refuses this; a hand-built Config gets a sender
30 // RouterWithStore refuses in turn (copyUnconfiguredMailer).
31 return mail.FromEnv("CARLOS", logger), nil
32 }
33 return mail.FromCarlos("CARLOS", logger)
34}
35
36// Pusher builds the push transport. Call it only where Equipo serves
37// (main's run), as Mailer: a seed or one-shot has no control socket and
38// sends nothing. EQUIPO_ALLOW_LOGGED_PUSH (admitted by LoadConfig on
39// loopback or staging only) logs every push; CARLOS_PUSH=submit is the
40// CARLOS platform's push submission (push.FromCarlos, a seam until the
41// platform verb exists); both refuse boot; neither is no push at all
42// (nil, nil).
43func Pusher(cfg Config, logger *slog.Logger, getenv func(string) string) (push.Transport, error) {
44 if cfg.AllowLoggedPush && getenv(push.CarlosPushEnv) != "" {
45 // Never one silently over the other.
46 //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go.
47 return nil, errors.New(copyPushBoth)
48 }
49 if cfg.AllowLoggedPush {
50 if cfg.validate() != nil {
51 //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go.
52 return nil, errors.New(copyLoggedPushPublic)
53 }
54 return push.Logged{Logger: logger}, nil
55 }
56 t, err := push.FromCarlos(getenv)
57 if err != nil {
58 //lint:ignore ST1005 User-facing errors preserve the reviewed sentences in copy.go.
59 return nil, errors.New(copyCarlosPushUnavailable)
60 }
61 return t, nil
62}
63