Auth: Update cluster/instance/bootstrap.go and registry/client.go #98

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-09-19 05:21:17 +02:00
parent 75af48c0c0
commit 2fe48605a2
2 changed files with 30 additions and 1 deletions

View File

@@ -119,8 +119,13 @@ func registerWithPortal(c *config.Config, portal *url.URL, token string) error {
"nodeRole": cluster.RoleInstance, // JSON wire format is string
"advertiseUrl": c.AdvertiseUrl(),
}
// Include siteUrl when it differs from advertiseUrl; server will validate/normalize.
if su := c.SiteUrl(); su != "" && su != c.AdvertiseUrl() {
payload["siteUrl"] = su
}
if wantRotateDatabase {
payload["rotate"] = true
// Align with API: request database rotation/creation on (re)register.
payload["rotateDatabase"] = true
}
bodyBytes, _ := json.Marshal(payload)

View File

@@ -118,6 +118,30 @@ func (r *ClientRegistry) Put(n *Node) error {
return err
}
}
// Reflect persisted values back into the provided node pointer so callers
// (e.g., API handlers) can return the actual ID and timestamps.
// Note: Do not overwrite sensitive in-memory fields like Secret.
n.ID = m.ClientUID
n.Name = m.ClientName
n.Role = m.ClientRole
n.AdvertiseUrl = m.ClientURL
n.CreatedAt = m.CreatedAt.UTC().Format(time.RFC3339)
n.UpdatedAt = m.UpdatedAt.UTC().Format(time.RFC3339)
if data := m.GetData(); data != nil {
// Labels and Site URL as persisted.
if data.Labels != nil {
n.Labels = data.Labels
}
n.SiteUrl = data.SiteURL
if db := data.Database; db != nil {
n.DB.Name = db.Name
n.DB.User = db.User
n.DB.RotAt = db.RotatedAt
}
n.SecretRot = data.SecretRotatedAt
}
// Set initial secret if provided on create/update.
if n.Secret != "" {
if err := m.SetSecret(n.Secret); err != nil {