From 788969bcf8b7ebb3919e99e25a1bbd1a39667e6b Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 30 Oct 2026 18:20:28 +0100 Subject: [PATCH] Write a kept user through mesh-sdk's AccountsEntry, so its lines are ComposeAccounts' own (issue 774) The grants part repeated the composer's entry lines to keep a refused principal's grants of the list in force; mesh-sdk 61b67d6 exports them as buscompose.AccountsEntry, so the copy goes. The byte-for-byte test of the kept entry still passes. Needs the mesh-sdk pin at 61b67d6 or later. --- .../mesh-grants/internal/grants/refused.go | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/modules/mesh-grants/internal/grants/refused.go b/modules/mesh-grants/internal/grants/refused.go index 6d2e8b7..d994a58 100644 --- a/modules/mesh-grants/internal/grants/refused.go +++ b/modules/mesh-grants/internal/grants/refused.go @@ -5,7 +5,6 @@ import ( "slices" "sort" "strings" - "time" "git.novox.be/novox/mesh-sdk/go/asks" "git.novox.be/novox/mesh-sdk/go/buscompose" @@ -77,30 +76,11 @@ func withKept(users []User, kept map[string]User) []User { return out } -// keptEntry is a user of the accounts block as buscompose.ComposeAccounts writes one, from grants kept rather than -// composed: the same lines, so the bus reads it as it read the list in force. +// keptEntry is a user of the accounts block from grants kept rather than composed, in ComposeAccounts' own lines +// (buscompose.AccountsEntry), so the bus reads it as it read the list in force. func keptEntry(u User, hash string) string { - var b strings.Builder - fmt.Fprintf(&b, " { user: %q, password: %q, permissions: {\n", u.User, hash) - if len(u.PublishDeny) > 0 { - fmt.Fprintf(&b, " publish: { allow: [%s], deny: [%s] }\n", quotedList(u.Publish), quotedList(u.PublishDeny)) - } else { - fmt.Fprintf(&b, " publish: { allow: [%s] }\n", quotedList(u.Publish)) - } - fmt.Fprintf(&b, " subscribe: { allow: [%s] }\n", quotedList(u.Subscribe)) - if u.AllowResponses { - fmt.Fprintf(&b, " allow_responses: { max: 1, ttl: \"%dm\" }\n", int(buscompose.ResponseTTL/time.Minute)) - } - b.WriteString(" } }\n") - return b.String() -} - -func quotedList(in []string) string { - q := make([]string, len(in)) - for i, s := range in { - q[i] = fmt.Sprintf("%q", s) - } - return strings.Join(q, ", ") + return buscompose.AccountsEntry(u.User, hash, buscompose.Permissions{Publish: u.Publish, PublishDeny: u.PublishDeny, + Subscribe: u.Subscribe, AllowResponses: u.AllowResponses}) } // withEntries puts entries at the end of the accounts block's users, before it closes.