Files
mesh-delivery/modules/mesh-grants/internal/grants/callers.go
T
jschoubben 6b43adafca G1 (in progress): the grants part reads no callers and no verdicts
Every account may call every verb: the grants part reads no definition's
callers (callerOf, the verb and accept callers, admits) and grants every
module's account every verb of every seat (mesh.seat.*.tool.> and its
caller-named form), a sent store to every module invoking a verb of its
claimant's seat, and every queue's named ask to every asker. grants_callers
goes; grants_why_refused answers the bus's own verdict. The indexer keeps
no verdicts: their first view, events, invoke and the engine's read go, and
a want names its build alone (no newest). internal/... and cmd/... tests are
green; the root package's grants_test.go still reads the verdicts (rows at
grants_test.go:303-307, 741, 1184, 3700-3870, 4560-4615) and does not compile.

Builds: design 47 H §745, §750, §752, §764 (every seat contract: the callers lists); lead answers H-A-37, H-A-66, H-A-79, H-A-113 (hq f599b761)

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 04:28:04 +01:00

74 lines
2.5 KiB
Go

package grants
import (
"encoding/json"
"errors"
"fmt"
"slices"
"strings"
"git.novox.be/novox/mesh-sdk/go/seatdef"
"mesh-grants/internal/buscompose"
)
// The tool that says why a call is refused at the bus (design 47 G §83): every account may call every verb, so no
// definition names callers and the bus's own verdict is the answer (design 47 H §752, H-A-113).
const ToolWhyRefused = "grants_why_refused"
// definitions are the seat definitions the part composes from, or why it has none.
func (p *Part) definitions() (map[string]seatdef.Definition, error) {
d, ok := p.SeatList.(SeatDefinitions)
if !ok {
return nil, errors.New("the seat list is not read here: the seats' verbs are unknown")
}
defs := d.Definitions()
if len(defs) == 0 {
return nil, errors.New("the seat list holds no definitions yet")
}
return defs, nil
}
// WhyRefused answers the tool grants_why_refused: whether the bus grants an account the call subject of address
// (`<seat>.<verb>`), the bus's own answer (nats.nats_user_can, the account's grants as the server holds them).
func (p *Part) WhyRefused(account, address, node string) (any, error) {
seat, verb, ok := strings.Cut(address, ".")
if account == "" || !ok || seat == "" || verb == "" {
return nil, errors.New("why_refused names an account and a verb as <seat>.<verb>")
}
defs, err := p.definitions()
if err != nil {
return nil, err
}
def, defined := defs[seat]
if !defined || !slices.ContainsFunc(def.Verbs, func(v seatdef.Verb) bool { return v.Name == verb }) {
return nil, fmt.Errorf("no seat definition names the verb %s", address)
}
s := buscompose.Seat{Name: seat, Scope: def.Scope}
subject := buscompose.CalledSubject(buscompose.SeatToolSubject(s, verb, node), account)
if subject == "" {
return nil, fmt.Errorf("%s is not the name of a bus user", account)
}
out := map[string]any{"account": account, "verb": address, "subject": subject}
raw, err := p.Call.Call(CallUserCan, map[string]any{"user": account, "action": "publish", "subject": subject})
if err != nil {
out["bus"] = "not read: " + err.Error()
return out, nil
}
var can struct {
Allowed *bool `json:"allowed"`
}
_ = json.Unmarshal(raw, &can)
out["bus"] = json.RawMessage(raw)
switch {
case can.Allowed == nil:
out["says"] = "the bus's answer names no verdict"
case *can.Allowed:
out["says"] = "not refused at the bus: the account holds the grant to publish " + subject
default:
out["says"] = "the account lacks the grant to publish " + subject
out["lacks"] = subject
}
return out, nil
}