Extend core config for ContentScanner sync

This commit is contained in:
Gabriel20xx committed 2026-09-18 15:54:39 +02:00
1 parent 8bbaf3c70b
commit 389dd8649d
2 files changed
+28 -4

No files matched your search

+19 -2
View File
@@ -28,6 +28,10 @@ type Info struct {
// configuration. Consumers with independent databases can use it to read settings such as the // configuration. Consumers with independent databases can use it to read settings such as the
// configured mount mappings. // configured mount mappings.
ProjectConfiguratorURL string `json:"projectConfiguratorUrl"` ProjectConfiguratorURL string `json:"projectConfiguratorUrl"`
// ContentScannerURL and ContentScannerSecret let services with independent databases import
// the scanner's successfully discovered media without connecting to its PostgreSQL database.
ContentScannerURL string `json:"contentScannerUrl,omitempty"`
ContentScannerSecret string `json:"contentScannerSecret,omitempty"`
// CarrierNodeURL is the primary CarrierNode instance's URL (CarrierNodeURLs[0], if any) - kept // CarrierNodeURL is the primary CarrierNode instance's URL (CarrierNodeURLs[0], if any) - kept
// for the services that only ever talk to one CarrierNode instance via // for the services that only ever talk to one CarrierNode instance via
@@ -78,6 +82,12 @@ func (s *Store) ComfyUIURL() string { return s.Get().ComfyUIURL }
// ProjectConfiguratorURL is a convenience accessor for Get().ProjectConfiguratorURL. // ProjectConfiguratorURL is a convenience accessor for Get().ProjectConfiguratorURL.
func (s *Store) ProjectConfiguratorURL() string { return s.Get().ProjectConfiguratorURL } func (s *Store) ProjectConfiguratorURL() string { return s.Get().ProjectConfiguratorURL }
// ContentScannerURL is a convenience accessor for Get().ContentScannerURL.
func (s *Store) ContentScannerURL() string { return s.Get().ContentScannerURL }
// ContentScannerSecret is the credential the scanner expects on internal sync requests.
func (s *Store) ContentScannerSecret() string { return s.Get().ContentScannerSecret }
// CarrierNodeURL is a convenience accessor for Get().CarrierNodeURL - the natural closure to wire // CarrierNodeURL is a convenience accessor for Get().CarrierNodeURL - the natural closure to wire
// as a single-instance carriernodeclient.Client's BaseURL: carriernodeclient.New(secret, func(ctx // as a single-instance carriernodeclient.Client's BaseURL: carriernodeclient.New(secret, func(ctx
// context.Context) string { return store.CarrierNodeURL() }). // context.Context) string { return store.CarrierNodeURL() }).
@@ -116,6 +126,12 @@ func (s *Store) Set(next Info) {
if url := strings.TrimRight(strings.TrimSpace(next.ProjectConfiguratorURL), "/"); url != "" { if url := strings.TrimRight(strings.TrimSpace(next.ProjectConfiguratorURL), "/"); url != "" {
s.info.ProjectConfiguratorURL = url s.info.ProjectConfiguratorURL = url
} }
if url := strings.TrimRight(strings.TrimSpace(next.ContentScannerURL), "/"); url != "" {
s.info.ContentScannerURL = url
}
if secret := strings.TrimSpace(next.ContentScannerSecret); secret != "" {
s.info.ContentScannerSecret = secret
}
if secret := strings.TrimSpace(next.CarrierNodeSecret); secret != "" { if secret := strings.TrimSpace(next.CarrierNodeSecret); secret != "" {
s.info.CarrierNodeSecret = secret s.info.CarrierNodeSecret = secret
} }
@@ -173,10 +189,11 @@ func Handler(secret string, store *Store) http.HandlerFunc {
return return
} }
store.Set(input) store.Set(input)
// Do not echo the CarrierNode credential to the caller. The push is // Do not echo service credentials to the caller. The push is authenticated, but
// authenticated, but the credential is needed only by the recipient. // these credentials are needed only by the recipient.
info := store.Get() info := store.Get()
info.CarrierNodeSecret = "" info.CarrierNodeSecret = ""
info.ContentScannerSecret = ""
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "info": info}) writeJSON(w, http.StatusOK, map[string]any{"ok": true, "info": info})
} }
} }
+9 -2
View File
@@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings"
"testing" "testing"
) )
@@ -127,7 +128,10 @@ func equalStrings(got, want []string) bool {
func TestHandlerAppliesPushedInfo(t *testing.T) { func TestHandlerAppliesPushedInfo(t *testing.T) {
store := NewStore(Info{}) store := NewStore(Info{})
handler := Handler("s3cret", store) handler := Handler("s3cret", store)
body, _ := json.Marshal(Info{AuthGuardURL: "http://auth.example.com", CarrierNodeURL: "http://carrier.example.com", CarrierNodeSecret: "carrier-secret"}) body, _ := json.Marshal(Info{
AuthGuardURL: "http://auth.example.com", CarrierNodeURL: "http://carrier.example.com", CarrierNodeSecret: "carrier-secret",
ContentScannerURL: "http://scanner.example.com/", ContentScannerSecret: "scanner-secret",
})
req := httptest.NewRequest(http.MethodPut, "/api/core-services/internal", bytes.NewReader(body)) req := httptest.NewRequest(http.MethodPut, "/api/core-services/internal", bytes.NewReader(body))
req.Header.Set("X-Internal-Auth", "s3cret") req.Header.Set("X-Internal-Auth", "s3cret")
@@ -138,7 +142,10 @@ func TestHandlerAppliesPushedInfo(t *testing.T) {
t.Fatalf("status = %d, want 200: %s", rec.Code, rec.Body.String()) t.Fatalf("status = %d, want 200: %s", rec.Code, rec.Body.String())
} }
got := store.Get() got := store.Get()
if got.AuthGuardURL != "http://auth.example.com" || got.CarrierNodeURL != "http://carrier.example.com" || got.CarrierNodeSecret != "carrier-secret" { if got.AuthGuardURL != "http://auth.example.com" || got.CarrierNodeURL != "http://carrier.example.com" || got.CarrierNodeSecret != "carrier-secret" || got.ContentScannerURL != "http://scanner.example.com" || got.ContentScannerSecret != "scanner-secret" {
t.Fatalf("store = %+v, want pushed values applied", got) t.Fatalf("store = %+v, want pushed values applied", got)
} }
if strings.Contains(rec.Body.String(), "scanner-secret") {
t.Fatal("response echoed the ContentScanner secret")
}
} }