-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: required changes for 3.1 compatibility #36
Changes from 6 commits
14256e9
2f294c1
4ac298b
b6e369b
788f46c
86df807
ff8aeb1
ab748dd
393daa9
739a308
001809f
884c12f
23c7b76
0345f15
ea9bcf7
b47d2e6
33e4b3c
9798f25
8bd2cdc
a7b66b9
74a909b
fc044a8
cddf098
821f5f7
4c25d00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
local tablex = require "pl.tablex" | ||
local pretty = require "pl.pretty" | ||
local utils = require "kong.tools.utils" | ||
local nkeys = require "table.nkeys" | ||
|
||
local cjson = { array_mt = {} } --- TODO(hbagdi) XXX analyze the impact | ||
local is_reference = function(value) return false end | ||
|
@@ -55,6 +54,23 @@ do | |
end | ||
end | ||
|
||
-- `table.nkeys()` is a LuaJIT function and is not available to the Lua VM that goks uses. | ||
local nkeys | ||
do | ||
local ok | ||
ok, nkeys = pcall(require, "table.nkeys") | ||
if not ok then | ||
nkeys = function (tab) | ||
local count = 0 | ||
for _, v in pairs(tab) do | ||
if v ~= nil then | ||
count = count + 1 | ||
end | ||
end | ||
return count | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is copypasta from resty/healthecheck.lua. I'm following the pattern of
I can't tell if this resolves the issue, however. I get a new error:
I'm able to validate the method is called. The if block beginning on line 62 is entered but The stacktrace is also not very illuminating: My guess is either:
Number 1 is the most reasonable, but I don't really understand what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
the LOG_LEVELS = {
debug = ngx.DEBUG,
info = ngx.INFO,
notice = ngx.NOTICE,
warn = ngx.WARN,
error = ngx.ERR,
crit = ngx.CRIT,
alert = ngx.ALERT,
emerg = ngx.EMERG,
[ngx.DEBUG] = "debug",
[ngx.INFO] = "info",
[ngx.NOTICE] = "notice",
[ngx.WARN] = "warn",
[ngx.ERR] = "error",
[ngx.CRIT] = "crit",
[ngx.ALERT] = "alert",
[ngx.EMERG] = "emerg",
}, lines 231-238 use the form Now to find where are those There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can't find them. I think the easiest would be to add to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
local validation_errors = { | ||
-- general message | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1267,7 +1267,7 @@ _M.yield = function() return end | |
local try_decode_base64 | ||
do | ||
local decode_base64 = ngx.decode_base64 | ||
local decode_base64url = require "ngx.base64".decode_base64url | ||
local decode_base64url = ngx.decode_base64url | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addresses:
This (and other instances) will need to be added to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's already There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We have |
||
|
||
local function decode_base64_str(str) | ||
if type(str) == "string" then | ||
|
@@ -1299,42 +1299,15 @@ end | |
_M.try_decode_base64 = try_decode_base64 | ||
|
||
|
||
local sha256_bin | ||
do | ||
local digest = require "resty.openssl.digest" | ||
local sha256_digest | ||
|
||
function sha256_bin(key) | ||
local _, bin, err | ||
if not sha256_digest then | ||
sha256_digest, err = digest.new("sha256") | ||
if err then | ||
return nil, err | ||
end | ||
end | ||
|
||
bin, err = sha256_digest:final(key) | ||
if err then | ||
sha256_digest = nil | ||
return nil, err | ||
end | ||
|
||
_, err = sha256_digest:reset() | ||
if err then | ||
sha256_digest = nil | ||
end | ||
|
||
return bin | ||
end | ||
end | ||
local sha256_bin = require "sha256".sha256_bin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addresses:
This will need to be added to lua-tree.patch. |
||
_M.sha256_bin = sha256_bin | ||
|
||
|
||
local sha256_hex, sha256_base64, sha256_base64url | ||
do | ||
local to_hex = require "resty.string".to_hex | ||
local to_hex = require "hex".to_hex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addresses another instance of |
||
local to_base64 = ngx.encode_base64 | ||
local to_base64url = require "ngx.base64".encode_base64url | ||
local to_base64url = ngx.encode_base64url | ||
|
||
local function sha256_encode(encode_alg, key) | ||
local bin, err = sha256_bin(key) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package hex | ||
|
||
import ( | ||
"encoding/hex" | ||
|
||
lua "github.com/yuin/gopher-lua" | ||
) | ||
|
||
// Encode encodes input string into hex bytes. It is a wrapper around | ||
// encoding/hex.Encode and replaces resty.string.to_hex. | ||
// See: https://github.com/openresty/lua-resty-string/blob/master/lib/resty/string.lua | ||
func Encode(l *lua.LState) int { | ||
input := l.CheckString(1) | ||
|
||
dst := make([]byte, hex.EncodedLen(len(input))) | ||
hex.Encode(dst, []byte(input)) | ||
|
||
l.Push(lua.LString(dst)) | ||
return 1 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package hex | ||
|
||
import lua "github.com/yuin/gopher-lua" | ||
|
||
func Loader(l *lua.LState) int { | ||
t := l.NewTable() | ||
l.SetFuncs(t, api) | ||
l.Push(t) | ||
return 1 | ||
} | ||
|
||
var api = map[string]lua.LGFunction{ | ||
"to_hex": Encode, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package sha256 | ||
|
||
import ( | ||
"crypto/sha256" | ||
|
||
lua "github.com/yuin/gopher-lua" | ||
) | ||
|
||
func BinarySha256(l *lua.LState) int { | ||
input := l.CheckString(1) | ||
h := sha256.New() | ||
h.Write([]byte(input)) | ||
l.Push(lua.LString(h.Sum(nil))) | ||
h.Reset() | ||
return 1 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package sha256 | ||
|
||
import lua "github.com/yuin/gopher-lua" | ||
|
||
func Loader(l *lua.LState) int { | ||
t := l.NewTable() | ||
l.SetFuncs(t, api) | ||
l.Push(t) | ||
return 1 | ||
} | ||
|
||
var api = map[string]lua.LGFunction{ | ||
"sha256_bin": BinarySha256, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using the pattern "go.xxx" for those replacement modules:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
33e4b3c