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.