Skip to content
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

refactor(pdk): use resty.core.utils.str_replace_char instead of gsub #11823

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions kong/pdk/service/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
local cjson = require "cjson.safe".new()
local multipart = require "multipart"
local phase_checker = require "kong.pdk.private.phases"
local string_tools = require "kong.tools.string"


local ngx = ngx
local sub = string.sub
local fmt = string.format
local gsub = string.gsub
local find = string.find
local type = type
local error = error
Expand All @@ -26,6 +26,10 @@ local check_phase = phase_checker.check
cjson.decode_array_with_array_mt(true)


local replace_dashes = string_tools.replace_dashes
local replace_dashes_lower = string_tools.replace_dashes_lower


local PHASES = phase_checker.phases


Expand All @@ -45,7 +49,7 @@ do
local resp_headers_mt = {
__index = function(t, name)
if type(name) == "string" then
local var = fmt("upstream_http_%s", gsub(lower(name), "-", "_"))
local var = fmt("upstream_http_%s", replace_dashes_lower(name))
if not ngx.var[var] then
return nil
end
Expand Down Expand Up @@ -94,7 +98,7 @@ do
return response_headers[name]
end

name = gsub(name, "-", "_")
name = replace_dashes(name)

if response_headers[name] then
return response_headers[name]
Expand All @@ -106,7 +110,7 @@ do
return nil
end

n = gsub(lower(n), "-", "_")
n = replace_dashes_lower(n)
if n == name then
return v
end
Expand Down
7 changes: 4 additions & 3 deletions kong/pdk/vault.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ local isempty = require "table.isempty"
local buffer = require "string.buffer"
local clone = require "table.clone"
local utils = require "kong.tools.utils"
local string_tools = require "kong.tools.string"
local cjson = require("cjson.safe").new()


local yield = utils.yield
local get_updated_now_ms = utils.get_updated_now_ms
local replace_dashes = string_tools.replace_dashes


local ngx = ngx
Expand All @@ -30,7 +32,6 @@ local max = math.max
local fmt = string.format
local sub = string.sub
local byte = string.byte
local gsub = string.gsub
local type = type
local sort = table.sort
local pcall = pcall
Expand Down Expand Up @@ -539,7 +540,7 @@ local function new(self)
base_config = {}
if self and self.configuration then
local configuration = self.configuration
local env_name = gsub(name, "-", "_")
local env_name = replace_dashes(name)
local _, err, schema = get_vault_strategy_and_schema(name)
if not schema then
return nil, err
Expand All @@ -553,7 +554,7 @@ local function new(self)
-- then you would configure it with KONG_VAULT_MY_VAULT_<setting>
-- or in kong.conf, where it would be called
-- "vault_my_vault_<setting>".
local n = lower(fmt("vault_%s_%s", env_name, gsub(k, "-", "_")))
local n = lower(fmt("vault_%s_%s", env_name, replace_dashes(k)))
local v = configuration[n]
v = arguments.infer_value(v, f)
-- TODO: should we be more visible with validation errors?
Expand Down