transtone / lua-resty-casbin-adapter

casbin-adapter is a OpenResty based adapter for Casbin that supports policies from SQL-based databases (MySQL, PostgreSQL).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lua-resty-casbin-adapter

lua-resty-casbin-adapter is a LuaSQL based adapter for Casbin that supports policies from SQL-based databases (MySQL, PostgreSQL, SQLite3).

Installation

First, install the corresponding driver of LuaSQL from LuaRocks based on the database you use:

  • For MySQL, install luasql-mysql.
  • For PostgreSQL, install luasql-postgres.
  • For SQLite3, install luasql-sqlite3.

Then install the casbin-adapter from LuaRocks by

sudo luarocks install https://raw.githubusercontent.com/transtone/lua-resty-casbin-adapter/main/casbin-adapter-1.0.0-1.rockspec
local Enforcer = require("casbin")
local Adapter  = require("casbin.postgres")

local pg_conf = {
    timeout = 1200,
    connect_config = {
        host = "127.0.0.1",
        port = 5432,
        database = "izw",
        user = "tom",
        password = "",
        max_packet_size = 1024 * 1024,
        charset = "utf8",
        application_name = "iot",

        ssl = false,
        ssl_required = nil,
        socket_type = "nginx",  -- "luasocket"
        application_name = "iot",
    },
    pool_config = {
        max_idle_timeout = 20000, -- 20s
        pool_size = 50 -- connection pool size
    }
}

local a = Adapter:new(pg_conf, "casbin_rules") -- hostname, port are optional
local e = Enforcer:new("/path/to/model.conf", a) --reates a new Casbin enforcer with the model.conf file and the database

About

casbin-adapter is a OpenResty based adapter for Casbin that supports policies from SQL-based databases (MySQL, PostgreSQL).

License:Apache License 2.0


Languages

Language:Lua 99.6%Language:Shell 0.4%