Skip to content

Commit

Permalink
Merge pull request #41 from croessner/features
Browse files Browse the repository at this point in the history
Features
  • Loading branch information
croessner authored Jul 3, 2024
2 parents 358f817 + 9a0c2e0 commit 9da2c35
Show file tree
Hide file tree
Showing 7 changed files with 463 additions and 33 deletions.
6 changes: 1 addition & 5 deletions server/backend/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ func setupGlobals(luaRequest *LuaRequest, L *lua.LState, logs *lualib.CustomLogK
globals.RawSetString(global.LuaFnAddCustomLog, L.NewFunction(lualib.AddCustomLog(logs)))
globals.RawSetString(global.LuaFnSetStatusMessage, L.NewFunction(lualib.SetStatusMessage(&luaRequest.StatusMessage)))
globals.RawSetString(global.LuaFnGetAllHTTPRequestHeaders, L.NewFunction(lualib.GetAllHTTPRequestHeaders(luaRequest.HTTPClientContext.Request)))
globals.RawSetString(global.LuaFnRedisGet, L.NewFunction(lualib.RedisGet))
globals.RawSetString(global.LuaFnRedisSet, L.NewFunction(lualib.RedisSet))
globals.RawSetString(global.LuaFnRedisIncr, L.NewFunction(lualib.RedisIncr))
globals.RawSetString(global.LuaFnRedisDel, L.NewFunction(lualib.RedisDel))
globals.RawSetString(global.LuaFnRedisExpire, L.NewFunction(lualib.RedisExpire))
lualib.SetUPRedisFunctions(globals, L)

if config.LoadableConfig.HaveLDAPBackend() {
globals.RawSetString(global.LuaFnLDAPSearch, L.NewFunction(LuaLDAPSearch(luaRequest.HTTPClientContext)))
Expand Down
45 changes: 43 additions & 2 deletions server/global/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,11 +965,12 @@ const (
LuaFnGetHTTPRequestBody = "get_http_request_body"

// LuaFnRedisGet represents the function name for "redis_get_str" in Lua
LuaFnRedisGet = "redis_get_str"
LuaFnRedisGet = "redis_get"

// LuaFnRedisSet represents the function name for "redis_set_str" in Lua
LuaFnRedisSet = "redis_set_str"
LuaFnRedisSet = "redis_set"

// LuaFnRedisIncr represents a constant string identifier for the Lua function redis_incr.
LuaFnRedisIncr = "redis_incr"

// LuaFnRedisDel represents the function name for "redis_det" in Lua
Expand All @@ -978,6 +979,30 @@ const (
// LuaFnRedisExpire represents the function name for "redis_expire" in Lua
LuaFnRedisExpire = "redis_expire"

// LuaFnRedisHGet represents the function name for "redis_hget" in Lua.
LuaFnRedisHGet = "redis_hget"

// LuaFnRedisHSet represents the function name for "redis_hset" in Lua
LuaFnRedisHSet = "redis_hset"

// LuaFnRedisHDel represents the function name for "redis_hdel" in Lua
LuaFnRedisHDel = "redis_hdel"

// LuaFnRedisHLen represents the function name for "redis_hlen" in Lua.
LuaFnRedisHLen = "redis_hlen"

// LuaFnRedisHGetAll represents the function name for "redis_hgetall" in Lua
LuaFnRedisHGetAll = "redis_hgetall"

// LuaFNRedisHIncrBy represents the function name for "redis_hincrby" in Lua.
LuaFNRedisHIncrBy = "redis_hincrby"

// LuaFNRedisHIncrByFloat represents the function name for "redis_hincrbyfloat" in Lua.
LuaFNRedisHIncrByFloat = "redis_hincrbyfloat"

// LuaFnRedisHExists represents the Lua function name for checking if a field exists in a Redis hash.
LuaFnRedisHExists = "redis_hexists"

// LuaFnApplyBackendResult applies changes to the backend result from a former authentication process.
LuaFnApplyBackendResult = "apply_backend_result"

Expand Down Expand Up @@ -1042,11 +1067,27 @@ const (
)

const (
//LuaLiteralString is a Lua "string" type
LuaLiteralString = "string"

// LuaLiteralTable is a Lua "table" type
LuaLiteralTable = "table"
)

const (
// TypeString represents a string type
TypeString = "string"

// TypeNumber represents a number type (float64)
TypeNumber = "number"

// TypeBoolean represents a boolean type
TypeBoolean = "bool"

// TypeNil represents the nil value type
TypeNil = "nil"
)

const (
// LuaRequestDebug is for debugging purposes.
LuaRequestDebug = "debug"
Expand Down
6 changes: 1 addition & 5 deletions server/lualib/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,7 @@ func (aw *Worker) setupGlobals(L *lua.LState, logs *lualib.CustomLogKeyValue, ht
globals.RawSetString(global.LuaFnCtxDelete, L.NewFunction(lualib.ContextDelete(aw.luaActionRequest.Context)))
globals.RawSetString(global.LuaFnAddCustomLog, L.NewFunction(lualib.AddCustomLog(logs)))
globals.RawSetString(global.LuaFnGetAllHTTPRequestHeaders, L.NewFunction(lualib.GetAllHTTPRequestHeaders(httpRequest)))
globals.RawSetString(global.LuaFnRedisGet, L.NewFunction(lualib.RedisGet))
globals.RawSetString(global.LuaFnRedisSet, L.NewFunction(lualib.RedisSet))
globals.RawSetString(global.LuaFnRedisIncr, L.NewFunction(lualib.RedisIncr))
globals.RawSetString(global.LuaFnRedisDel, L.NewFunction(lualib.RedisDel))
globals.RawSetString(global.LuaFnRedisExpire, L.NewFunction(lualib.RedisExpire))
lualib.SetUPRedisFunctions(globals, L)

if config.LoadableConfig.HaveLDAPBackend() {
globals.RawSetString(global.LuaFnLDAPSearch, L.NewFunction(backend.LuaLDAPSearch(context.Background())))
Expand Down
6 changes: 1 addition & 5 deletions server/lualib/callback/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,9 @@ func getHTTPRequestBody(httpRequest *http.Request) lua.LGFunction {
func setupGlobals(ctx *gin.Context, L *lua.LState) *lua.LTable {
globals := L.NewTable()

globals.RawSetString(global.LuaFnRedisGet, L.NewFunction(lualib.RedisGet))
globals.RawSetString(global.LuaFnRedisSet, L.NewFunction(lualib.RedisSet))
globals.RawSetString(global.LuaFnRedisIncr, L.NewFunction(lualib.RedisIncr))
globals.RawSetString(global.LuaFnRedisDel, L.NewFunction(lualib.RedisDel))
globals.RawSetString(global.LuaFnRedisExpire, L.NewFunction(lualib.RedisExpire))
globals.RawSetString(global.LuaFnGetAllHTTPRequestHeaders, L.NewFunction(lualib.GetAllHTTPRequestHeaders(ctx.Request)))
globals.RawSetString(global.LuaFnGetHTTPRequestBody, L.NewFunction(getHTTPRequestBody(ctx.Request)))
lualib.SetUPRedisFunctions(globals, L)

L.SetGlobal(global.LuaDefaultTable, globals)

Expand Down
6 changes: 1 addition & 5 deletions server/lualib/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,7 @@ func (r *Request) setGlobals(ctx *gin.Context, L *lua.LState) *lua.LTable {
globals.RawSetString(global.LuaFnAddCustomLog, L.NewFunction(lualib.AddCustomLog(r.Logs)))
globals.RawSetString(global.LuaFnSetStatusMessage, L.NewFunction(lualib.SetStatusMessage(&r.StatusMessage)))
globals.RawSetString(global.LuaFnGetAllHTTPRequestHeaders, L.NewFunction(lualib.GetAllHTTPRequestHeaders(ctx.Request)))
globals.RawSetString(global.LuaFnRedisGet, L.NewFunction(lualib.RedisGet))
globals.RawSetString(global.LuaFnRedisSet, L.NewFunction(lualib.RedisSet))
globals.RawSetString(global.LuaFnRedisIncr, L.NewFunction(lualib.RedisIncr))
globals.RawSetString(global.LuaFnRedisDel, L.NewFunction(lualib.RedisDel))
globals.RawSetString(global.LuaFnRedisExpire, L.NewFunction(lualib.RedisExpire))
lualib.SetUPRedisFunctions(globals, L)

if config.LoadableConfig.HaveLDAPBackend() {
globals.RawSetString(global.LuaFnLDAPSearch, L.NewFunction(backend.LuaLDAPSearch(ctx)))
Expand Down
6 changes: 1 addition & 5 deletions server/lualib/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,7 @@ func setGlobals(ctx *gin.Context, r *Request, L *lua.LState, backendResult **lua
globals.RawSetString(global.LuaFnSetStatusMessage, L.NewFunction(lualib.SetStatusMessage(&r.StatusMessage)))
globals.RawSetString(global.LuaFnApplyBackendResult, L.NewFunction(applyBackendResult(backendResult)))
globals.RawSetString(global.LuaFnGetAllHTTPRequestHeaders, L.NewFunction(lualib.GetAllHTTPRequestHeaders(ctx.Request)))
globals.RawSetString(global.LuaFnRedisGet, L.NewFunction(lualib.RedisGet))
globals.RawSetString(global.LuaFnRedisSet, L.NewFunction(lualib.RedisSet))
globals.RawSetString(global.LuaFnRedisIncr, L.NewFunction(lualib.RedisIncr))
globals.RawSetString(global.LuaFnRedisDel, L.NewFunction(lualib.RedisDel))
globals.RawSetString(global.LuaFnRedisExpire, L.NewFunction(lualib.RedisExpire))
lualib.SetUPRedisFunctions(globals, L)

if config.LoadableConfig.HasFeature(global.FeatureBackendServersMonitoring) {
globals.RawSetString(global.LuaFnGetBackendServers, L.NewFunction(getBackendServers(r.BackendServers)))
Expand Down
Loading

0 comments on commit 9da2c35

Please sign in to comment.