From d52507566f8a642b670901d95273d237477dcd88 Mon Sep 17 00:00:00 2001 From: Evan Jarrett Date: Tue, 9 Dec 2025 14:01:03 -0600 Subject: [PATCH] spindle/config: add abilility to override motd Signed-off-by: Evan Jarrett --- spindle/server.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/spindle/server.go b/spindle/server.go index 6ce9464d..0aae6b70 100644 --- a/spindle/server.go +++ b/spindle/server.go @@ -8,6 +8,7 @@ import ( "log/slog" "maps" "net/http" + "sync" "github.com/go-chi/chi/v5" "tangled.org/core/api/tangled" @@ -30,7 +31,7 @@ import ( ) //go:embed motd -var motd []byte +var defaultMotd []byte const ( rbacDomain = "thisserver" @@ -47,7 +48,9 @@ type Spindle struct { cfg *config.Config ks *eventconsumer.Consumer res *idresolver.Resolver - vault secrets.Manager + vault secrets.Manager + motd []byte + motdMu sync.RWMutex } // New creates a new Spindle server with the provided configuration and engines. @@ -128,6 +131,7 @@ func New(ctx context.Context, cfg *config.Config, engines map[string]models.Engi cfg: cfg, res: resolver, vault: vault, + motd: defaultMotd, } err = e.AddSpindle(rbacDomain) @@ -201,6 +205,20 @@ func (s *Spindle) Enforcer() *rbac.Enforcer { return s.e } +// SetMotdContent sets custom MOTD content, replacing the embedded default. +func (s *Spindle) SetMotdContent(content []byte) { + s.motdMu.Lock() + defer s.motdMu.Unlock() + s.motd = content +} + +// GetMotdContent returns the current MOTD content. +func (s *Spindle) GetMotdContent() []byte { + s.motdMu.RLock() + defer s.motdMu.RUnlock() + return s.motd +} + // Start starts the Spindle server (blocking). func (s *Spindle) Start(ctx context.Context) error { // starts a job queue runner in the background @@ -246,7 +264,7 @@ func (s *Spindle) Router() http.Handler { mux := chi.NewRouter() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - w.Write(motd) + w.Write(s.GetMotdContent()) }) mux.HandleFunc("/events", s.Events) mux.HandleFunc("/logs/{knot}/{rkey}/{name}", s.Logs) -- 2.43.0