nats: say whether a user's grant is in force on the running server, not only written (hq issue 353)
mesh/merge-gate pass: builds nats, sent nowhere; merging this needs a person's bus upgrade; 1 wait(s) for a person; every machine composes with the change …
mesh/repo-check pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-check-typescript.sh (typescript)
mesh/delivery delivered
mesh/merge-gate pass: builds nats, sent nowhere; merging this needs a person's bus upgrade; 1 wait(s) for a person; every machine composes with the change …
mesh/repo-check pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-check-typescript.sh (typescript)
mesh/delivery delivered
nats_user_can read the user list on the machine. A list written is not a list the bus enforces until the server reloads it: on 2026-10-09 the controller asked between the write and the reload's effect. The answer now carries in_force — allowed in the file, and the server's config_load_time after the file's write — with why when it is not, and anything not known is not in force.
This commit is contained in:
@@ -65,3 +65,24 @@ func ReadUsers(ctx context.Context) ([]byte, error) {
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UsersWritten is when the composed user list the server includes was last written, read in the container
|
||||
// to the nanosecond (`stat -c %y`): what the server's last reload must come after for the list to be in force.
|
||||
func UsersWritten(ctx context.Context) (time.Time, error) {
|
||||
container := env("MESH_NATS_CONTAINER", "mesh-broker-nats")
|
||||
path := env("MESH_NATS_USERS_FILE", "/etc/nats/accounts.conf")
|
||||
out, err := exec.CommandContext(ctx, "docker", "exec", container, "stat", "-c", "%y", path).Output()
|
||||
if err != nil {
|
||||
return time.Time{}, fmt.Errorf("when the bus's user list was written could not be read inside %s: %w", container, err)
|
||||
}
|
||||
return ParseWritten(string(out))
|
||||
}
|
||||
|
||||
// ParseWritten reads `stat -c %y`: "2026-10-09 17:38:13.422211788 +0000".
|
||||
func ParseWritten(s string) (time.Time, error) {
|
||||
t, err := time.Parse("2006-01-02 15:04:05.999999999 -0700", strings.TrimSpace(s))
|
||||
if err != nil {
|
||||
return time.Time{}, fmt.Errorf("when the bus's user list was written is not a time: %q", strings.TrimSpace(s))
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user