class

LavinMQ::MQTT::PermissionService

Inherits Reference < Object

Every change rebuilds the compiled state and publishes it with one reference assignment, so readers never see stale or partial state.

A topic is allowed only when a rule grants it. A vhost is still open by default: the DEFAULT_GROUP grants every user every topic, and the operator locks the vhost down by deleting or narrowing that group.

Constants

DEFAULT_GROUP = PermissionGroup::DEFAULT_NAME
Log = LavinMQ::Log.for("mqtt.permission_service")

Constructors

new(vhost : String, data_dir : String, replicator : Clustering::Replicator | Nil, default_group = true)

A vhost without mqtt_permissions.json gets the DEFAULT_GROUP unless default_group is false, and the result is saved at once, so the file always holds the groups that are in effect.

Source

Instance methods

[]?(name : String) : PermissionGroup | Nil
Source
can_read?(context : Context, topic : String) : Bool
Source
can_write?(context : Context, topic : String) : Bool
Source
create(group : PermissionGroup) : Bool

Commit the group only when its name is free, so a concurrent create or import cannot be overwritten. Returns false when the name is taken.

Source
delete(name : String) : PermissionGroup | Nil
Source
each_value
Source
import(imported : Array(PermissionGroup), skip_existing = false) : Nil

Commit all imported groups together. Check existing names under the same lock as API edits. An import adds and replaces groups, it never deletes one.

Source
put(group : PermissionGroup) : PermissionGroup
Source
size
Source
to_json(json : JSON::Builder)
Source
update(name : String, & : PermissionGroup -> PermissionGroup | Nil) : Bool

Read the group and commit the change under one lock, so an edit that commits while the caller prepares its own change is not overwritten. The block returns nil to leave the group as it is. Returns false when no group has that name. The block runs with the lock held, so it must not call back into the service and it must not wait on IO.

Source
values
Source

Nested types