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.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user