carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package console
2
3import (
4 "log"
5
6 "github.com/carlosframework/platform/internal/appconfig"
7)
8
9// appRegionsOn is spec §5.6: the switch AND a named home.
10func (s *Server) appRegionsOn() bool {
11 return s.cfg.AppRegions && s.cfg.HomeRegion != ""
12}
13
14// expectedSecretsFP is the fingerprint a box must publish to receive
15// placed instances (spec R9): the console's own CARLOS_SECRETS_PUBKEY,
16// the key the CLI seals config to. "" means the console cannot judge, and
17// then no coded region is eligible for automatic placement.
18func (s *Server) expectedSecretsFP() string {
19 if s.cfg.SecretsPub == "" {
20 return ""
21 }
22 fp, err := appconfig.PublicFingerprint(s.cfg.SecretsPub)
23 if err != nil {
24 return ""
25 }
26 return fp
27}
28
29// appRegion reads the app's stored region through the test seam when one
30// is set.
31func (s *Server) appRegion(accountID int64, app string) (string, string, error) {
32 if s.appRegionOf != nil {
33 return s.appRegionOf(accountID, app)
34 }
35 return s.store.AppRegion(accountID, app)
36}
37
38// logRegionConfig names, once at startup, each configuration that leaves
39// part of the feature off. The secrets-key line does not depend on the
40// switch: the guess endpoint answers with the switch off too (R9).
41func logRegionConfig(cfg Config) {
42 if cfg.AppRegions && cfg.HomeRegion == "" {
43 log.Print("console: CONSOLE_APP_REGIONS=on but CONSOLE_HOME_REGION is unset, so app regions stay off until the home is named")
44 }
45 if cfg.SecretsPub == "" {
46 log.Print("console: CARLOS_SECRETS_PUBKEY is unset, so no region outside the home can be chosen automatically")
47 }
48}
49