Skip to content

Instantly share code, notes, and snippets.

@cmnstmntmn
Last active July 16, 2018 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmnstmntmn/ba914cb75e86d59bd9ea88497e9a5058 to your computer and use it in GitHub Desktop.
Save cmnstmntmn/ba914cb75e86d59bd9ea88497e9a5058 to your computer and use it in GitHub Desktop.
verne-crdb
2018-07-16 09:40:06.756 [error] <0.409.0>@vmq_diversity_lager:error:36 a intrat aici
2018-07-16 09:40:06.758 [error] <0.409.0>@vmq_diversity_lager:error:36 all bad
2018-07-16 09:40:06.758 [warning] <0.491.0>@vmq_mqtt_fsm:check_user:555 can't authenticate client {[],<<"ctin">>} due to error
I180716 06:41:39.864637 8714 sql/exec_log.go:168 [n1,client=127.0.0.1:64023,user=root] 896 exec "" {} "SELECT publish_acl::TEXT, subscribe_acl::TEXT FROM vmq_auth_acl WHERE (((mountpoint = $1) AND (client_id = $2)) AND (username = $3)) AND (password = $4)" {$1:"''", $2:"'ctin'", $3:"'ion'", $4:"'123'"} 0.856 0 ""
function auth_on_register(reg)
if reg.username ~= nil and reg.password ~= nil then
results = postgres.execute(pool,
[[SELECT publish_acl::TEXT, subscribe_acl::TEXT
FROM vmq_auth_acl
WHERE
mountpoint=$1 AND
client_id=$2 AND
username=$3 AND
password=$4
]],
reg.mountpoint,
reg.client_id,
reg.username,
reg.password)
if #results == 1 then
row = results[1]
publish_acl = json.decode(row.publish_acl)
subscribe_acl = json.decode(row.subscribe_acl)
cache_insert(
reg.mountpoint,
reg.client_id,
reg.username,
publish_acl,
subscribe_acl
)
log.error("all good")
return true
else
log.error("all bad")
return false
end
end
end
pool = "auth_crdb"
config = {
pool_id = pool,
}
postgres.ensure_pool(config)
hooks = {
auth_on_register = auth_on_register,
auth_on_publish = auth_on_publish,
auth_on_subscribe = auth_on_subscribe,
on_unsubscribe = on_unsubscribe,
on_client_gone = on_client_gone,
on_client_offline = on_client_offline
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment