mosquitto-acl-parser
v1.0.0
Published
Parse and Stringify Mosquitto ACLs
Downloads
11
Maintainers
Readme
mosquitto-acl-parser
Parse and Stringify Mosquitto ACLs
This tiny module parses Mosquitto ACLs into a Javascript object and stringifies objects back into a ACL string.
Usage
npm install mosquitto-acl-parser
.parse(string)
const macl = require('mosquitto-acl-parser');
const acl = macl.parse(`# This affects access control for clients with no username.
topic read $SYS/#
# This only affects clients with username "roger".
user roger
topic foo/bar
# This affects all clients.
pattern write $SYS/broker/connection/%c/state`);
acl
contains then...
{
"topics": [
{
"perm": "read",
"topic": "$SYS/#"
}
],
"users": {
"roger": [
{
"perm": "readwrite",
"topic": "foo/bar"
}
]
},
"patterns": [
{
"perm": "write",
"topic": "$SYS/broker/connection/%c/state"
}
]
}
.stringify(acl)
const macl = require('mosquitto-acl-parser');
console.log(macl.stringify({
topics: [
{
perm: 'read',
topic: 'everyone/can/read '
},
{
perm: 'readwrite',
topic: 'everyone/can/readwrite'
}
],
users: {
user1: [
{
perm: 'read',
topic: 'user1/can/read'
},
{
perm: 'readwrite',
topic: 'user1/can/readwrite'
}
],
user2: [
{
perm: 'read',
topic: 'user2/can/read'
},
{
perm: 'readwrite',
topic: 'user2/can/readwrite'
}
]
},
patterns: [
{
perm: 'read',
topic: 'pattern/%u/can/read'
},
{
perm: 'readwrite',
topic: 'pattern/%u/can/readwrite'
}
]
}));
Outputs...
# created by mosquitto-acl-parser
topic read everyone/can/read
topic readwrite everyone/can/readwrite
user user1
topic read user1/can/read
topic readwrite user1/can/readwrite
user user2
topic read user2/can/read
topic readwrite user2/can/readwrite
pattern read pattern/%u/can/read
pattern readwrite pattern/%u/can/readwrite
License
MIT (c) 2017 Sebastian Raff