This commit is contained in:
1 parent
6e70b7e8c1
commit
c097383d3a
3 files changed
+43
-5
No files matched your search
@@ -39,6 +39,11 @@ type Info struct {
|
||||
// discover files across every configured storage backend / fail over between replicas wire
|
||||
// this through carriernodeclient.NewMulti(secret, store.CarrierNodeURLs) instead.
|
||||
CarrierNodeURLs []string `json:"carrierNodeUrls"`
|
||||
|
||||
// CarrierNodeSecret is the credential CarrierNode expects in X-Internal-Auth.
|
||||
// ProjectConfigurator includes it so consumers with independent databases can
|
||||
// authenticate storage requests without falling back to their own SECRET.
|
||||
CarrierNodeSecret string `json:"carrierNodeSecret,omitempty"`
|
||||
}
|
||||
|
||||
// Store holds the most recently pushed Info, defaulting to whatever fallback NewStore was given
|
||||
@@ -84,6 +89,9 @@ func (s *Store) CarrierNodeURL() string { return s.Get().CarrierNodeURL }
|
||||
// store.CarrierNodeURLs() }).
|
||||
func (s *Store) CarrierNodeURLs() []string { return s.Get().CarrierNodeURLs }
|
||||
|
||||
// CarrierNodeSecret is a convenience accessor for Get().CarrierNodeSecret.
|
||||
func (s *Store) CarrierNodeSecret() string { return s.Get().CarrierNodeSecret }
|
||||
|
||||
// OnUpdate registers fn to be called (synchronously, so keep it fast) with the new Info after
|
||||
// every Set - e.g. client.SetBaseURL for an authclient.Client that isn't already reading through
|
||||
// Store on every call. Only one callback is kept; a second registration replaces the first, which
|
||||
@@ -108,6 +116,9 @@ func (s *Store) Set(next Info) {
|
||||
if url := strings.TrimRight(strings.TrimSpace(next.ProjectConfiguratorURL), "/"); url != "" {
|
||||
s.info.ProjectConfiguratorURL = url
|
||||
}
|
||||
if secret := strings.TrimSpace(next.CarrierNodeSecret); secret != "" {
|
||||
s.info.CarrierNodeSecret = secret
|
||||
}
|
||||
if len(next.CarrierNodeURLs) > 0 {
|
||||
s.info.CarrierNodeURLs = next.CarrierNodeURLs
|
||||
s.info.CarrierNodeURL = next.CarrierNodeURLs[0]
|
||||
@@ -162,7 +173,11 @@ func Handler(secret string, store *Store) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
store.Set(input)
|
||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "info": store.Get()})
|
||||
// Do not echo the CarrierNode credential to the caller. The push is
|
||||
// authenticated, but the credential is needed only by the recipient.
|
||||
info := store.Get()
|
||||
info.CarrierNodeSecret = ""
|
||||
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "info": info})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,19 @@ func TestStoreSetComfyUIURL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreSetCarrierNodeSecret(t *testing.T) {
|
||||
store := NewStore(Info{})
|
||||
store.Set(Info{CarrierNodeSecret: " carrier-secret "})
|
||||
|
||||
if got := store.CarrierNodeSecret(); got != "carrier-secret" {
|
||||
t.Fatalf("CarrierNodeSecret = %q, want trimmed pushed secret", got)
|
||||
}
|
||||
store.Set(Info{})
|
||||
if got := store.CarrierNodeSecret(); got != "carrier-secret" {
|
||||
t.Fatalf("blank push cleared CarrierNodeSecret to %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreOnUpdateFiresWithNewInfo(t *testing.T) {
|
||||
store := NewStore(Info{})
|
||||
var got Info
|
||||
@@ -114,7 +127,7 @@ 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"})
|
||||
body, _ := json.Marshal(Info{AuthGuardURL: "http://auth.example.com", CarrierNodeURL: "http://carrier.example.com", CarrierNodeSecret: "carrier-secret"})
|
||||
|
||||
req := httptest.NewRequest(http.MethodPut, "/api/core-services/internal", bytes.NewReader(body))
|
||||
req.Header.Set("X-Internal-Auth", "s3cret")
|
||||
@@ -125,7 +138,7 @@ 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" {
|
||||
if got.AuthGuardURL != "http://auth.example.com" || got.CarrierNodeURL != "http://carrier.example.com" || got.CarrierNodeSecret != "carrier-secret" {
|
||||
t.Fatalf("store = %+v, want pushed values applied", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user