diff --git a/kong/cache/warmup.lua b/kong/cache/warmup.lua index 3d7829f94f7f..5ce12816627b 100644 --- a/kong/cache/warmup.lua +++ b/kong/cache/warmup.lua @@ -1,4 +1,4 @@ -local utils = require "kong.tools.utils" +local hostname_type = require("kong.tools.ip").hostname_type local constants = require "kong.constants" local buffer = require "string.buffer" local acl_groups @@ -131,7 +131,7 @@ function cache_warmup.single_dao(dao) end if entity_name == "services" then - if utils.hostname_type(entity.host) == "name" + if hostname_type(entity.host) == "name" and hosts_set[entity.host] == nil then host_count = host_count + 1 hosts_array[host_count] = entity.host diff --git a/kong/conf_loader/listeners.lua b/kong/conf_loader/listeners.lua index e4dadd820e02..7e638b3618e5 100644 --- a/kong/conf_loader/listeners.lua +++ b/kong/conf_loader/listeners.lua @@ -1,5 +1,5 @@ local pl_stringx = require "pl.stringx" -local utils = require "kong.tools.utils" +local tools_ip = require "kong.tools.ip" local type = type @@ -109,14 +109,14 @@ local function parse_listeners(values, flags) -- verify IP for remainder local ip - if utils.hostname_type(remainder) == "name" then + if tools_ip.hostname_type(remainder) == "name" then -- it's not an IP address, so a name/wildcard/regex ip = {} ip.host, ip.port = remainder:match("(.+):([%d]+)$") else -- It's an IPv4 or IPv6, normalize it - ip = utils.normalize_ip(remainder) + ip = tools_ip.normalize_ip(remainder) -- nginx requires brackets in IPv6 addresses, but normalize_ip does -- not include them (due to backwards compatibility with its other uses) if ip and ip.type == "ipv6" then diff --git a/kong/db/dao/targets.lua b/kong/db/dao/targets.lua index 09077ec670b2..42efb3a3f070 100644 --- a/kong/db/dao/targets.lua +++ b/kong/db/dao/targets.lua @@ -1,7 +1,7 @@ local balancer = require "kong.runloop.balancer" -local utils = require "kong.tools.utils" local cjson = require "cjson" local workspaces = require "kong.workspaces" +local tools_ip = require "kong.tools.ip" local setmetatable = setmetatable @@ -29,11 +29,11 @@ end local function format_target(target) - local p = utils.normalize_ip(target) + local p = tools_ip.normalize_ip(target) if not p then return false, "Invalid target; not a valid hostname or ip address" end - return utils.format_host(p, DEFAULT_PORT) + return tools_ip.format_host(p, DEFAULT_PORT) end @@ -296,13 +296,13 @@ end function _TARGETS:post_health(upstream_pk, target, address, is_healthy) local upstream = balancer.get_upstream_by_id(upstream_pk.id) - local host_addr = utils.normalize_ip(target.target) - local hostname = utils.format_host(host_addr.host) + local host_addr = tools_ip.normalize_ip(target.target) + local hostname = tools_ip.format_host(host_addr.host) local ip local port if address ~= nil then - local addr = utils.normalize_ip(address) + local addr = tools_ip.normalize_ip(address) ip = addr.host if addr.port then port = addr.port diff --git a/kong/db/schema/entities/targets.lua b/kong/db/schema/entities/targets.lua index 0f735581a941..21096f21fdc6 100644 --- a/kong/db/schema/entities/targets.lua +++ b/kong/db/schema/entities/targets.lua @@ -1,9 +1,10 @@ local typedefs = require "kong.db.schema.typedefs" local utils = require "kong.tools.utils" +local normalize_ip = require("kong.tools.ip").normalize_ip local function validate_target(target) - local p = utils.normalize_ip(target) + local p = normalize_ip(target) if not p then local ok = utils.validate_utf8(target) if not ok then diff --git a/kong/db/schema/entities/upstreams.lua b/kong/db/schema/entities/upstreams.lua index 6d3c963411c3..5f13038518d6 100644 --- a/kong/db/schema/entities/upstreams.lua +++ b/kong/db/schema/entities/upstreams.lua @@ -1,6 +1,7 @@ local Schema = require "kong.db.schema" local typedefs = require "kong.db.schema.typedefs" local utils = require "kong.tools.utils" +local normalize_ip = require("kong.tools.ip").normalize_ip local null = ngx.null @@ -15,7 +16,7 @@ end local validate_name = function(name) - local p = utils.normalize_ip(name) + local p = normalize_ip(name) if not p then return nil, get_name_for_error(name) .. "; must be a valid hostname" end diff --git a/kong/db/schema/typedefs.lua b/kong/db/schema/typedefs.lua index 0b0de71d9ea1..d3bee459d2c7 100644 --- a/kong/db/schema/typedefs.lua +++ b/kong/db/schema/typedefs.lua @@ -8,6 +8,7 @@ local openssl_x509 = require "resty.openssl.x509" local Schema = require "kong.db.schema" local socket_url = require "socket.url" local constants = require "kong.constants" +local tools_ip = require "kong.tools.ip" local DAO_MAX_TTL = constants.DATABASE.DAO_MAX_TTL @@ -20,7 +21,7 @@ local type = type local function validate_host(host) - local res, err_or_port = utils.normalize_ip(host) + local res, err_or_port = tools_ip.normalize_ip(host) if type(err_or_port) == "string" and err_or_port ~= "invalid port number" then return nil, "invalid value: " .. host end @@ -34,13 +35,13 @@ end local function validate_host_with_optional_port(host) - local res, err_or_port = utils.normalize_ip(host) + local res, err_or_port = tools_ip.normalize_ip(host) return (res and true or nil), err_or_port end local function validate_ip(ip) - if utils.is_valid_ip(ip) then + if tools_ip.is_valid_ip(ip) then return true end @@ -49,7 +50,7 @@ end local function validate_ip_or_cidr(ip_or_cidr) - if utils.is_valid_ip_or_cidr(ip_or_cidr) then + if tools_ip.is_valid_ip_or_cidr(ip_or_cidr) then return true end @@ -58,7 +59,7 @@ end local function validate_ip_or_cidr_v4(ip_or_cidr_v4) - if utils.is_valid_ip_or_cidr_v4(ip_or_cidr_v4) then + if tools_ip.is_valid_ip_or_cidr_v4(ip_or_cidr_v4) then return true end @@ -150,7 +151,7 @@ end local function validate_sni(host) - local res, err_or_port = utils.normalize_ip(host) + local res, err_or_port = tools_ip.normalize_ip(host) if type(err_or_port) == "string" and err_or_port ~= "invalid port number" then return nil, "invalid value: " .. host end @@ -183,7 +184,7 @@ local function validate_wildcard_host(host) host = mock_host end - local res, err_or_port = utils.normalize_ip(host) + local res, err_or_port = tools_ip.normalize_ip(host) if type(err_or_port) == "string" and err_or_port ~= "invalid port number" then return nil, "invalid value: " .. host end diff --git a/kong/pdk/ip.lua b/kong/pdk/ip.lua index 0e406ecbb08e..9bb7dc2a675e 100644 --- a/kong/pdk/ip.lua +++ b/kong/pdk/ip.lua @@ -12,7 +12,7 @@ -- See the [documentation on trusted IPs](https://docs.konghq.com/gateway/latest/reference/configuration/#trusted_ips). -- -- @module kong.ip -local utils = require "kong.tools.utils" +local is_valid_ip_or_cidr = require("kong.tools.ip").is_valid_ip_or_cidr local ipmatcher = require "resty.ipmatcher" --- @@ -47,7 +47,7 @@ local function new(self) for i = 1, n_ips do local address = ips[i] - if utils.is_valid_ip_or_cidr(address) then + if is_valid_ip_or_cidr(address) then trusted_ips[idx] = address idx = idx + 1 diff --git a/kong/router/utils.lua b/kong/router/utils.lua index b5a90632f009..4cd32ed171e5 100644 --- a/kong/router/utils.lua +++ b/kong/router/utils.lua @@ -1,5 +1,5 @@ local constants = require("kong.constants") -local hostname_type = require("kong.tools.utils").hostname_type +local hostname_type = require("kong.tools.ip").hostname_type local normalize = require("kong.tools.uri").normalize diff --git a/kong/runloop/balancer/init.lua b/kong/runloop/balancer/init.lua index e3a3eae264b4..57331d804a20 100644 --- a/kong/runloop/balancer/init.lua +++ b/kong/runloop/balancer/init.lua @@ -1,5 +1,5 @@ local pl_tablex = require "pl.tablex" -local utils = require "kong.tools.utils" +local hostname_type = require("kong.tools.ip").hostname_type local hooks = require "kong.hooks" local recreate_request = require("ngx.balancer").recreate_request local uuid = require("kong.tools.uuid").uuid @@ -413,7 +413,7 @@ local function post_health(upstream, hostname, ip, port, is_healthy) end local ok, err - if ip and (utils.hostname_type(ip) ~= "name") then + if ip and (hostname_type(ip) ~= "name") then ok, err = healthchecker:set_target_status(ip, port, hostname, is_healthy) else ok, err = healthchecker:set_all_target_statuses_for_hostname(hostname, port, is_healthy) diff --git a/spec/01-unit/05-utils_spec.lua b/spec/01-unit/05-utils_spec.lua index 34c20289688b..c3811e373628 100644 --- a/spec/01-unit/05-utils_spec.lua +++ b/spec/01-unit/05-utils_spec.lua @@ -1,6 +1,7 @@ local utils = require "kong.tools.utils" local kong_table = require "kong.tools.table" local pl_path = require "pl.path" +local tools_ip = require "kong.tools.ip" describe("Utils", function() @@ -524,47 +525,47 @@ describe("Utils", function() describe("hostname_type", function() -- no check on "name" type as anything not ipv4 and not ipv6 will be labelled as 'name' anyway it("checks valid IPv4 address types", function() - assert.are.same("ipv4", utils.hostname_type("123.123.123.123")) - assert.are.same("ipv4", utils.hostname_type("1.2.3.4")) - assert.are.same("ipv4", utils.hostname_type("1.2.3.4:80")) + assert.are.same("ipv4", tools_ip.hostname_type("123.123.123.123")) + assert.are.same("ipv4", tools_ip.hostname_type("1.2.3.4")) + assert.are.same("ipv4", tools_ip.hostname_type("1.2.3.4:80")) end) it("checks valid IPv6 address types", function() - assert.are.same("ipv6", utils.hostname_type("::1")) - assert.are.same("ipv6", utils.hostname_type("2345::6789")) - assert.are.same("ipv6", utils.hostname_type("0001:0001:0001:0001:0001:0001:0001:0001")) - assert.are.same("ipv6", utils.hostname_type("[2345::6789]:80")) + assert.are.same("ipv6", tools_ip.hostname_type("::1")) + assert.are.same("ipv6", tools_ip.hostname_type("2345::6789")) + assert.are.same("ipv6", tools_ip.hostname_type("0001:0001:0001:0001:0001:0001:0001:0001")) + assert.are.same("ipv6", tools_ip.hostname_type("[2345::6789]:80")) end) end) describe("parsing", function() it("normalizes IPv4 address types", function() - assert.are.same({"123.123.123.123"}, {utils.normalize_ipv4("123.123.123.123")}) - assert.are.same({"123.123.123.123", 80}, {utils.normalize_ipv4("123.123.123.123:80")}) - assert.are.same({"1.1.1.1"}, {utils.normalize_ipv4("1.1.1.1")}) - assert.are.same({"1.1.1.1", 80}, {utils.normalize_ipv4("001.001.001.001:00080")}) + assert.are.same({"123.123.123.123"}, {tools_ip.normalize_ipv4("123.123.123.123")}) + assert.are.same({"123.123.123.123", 80}, {tools_ip.normalize_ipv4("123.123.123.123:80")}) + assert.are.same({"1.1.1.1"}, {tools_ip.normalize_ipv4("1.1.1.1")}) + assert.are.same({"1.1.1.1", 80}, {tools_ip.normalize_ipv4("001.001.001.001:00080")}) end) it("fails normalizing bad IPv4 address types", function() - assert.is_nil(utils.normalize_ipv4("123.123:80")) - assert.is_nil(utils.normalize_ipv4("123.123.123.999")) - assert.is_nil(utils.normalize_ipv4("123.123.123.123:80a")) - assert.is_nil(utils.normalize_ipv4("123.123.123.123.123:80")) - assert.is_nil(utils.normalize_ipv4("localhost:80")) - assert.is_nil(utils.normalize_ipv4("[::1]:80")) - assert.is_nil(utils.normalize_ipv4("123.123.123.123:99999")) + assert.is_nil(tools_ip.normalize_ipv4("123.123:80")) + assert.is_nil(tools_ip.normalize_ipv4("123.123.123.999")) + assert.is_nil(tools_ip.normalize_ipv4("123.123.123.123:80a")) + assert.is_nil(tools_ip.normalize_ipv4("123.123.123.123.123:80")) + assert.is_nil(tools_ip.normalize_ipv4("localhost:80")) + assert.is_nil(tools_ip.normalize_ipv4("[::1]:80")) + assert.is_nil(tools_ip.normalize_ipv4("123.123.123.123:99999")) end) it("normalizes IPv6 address types", function() - assert.are.same({"0000:0000:0000:0000:0000:0000:0000:0001"}, {utils.normalize_ipv6("::1")}) - assert.are.same({"0000:0000:0000:0000:0000:0000:0000:0001"}, {utils.normalize_ipv6("[::1]")}) - assert.are.same({"0000:0000:0000:0000:0000:0000:0000:0001", 80}, {utils.normalize_ipv6("[::1]:80")}) - assert.are.same({"0000:0000:0000:0000:0000:0000:0000:0001", 80}, {utils.normalize_ipv6("[0000:0000:0000:0000:0000:0000:0000:0001]:80")}) + assert.are.same({"0000:0000:0000:0000:0000:0000:0000:0001"}, {tools_ip.normalize_ipv6("::1")}) + assert.are.same({"0000:0000:0000:0000:0000:0000:0000:0001"}, {tools_ip.normalize_ipv6("[::1]")}) + assert.are.same({"0000:0000:0000:0000:0000:0000:0000:0001", 80}, {tools_ip.normalize_ipv6("[::1]:80")}) + assert.are.same({"0000:0000:0000:0000:0000:0000:0000:0001", 80}, {tools_ip.normalize_ipv6("[0000:0000:0000:0000:0000:0000:0000:0001]:80")}) end) it("fails normalizing bad IPv6 address types", function() - assert.is_nil(utils.normalize_ipv6("123.123.123.123")) - assert.is_nil(utils.normalize_ipv6("localhost:80")) - assert.is_nil(utils.normalize_ipv6("::x")) - assert.is_nil(utils.normalize_ipv6("[::x]:80")) - assert.is_nil(utils.normalize_ipv6("[::1]:80a")) - assert.is_nil(utils.normalize_ipv6("1")) - assert.is_nil(utils.normalize_ipv6("[::1]:99999")) + assert.is_nil(tools_ip.normalize_ipv6("123.123.123.123")) + assert.is_nil(tools_ip.normalize_ipv6("localhost:80")) + assert.is_nil(tools_ip.normalize_ipv6("::x")) + assert.is_nil(tools_ip.normalize_ipv6("[::x]:80")) + assert.is_nil(tools_ip.normalize_ipv6("[::1]:80a")) + assert.is_nil(tools_ip.normalize_ipv6("1")) + assert.is_nil(tools_ip.normalize_ipv6("[::1]:99999")) end) it("validates hostnames", function() local valids = {"hello.com", "hello.fr", "test.hello.com", "1991.io", "hello.COM", @@ -582,66 +583,66 @@ describe("Utils", function() "hello..example.com", "hello-.example.com", } for _, name in ipairs(valids) do - assert.are.same(name, (utils.check_hostname(name))) + assert.are.same(name, (tools_ip.check_hostname(name))) end for _, name in ipairs(valids) do - assert.are.same({ [1] = name, [2] = 80}, { utils.check_hostname(name .. ":80")}) + assert.are.same({ [1] = name, [2] = 80}, { tools_ip.check_hostname(name .. ":80")}) end for _, name in ipairs(valids) do - assert.is_nil((utils.check_hostname(name .. ":xx"))) - assert.is_nil((utils.check_hostname(name .. ":99999"))) + assert.is_nil((tools_ip.check_hostname(name .. ":xx"))) + assert.is_nil((tools_ip.check_hostname(name .. ":99999"))) end for _, name in ipairs(invalids) do - assert.is_nil((utils.check_hostname(name))) - assert.is_nil((utils.check_hostname(name .. ":80"))) + assert.is_nil((tools_ip.check_hostname(name))) + assert.is_nil((tools_ip.check_hostname(name .. ":80"))) end end) it("validates addresses", function() - assert.are.same({host = "1.2.3.4", type = "ipv4", port = 80}, utils.normalize_ip("1.2.3.4:80")) - assert.are.same({host = "1.2.3.4", type = "ipv4", port = nil}, utils.normalize_ip("1.2.3.4")) - assert.are.same({host = "0000:0000:0000:0000:0000:0000:0000:0001", type = "ipv6", port = 80}, utils.normalize_ip("[::1]:80")) - assert.are.same({host = "0000:0000:0000:0000:0000:0000:0000:0001", type = "ipv6", port = nil}, utils.normalize_ip("::1")) - assert.are.same({host = "localhost", type = "name", port = 80}, utils.normalize_ip("localhost:80")) - assert.are.same({host = "mashape.test", type = "name", port = nil}, utils.normalize_ip("mashape.test")) - - assert.is_nil((utils.normalize_ip("1.2.3.4:8x0"))) - assert.is_nil((utils.normalize_ip("1.2.3.400"))) - assert.is_nil((utils.normalize_ip("[::1]:8x0"))) - assert.is_nil((utils.normalize_ip(":x:1"))) - assert.is_nil((utils.normalize_ip("localhost:8x0"))) - assert.is_nil((utils.normalize_ip("mashape..test"))) + assert.are.same({host = "1.2.3.4", type = "ipv4", port = 80}, tools_ip.normalize_ip("1.2.3.4:80")) + assert.are.same({host = "1.2.3.4", type = "ipv4", port = nil}, tools_ip.normalize_ip("1.2.3.4")) + assert.are.same({host = "0000:0000:0000:0000:0000:0000:0000:0001", type = "ipv6", port = 80}, tools_ip.normalize_ip("[::1]:80")) + assert.are.same({host = "0000:0000:0000:0000:0000:0000:0000:0001", type = "ipv6", port = nil}, tools_ip.normalize_ip("::1")) + assert.are.same({host = "localhost", type = "name", port = 80}, tools_ip.normalize_ip("localhost:80")) + assert.are.same({host = "mashape.test", type = "name", port = nil}, tools_ip.normalize_ip("mashape.test")) + + assert.is_nil((tools_ip.normalize_ip("1.2.3.4:8x0"))) + assert.is_nil((tools_ip.normalize_ip("1.2.3.400"))) + assert.is_nil((tools_ip.normalize_ip("[::1]:8x0"))) + assert.is_nil((tools_ip.normalize_ip(":x:1"))) + assert.is_nil((tools_ip.normalize_ip("localhost:8x0"))) + assert.is_nil((tools_ip.normalize_ip("mashape..test"))) end) end) describe("formatting", function() it("correctly formats addresses", function() - assert.are.equal("1.2.3.4", utils.format_host("1.2.3.4")) - assert.are.equal("1.2.3.4:80", utils.format_host("1.2.3.4", 80)) - assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]", utils.format_host("::1")) - assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]:80", utils.format_host("::1", 80)) - assert.are.equal("localhost", utils.format_host("localhost")) - assert.are.equal("mashape.test:80", utils.format_host("mashape.test", 80)) + assert.are.equal("1.2.3.4", tools_ip.format_host("1.2.3.4")) + assert.are.equal("1.2.3.4:80", tools_ip.format_host("1.2.3.4", 80)) + assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]", tools_ip.format_host("::1")) + assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]:80", tools_ip.format_host("::1", 80)) + assert.are.equal("localhost", tools_ip.format_host("localhost")) + assert.are.equal("mashape.test:80", tools_ip.format_host("mashape.test", 80)) -- passthrough (string) - assert.are.equal("1.2.3.4", utils.format_host(utils.normalize_ipv4("1.2.3.4"))) - assert.are.equal("1.2.3.4:80", utils.format_host(utils.normalize_ipv4("1.2.3.4:80"))) - assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]", utils.format_host(utils.normalize_ipv6("::1"))) - assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]:80", utils.format_host(utils.normalize_ipv6("[::1]:80"))) - assert.are.equal("localhost", utils.format_host(utils.check_hostname("localhost"))) - assert.are.equal("mashape.test:80", utils.format_host(utils.check_hostname("mashape.test:80"))) + assert.are.equal("1.2.3.4", tools_ip.format_host(tools_ip.normalize_ipv4("1.2.3.4"))) + assert.are.equal("1.2.3.4:80", tools_ip.format_host(tools_ip.normalize_ipv4("1.2.3.4:80"))) + assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]", tools_ip.format_host(tools_ip.normalize_ipv6("::1"))) + assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]:80", tools_ip.format_host(tools_ip.normalize_ipv6("[::1]:80"))) + assert.are.equal("localhost", tools_ip.format_host(tools_ip.check_hostname("localhost"))) + assert.are.equal("mashape.test:80", tools_ip.format_host(tools_ip.check_hostname("mashape.test:80"))) -- passthrough general (table) - assert.are.equal("1.2.3.4", utils.format_host(utils.normalize_ip("1.2.3.4"))) - assert.are.equal("1.2.3.4:80", utils.format_host(utils.normalize_ip("1.2.3.4:80"))) - assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]", utils.format_host(utils.normalize_ip("::1"))) - assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]:80", utils.format_host(utils.normalize_ip("[::1]:80"))) - assert.are.equal("localhost", utils.format_host(utils.normalize_ip("localhost"))) - assert.are.equal("mashape.test:80", utils.format_host(utils.normalize_ip("mashape.test:80"))) + assert.are.equal("1.2.3.4", tools_ip.format_host(tools_ip.normalize_ip("1.2.3.4"))) + assert.are.equal("1.2.3.4:80", tools_ip.format_host(tools_ip.normalize_ip("1.2.3.4:80"))) + assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]", tools_ip.format_host(tools_ip.normalize_ip("::1"))) + assert.are.equal("[0000:0000:0000:0000:0000:0000:0000:0001]:80", tools_ip.format_host(tools_ip.normalize_ip("[::1]:80"))) + assert.are.equal("localhost", tools_ip.format_host(tools_ip.normalize_ip("localhost"))) + assert.are.equal("mashape.test:80", tools_ip.format_host(tools_ip.normalize_ip("mashape.test:80"))) -- passthrough errors - local one, two = utils.format_host(utils.normalize_ipv4("1.2.3.4.5")) + local one, two = tools_ip.format_host(tools_ip.normalize_ipv4("1.2.3.4.5")) assert.are.equal("nilstring", type(one) .. type(two)) - local one, two = utils.format_host(utils.normalize_ipv6("not ipv6...")) + local one, two = tools_ip.format_host(tools_ip.normalize_ipv6("not ipv6...")) assert.are.equal("nilstring", type(one) .. type(two)) - local one, two = utils.format_host(utils.check_hostname("//bad..name\\:123")) + local one, two = tools_ip.format_host(tools_ip.check_hostname("//bad..name\\:123")) assert.are.equal("nilstring", type(one) .. type(two)) - local one, two = utils.format_host(utils.normalize_ip("m a s h a p e.test:80")) + local one, two = tools_ip.format_host(tools_ip.normalize_ip("m a s h a p e.test:80")) assert.are.equal("nilstring", type(one) .. type(two)) end) end) diff --git a/spec/fixtures/balancer_utils.lua b/spec/fixtures/balancer_utils.lua index fdac769de7e5..92e4b0c47b6f 100644 --- a/spec/fixtures/balancer_utils.lua +++ b/spec/fixtures/balancer_utils.lua @@ -1,7 +1,7 @@ local cjson = require "cjson" local declarative = require "kong.db.declarative" local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local format_host = require("kong.tools.ip").format_host local kong_table = require "kong.tools.table" local https_server = require "spec.fixtures.https_server" local uuid = require("kong.tools.uuid").uuid @@ -88,7 +88,7 @@ local function put_target_endpoint(upstream_id, host, port, endpoint) end local path = "/upstreams/" .. upstream_id .. "/targets/" - .. utils.format_host(host, port) + .. format_host(host, port) .. "/" .. endpoint local api_client = helpers.admin_client() local res, err = assert(api_client:put(prefix .. path, { @@ -317,7 +317,7 @@ do if host == "[::1]" then host = "[0000:0000:0000:0000:0000:0000:0000:0001]" end - req.target = req.target or utils.format_host(host, port) + req.target = req.target or format_host(host, port) req.weight = req.weight or 10 req.upstream = { id = upstream_id } local new_target = bp.targets:insert(req) @@ -329,7 +329,7 @@ do if host == "[::1]" then host = "[0000:0000:0000:0000:0000:0000:0000:0001]" end - req.target = req.target or utils.format_host(host, port) + req.target = req.target or format_host(host, port) req.weight = req.weight or 10 req.upstream = { id = upstream_id } bp.targets:update(req.id or req.target, req)