From e5f9e31e7caf40d73b1e45509c3f5179e1b01a37 Mon Sep 17 00:00:00 2001 From: An Tran Date: Tue, 5 Mar 2024 11:56:59 +1000 Subject: [PATCH 1/2] [luacheck] update luacheck settings --- .luacheckrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.luacheckrc b/.luacheckrc index 3fdc64507..45f5b6dce 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -9,6 +9,9 @@ stds.ngx = { } std = 'ngx_lua+lua52+ngx' -- lua52 has table.pack +redefined = false +unused_args = false +max_line_length = false busted = {std = "+busted", globals = { 'fixture' } } files["**/spec/**/*_spec.lua"] = busted From 2cd83c104163dd091535d6207196e4d7ce330b46 Mon Sep 17 00:00:00 2001 From: An Tran Date: Tue, 5 Mar 2024 12:15:43 +1000 Subject: [PATCH 2/2] [luacheck] Fix luacheck warnings --- gateway/src/apicast/configuration.lua | 3 +-- .../apicast/configuration_loader/remote_v2.lua | 1 - gateway/src/apicast/http_proxy.lua | 2 -- gateway/src/apicast/management.lua | 2 +- gateway/src/apicast/policy/apicast/apicast.lua | 1 - .../policy/clear_context/clear_context.lua | 15 ++++++++------- gateway/src/apicast/policy/ip_check/ip_check.lua | 2 +- .../policy/maintenance_mode/maintenance_mode.lua | 4 +++- .../policy/upstream_mtls/upstream_mtls.lua | 2 -- .../policy/url_rewriting/url_rewriting.lua | 2 +- gateway/src/apicast/usage.lua | 1 - gateway/src/resty/http/uri_escape.lua | 2 +- gateway/src/resty/http_ng/headers.lua | 3 +-- gateway/src/resty/http_ng/request.lua | 2 -- gateway/src/resty/openssl/x509/store.lua | 2 +- 15 files changed, 18 insertions(+), 26 deletions(-) diff --git a/gateway/src/apicast/configuration.lua b/gateway/src/apicast/configuration.lua index aa338de36..3520c18e9 100644 --- a/gateway/src/apicast/configuration.lua +++ b/gateway/src/apicast/configuration.lua @@ -17,7 +17,6 @@ local resty_url = require 'resty.url' local util = require 'apicast.util' local policy_chain = require 'apicast.policy_chain' local mapping_rule = require 'apicast.mapping_rule' -local tab_new = require('resty.core.base').new_tab local re = require 'ngx.re' local match = ngx.re.match @@ -67,7 +66,7 @@ local function build_policy_chain(policies) local built_chain = policy_chain.new() for i=1, #policies do - local ok, err = built_chain:add_policy(policies[i].name, policies[i].version, policies[i].configuration) + local _, err = built_chain:add_policy(policies[i].name, policies[i].version, policies[i].configuration) if err then ngx.log(ngx.WARN, 'failed to load policy: ', policies[i].name, ' version: ', policies[i].version, ' err: ', err) end diff --git a/gateway/src/apicast/configuration_loader/remote_v2.lua b/gateway/src/apicast/configuration_loader/remote_v2.lua index cd4e48ca2..7305afa3d 100644 --- a/gateway/src/apicast/configuration_loader/remote_v2.lua +++ b/gateway/src/apicast/configuration_loader/remote_v2.lua @@ -216,7 +216,6 @@ function _M:index_custom_path(host) return nil, 'not initialized' end - local proxy_config_path = self.path local env = resty_env.value('THREESCALE_DEPLOYMENT_ENV') if not env then diff --git a/gateway/src/apicast/http_proxy.lua b/gateway/src/apicast/http_proxy.lua index df55d6258..0c868365b 100644 --- a/gateway/src/apicast/http_proxy.lua +++ b/gateway/src/apicast/http_proxy.lua @@ -1,9 +1,7 @@ local format = string.format local tostring = tostring -local ngx_flush = ngx.flush local ngx_get_method = ngx.req.get_method local ngx_http_version = ngx.req.http_version -local ngx_send_headers = ngx.send_headers local resty_url = require "resty.url" local url_helper = require('resty.url_helper') diff --git a/gateway/src/apicast/management.lua b/gateway/src/apicast/management.lua index abc69212a..ea7bd1be2 100644 --- a/gateway/src/apicast/management.lua +++ b/gateway/src/apicast/management.lua @@ -31,7 +31,7 @@ function _M.live() end local function context_configuration() - return executor:context().configuration or policy_loader:pcall("load_configuration", version or 'builtin') + return executor:context().configuration or policy_loader:pcall("load_configuration", 'builtin') end function _M.status(config) diff --git a/gateway/src/apicast/policy/apicast/apicast.lua b/gateway/src/apicast/policy/apicast/apicast.lua index 56b59da08..b53e6f314 100644 --- a/gateway/src/apicast/policy/apicast/apicast.lua +++ b/gateway/src/apicast/policy/apicast/apicast.lua @@ -64,7 +64,6 @@ function _M:rewrite(context) p:rewrite(service, context) end - local err context[self] = context[self] or {} context[self].upstream, err = p.get_upstream(service, context) context.get_upstream = function() diff --git a/gateway/src/apicast/policy/clear_context/clear_context.lua b/gateway/src/apicast/policy/clear_context/clear_context.lua index e053c3f79..bed688c9d 100644 --- a/gateway/src/apicast/policy/clear_context/clear_context.lua +++ b/gateway/src/apicast/policy/clear_context/clear_context.lua @@ -5,16 +5,17 @@ function _M.new(...) return new(...) end -function _M:ssl_certificate(context) - --resetting the context after every other policy in the chain - --has executed their ssl_certificate phase. - clear_table(ngx.ctx) -end - -function clear_table(t) +local function clear_table(t) for k, _ in pairs(t) do t[k] = nil end end +function _M:ssl_certificate(_) + --resetting the context after every other policy in the chain + --has executed their ssl_certificate phase. + clear_table(ngx.ctx) +end + + return _M diff --git a/gateway/src/apicast/policy/ip_check/ip_check.lua b/gateway/src/apicast/policy/ip_check/ip_check.lua index 2aece91f9..5e6243d32 100644 --- a/gateway/src/apicast/policy/ip_check/ip_check.lua +++ b/gateway/src/apicast/policy/ip_check/ip_check.lua @@ -64,7 +64,7 @@ function _M:access() ngx.log(ngx.INFO, "Rejecting request due to is invalid to retrieve the IP information") deny_request(self.error_msg) return - end + end self:check_client_ip(client_ip) end diff --git a/gateway/src/apicast/policy/maintenance_mode/maintenance_mode.lua b/gateway/src/apicast/policy/maintenance_mode/maintenance_mode.lua index 4394efd9f..5d8f359a7 100644 --- a/gateway/src/apicast/policy/maintenance_mode/maintenance_mode.lua +++ b/gateway/src/apicast/policy/maintenance_mode/maintenance_mode.lua @@ -10,6 +10,8 @@ local new = _M.new local default_status_code = 503 local default_message = "Service Unavailable - Maintenance" local default_message_content_type = "text/plain; charset=utf-8" +local default_template_type = 'plain' +local default_combine_op = "and" local Condition = require('apicast.conditions.condition') local Operation = require('apicast.conditions.operation') @@ -49,7 +51,7 @@ function _M:load_condition(config) self.condition = Condition.new( operations, config.condition.combine_op or default_combine_op) end -function set_maintenance_mode(self) +local function set_maintenance_mode(self) ngx.header['Content-Type'] = self.message_content_type ngx.status = self.status_code ngx.say(self.message) diff --git a/gateway/src/apicast/policy/upstream_mtls/upstream_mtls.lua b/gateway/src/apicast/policy/upstream_mtls/upstream_mtls.lua index bf941aae1..c376d2a1e 100644 --- a/gateway/src/apicast/policy/upstream_mtls/upstream_mtls.lua +++ b/gateway/src/apicast/policy/upstream_mtls/upstream_mtls.lua @@ -105,8 +105,6 @@ local function read_ca_certificates(ca_certificates) if valid then return store.store end - - store = nil end function _M.new(config) diff --git a/gateway/src/apicast/policy/url_rewriting/url_rewriting.lua b/gateway/src/apicast/policy/url_rewriting/url_rewriting.lua index 439906fde..daec00117 100644 --- a/gateway/src/apicast/policy/url_rewriting/url_rewriting.lua +++ b/gateway/src/apicast/policy/url_rewriting/url_rewriting.lua @@ -123,7 +123,7 @@ end function _M:rewrite(context) for _, command in ipairs(self.commands) do local should_apply_command = is_match_methods(command.methods) - + if should_apply_command then local rewritten = apply_rewrite_command(command) diff --git a/gateway/src/apicast/usage.lua b/gateway/src/apicast/usage.lua index d8ef3fd42..fee0d7de3 100644 --- a/gateway/src/apicast/usage.lua +++ b/gateway/src/apicast/usage.lua @@ -6,7 +6,6 @@ local setmetatable = setmetatable local ipairs = ipairs local insert = table.insert local remove = table.remove -local encode_args = ngx.encode_args local tconcat = table.concat local tinsert = table.insert local format = string.format diff --git a/gateway/src/resty/http/uri_escape.lua b/gateway/src/resty/http/uri_escape.lua index 977dfc13a..0e0004c7e 100644 --- a/gateway/src/resty/http/uri_escape.lua +++ b/gateway/src/resty/http/uri_escape.lua @@ -30,7 +30,7 @@ function _M.escape_uri(source_uri) local dst = ffi.new("unsigned char[?]", source_uri_len + 1 + tonumber(escape_len)) ngx_escape_uri(dst, source_str, source_uri_len, 0) - return ffi_str(dst) + return ffi_str(dst) end return _M diff --git a/gateway/src/resty/http_ng/headers.lua b/gateway/src/resty/http_ng/headers.lua index 48c4f3689..1fed28fdd 100644 --- a/gateway/src/resty/http_ng/headers.lua +++ b/gateway/src/resty/http_ng/headers.lua @@ -1,7 +1,6 @@ local insert = table.insert local concat = table.concat local assert = assert -local pairs = pairs local rawset = rawset local rawget = rawget local setmetatable = setmetatable @@ -78,7 +77,7 @@ end headers.normalize = function(http_headers) http_headers = http_headers or {} - + local serialize = function(k,v) return headers.normalize_value(v), headers.normalize_key(k) end diff --git a/gateway/src/resty/http_ng/request.lua b/gateway/src/resty/http_ng/request.lua index ae4db14ac..8c4907895 100644 --- a/gateway/src/resty/http_ng/request.lua +++ b/gateway/src/resty/http_ng/request.lua @@ -1,5 +1,3 @@ -local find = string.find -local sub = string.sub local assert = assert local setmetatable = setmetatable local resty_url = require 'resty.url' diff --git a/gateway/src/resty/openssl/x509/store.lua b/gateway/src/resty/openssl/x509/store.lua index 07966e320..4ebc6176f 100644 --- a/gateway/src/resty/openssl/x509/store.lua +++ b/gateway/src/resty/openssl/x509/store.lua @@ -80,7 +80,7 @@ function _M.new() local verify_param = X509_VERIFY_PARAM(X509_V_FLAG_PARTIAL_CHAIN) ffi_assert(C.X509_STORE_set1_param(store, verify_param),1) - + local self = setmetatable({ store = store, }, mt)