Skip to content

Commit

Permalink
add acl plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
felipejfc committed Jun 17, 2016
1 parent e31cc41 commit 5982171
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
7 changes: 6 additions & 1 deletion config/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ mqttserver:
qos: 2
plugins:
- plugin: "register_user"
messagePattern: ".*"
messagePattern: "register"
- topic: 'mqttbot/acl/#'
qos: 2
plugins:
- plugin: "add_user_subscription_acl"
messagePattern: "aclpermitsubscription"
elasticsearch:
host: "http://localhost:9200"
sniff: false
Expand Down
26 changes: 26 additions & 0 deletions plugins/add_user_subscription_acl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
local redis = require 'redis_module'
local json = require 'json'

function register_subscriptions(username, subscriptions)
for i = 1, #subscriptions do
err, ret = redis.execute("set", 2, username.."-"..subscriptions[i], 2)
if err ~= nil then
return err, 1
end
end
return nil, 0
end

function run_plugin(topic, payload)
local json_message = json.decode(payload)
--message: {"payload": {"message": "aclpermitsubscription", "username": "username", subscriptions: ["subs1", "subs2"]}}
local username = json_message["payload"]["username"]
local subscriptions = json_message["payload"]["subscriptions"]
if subscriptions ~= nil then
err, ret = register_subscriptions(username, subscriptions)
if err ~= nil then
return err, 1
end
end
return nil, 0
end
1 change: 0 additions & 1 deletion plugins/register_user.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ end
function run_plugin(topic, payload)
local json_message = json.decode(payload)
--message: {"payload": {"message": "register", "username": "username", "password": "userpass", subscriptions: ["subs1", "subs2"]}}
print(payload, json_message)
local username = json_message["payload"]["username"]
local pass = json_message["payload"]["password"]
local subscriptions = json_message["payload"]["subscriptions"]
Expand Down

0 comments on commit 5982171

Please sign in to comment.