diff --git a/backend/coreconfig/coreconfig.go b/backend/coreconfig/coreconfig.go index f3251e4..5e0e5f7 100644 --- a/backend/coreconfig/coreconfig.go +++ b/backend/coreconfig/coreconfig.go @@ -28,6 +28,10 @@ type Info struct { // configuration. Consumers with independent databases can use it to read settings such as the // configured mount mappings. 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 // 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. 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 // as a single-instance carriernodeclient.Client's BaseURL: carriernodeclient.New(secret, func(ctx // 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 != "" { 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 != "" { s.info.CarrierNodeSecret = secret } @@ -173,10 +189,11 @@ func Handler(secret string, store *Store) http.HandlerFunc { return } store.Set(input) - // Do not echo the CarrierNode credential to the caller. The push is - // authenticated, but the credential is needed only by the recipient. + // Do not echo service credentials to the caller. The push is authenticated, but + // these credentials are needed only by the recipient. info := store.Get() info.CarrierNodeSecret = "" + info.ContentScannerSecret = "" writeJSON(w, http.StatusOK, map[string]any{"ok": true, "info": info}) } } diff --git a/backend/coreconfig/coreconfig_test.go b/backend/coreconfig/coreconfig_test.go index e5115de..e4c7eb6 100644 --- a/backend/coreconfig/coreconfig_test.go +++ b/backend/coreconfig/coreconfig_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "net/http" "net/http/httptest" + "strings" "testing" ) @@ -127,7 +128,10 @@ func equalStrings(got, want []string) bool { func TestHandlerAppliesPushedInfo(t *testing.T) { store := NewStore(Info{}) 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.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()) } 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) } + if strings.Contains(rec.Body.String(), "scanner-secret") { + t.Fatal("response echoed the ContentScanner secret") + } }