| 1 | package memoria |
| 2 | |
| 3 | // A team instance never reaches anybody else's sibling apps — Paul's |
| 4 | // above all (MEMORIA_SIBLINGS / MEMORIA_TEAM in team mode). |
| 5 | // |
| 6 | // The sibling transport already refuses any host that is not |
| 7 | // `<MEMORIA_TEAM>.<app>.oficina.works` (suite.CheckSiblingHost, at boot in |
| 8 | // LoadSiblings and again before every dial). What that leaves open is |
| 9 | // MEMORIA_TEAM itself: it is an operator's string, and a team instance |
| 10 | // given another team's label would be bound, correctly and completely, to |
| 11 | // the wrong team. So in team mode the label must be this instance's own: |
| 12 | // the first label of MEMORIA_ORIGIN, which Alta sets to |
| 13 | // `https://<label>.memoria.oficina.works` beside MEMORIA_TEAM=<label>. |
| 14 | // Anything else refuses boot. Paul's own apps sit at `<app>.oficina.works`, |
| 15 | // which no label can name. |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "net/url" |
| 20 | "strings" |
| 21 | |
| 22 | "amadan.net/oficina/suite" |
| 23 | ) |
| 24 | |
| 25 | // teamSiblingsBound refuses a sibling roster whose team label is not this |
| 26 | // team instance's own. Called by WireSiblings only in team mode, and only |
| 27 | // when a sibling is configured. |
| 28 | func teamSiblingsBound(origin, team string) error { |
| 29 | u, err := url.Parse(origin) |
| 30 | if err != nil || u.Scheme != "https" { |
| 31 | return fmt.Errorf("%w: in team mode MEMORIA_SIBLINGS needs MEMORIA_ORIGIN to be this team's https://<team>.memoria.%s", errTeamConfig, suite.SuiteDomain) |
| 32 | } |
| 33 | want := team + ".memoria." + suite.SuiteDomain |
| 34 | if team == "" || !strings.EqualFold(strings.TrimSuffix(u.Hostname(), "."), want) || u.Port() != "" { |
| 35 | // Neither value in the message: both are configuration, and the |
| 36 | // operator has them; the rule is what they need. |
| 37 | return fmt.Errorf("%w: in team mode MEMORIA_TEAM must be this instance's own team label, the first label of MEMORIA_ORIGIN (https://<team>.memoria.%s), so siblings stay on this team's hosts", errTeamConfig, suite.SuiteDomain) |
| 38 | } |
| 39 | return nil |
| 40 | } |
| 41 | |