Skip to content

Commit

Permalink
refactor(tools/uuid): update UUID reference (#12952)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored and hanshuebner committed May 29, 2024
1 parent 1b87374 commit cd675c9
Show file tree
Hide file tree
Showing 74 changed files with 286 additions and 278 deletions.
11 changes: 6 additions & 5 deletions kong/api/endpoints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]

local Errors = require "kong.db.errors"
local utils = require "kong.tools.utils"
local uuid = require "kong.tools.uuid"
local arguments = require "kong.api.arguments"
local workspaces = require "kong.workspaces"
local app_helpers = require "lapis.application"
Expand All @@ -26,8 +26,9 @@ local type = type
local fmt = string.format
local concat = table.concat
local re_match = ngx.re.match
local split = utils.split
local insert = table.insert
local split = require("kong.tools.string").split
local get_default_exit_body = require("kong.tools.http").get_default_exit_body


-- error codes http status codes
Expand Down Expand Up @@ -147,7 +148,7 @@ local function handle_error(err_t)
return kong.response.exit(status, err_t)
end

return kong.response.exit(status, utils.get_default_exit_body(status, err_t))
return kong.response.exit(status, get_default_exit_body(status, err_t))
end

local function parse_boolean_query_arg(arg)
Expand Down Expand Up @@ -321,7 +322,7 @@ local function query_entity(context, self, db, schema, method)
end
end

if key.id and not utils.is_valid_uuid(key.id) then
if key.id and not uuid.is_valid_uuid(key.id) then
local endpoint_key = schema.endpoint_key
if endpoint_key then
local field = schema.fields[endpoint_key]
Expand Down Expand Up @@ -677,7 +678,7 @@ local function put_entity_endpoint(schema, foreign_schema, foreign_field_name, m
self.params[foreign_schema.name] = pk
else
associate = true
self.params[foreign_schema.name] = utils.uuid()
self.params[foreign_schema.name] = uuid.uuid()
end

else
Expand Down
6 changes: 3 additions & 3 deletions kong/api/routes/certificates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

local endpoints = require "kong.api.endpoints"
local arguments = require "kong.api.arguments"
local utils = require "kong.tools.utils"
local openssl_pkey = require "resty.openssl.pkey"
local uuid = require "kong.tools.uuid"


local ngx = ngx
Expand All @@ -23,7 +23,7 @@ local function prepare_params(self)
local id = unescape_uri(self.params.certificates)
local method = self.req.method
local name
if not utils.is_valid_uuid(id) then
if not uuid.is_valid_uuid(id) then
name = arguments.infer_value(id, kong.db.snis.schema.fields.name)

local sni, _, err_t = kong.db.snis:select_by_name(name)
Expand All @@ -39,7 +39,7 @@ local function prepare_params(self)
return kong.response.exit(404, { message = "SNI not found" })
end

id = utils.uuid()
id = uuid.uuid()
end
end

Expand Down
6 changes: 3 additions & 3 deletions kong/api/routes/upstreams.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]

local endpoints = require "kong.api.endpoints"
local utils = require "kong.tools.utils"
local uuid = require "kong.tools.uuid"


local kong = kong
Expand All @@ -28,7 +28,7 @@ local function set_target_health(self, db, is_healthy)
end

local target
if utils.is_valid_uuid(unescape_uri(self.params.targets)) then
if uuid.is_valid_uuid(unescape_uri(self.params.targets)) then
target, _, err_t = endpoints.select_entity(self, db, db.targets.schema)

else
Expand Down Expand Up @@ -97,7 +97,7 @@ local function target_endpoint(self, db, callback)
end

local target
if utils.is_valid_uuid(unescape_uri(self.params.targets)) then
if uuid.is_valid_uuid(unescape_uri(self.params.targets)) then
target, _, err_t = endpoints.select_entity(self, db, db.targets.schema)

else
Expand Down
4 changes: 2 additions & 2 deletions kong/cluster_events/strategies/postgres.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-- at https://konghq.com/enterprisesoftwarelicense/.
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]

local utils = require "kong.tools.utils"
local uuid = require "kong.tools.uuid"
local new_tab = require "table.new"


Expand Down Expand Up @@ -104,7 +104,7 @@ function _M:insert(node_id, channel, at, data, delay)
nbf = "NULL"
end

local pg_id = self.connector:escape_literal(utils.uuid())
local pg_id = self.connector:escape_literal(uuid.uuid())
local pg_node_id = self.connector:escape_literal(node_id)
local pg_channel = self.connector:escape_literal(channel)
local pg_data = self.connector:escape_literal(data)
Expand Down
4 changes: 2 additions & 2 deletions kong/db/dao/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

local cjson = require "cjson"
local iteration = require "kong.db.iteration"
local utils = require "kong.tools.utils"
local kong_table = require "kong.tools.table"
local defaults = require "kong.db.strategies.connector".defaults
local hooks = require "kong.hooks"
local workspaces = require "kong.workspaces"
local new_tab = require "table.new"
local DAO_MAX_TTL = require("kong.constants").DATABASE.DAO_MAX_TTL
local get_request_id = require("kong.tracing.request_id").get
local is_valid_uuid = require("kong.tools.uuid").is_valid_uuid

local setmetatable = setmetatable
local tostring = tostring
Expand Down Expand Up @@ -182,7 +182,7 @@ local function validate_options_value(self, options)

if options.workspace then
if type(options.workspace) == "string" then
if not utils.is_valid_uuid(options.workspace) then
if not is_valid_uuid(options.workspace) then
local ws = kong.db.workspaces:select_by_name(options.workspace)
if ws then
options.workspace = ws.id
Expand Down
4 changes: 2 additions & 2 deletions kong/db/errors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local pl_pretty = require("pl.pretty").write
local pl_keys = require("pl.tablex").keys
local nkeys = require("table.nkeys")
local table_isarray = require("table.isarray")
local utils = require("kong.tools.utils")
local uuid = require("kong.tools.uuid")


local type = type
Expand Down Expand Up @@ -797,7 +797,7 @@ do
---@return string|nil
local function validate_id(id)
return (type(id) == "string"
and utils.is_valid_uuid(id)
and uuid.is_valid_uuid(id)
and id)
or nil
end
Expand Down
4 changes: 2 additions & 2 deletions kong/db/migrations/core/013_220_to_230.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
-- at https://konghq.com/enterprisesoftwarelicense/.
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]

local utils = require("kong.tools.utils")
local uuid = require("kong.tools.uuid")


local CLUSTER_ID = utils.uuid()
local CLUSTER_ID = uuid.uuid()


return {
Expand Down
4 changes: 2 additions & 2 deletions kong/db/schema/others/declarative_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]

local uuid = require("resty.jit-uuid")
local utils = require("kong.tools.utils")
local kong_table = require("kong.tools.table")
local Errors = require("kong.db.errors")
local Entity = require("kong.db.schema.entity")
Expand All @@ -16,6 +15,7 @@ local plugin_loader = require("kong.db.schema.plugin_loader")
local vault_loader = require("kong.db.schema.vault_loader")
local schema_topological_sort = require("kong.db.schema.topological_sort")
local typedefs = require("kong.db.schema.typedefs")
local utils_uuid = require("kong.tools.uuid").uuid


local null = ngx.null
Expand Down Expand Up @@ -666,7 +666,7 @@ local function populate_ids_for_validation(input, known_entities, parent_entity,
if key then
item[pk_name] = generate_uuid(schema.name, key)
else
item[pk_name] = utils.uuid()
item[pk_name] = utils_uuid()
end
end

Expand Down
3 changes: 2 additions & 1 deletion kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ local wasm = require "kong.runloop.wasm"
local reports = require "kong.reports"
local pl_file = require "pl.file"
local req_dyn_hook = require "kong.dynamic_hook"
local uuid = require("kong.tools.uuid").uuid


local internal_proxies = require "kong.enterprise_edition.proxies"
Expand Down Expand Up @@ -848,7 +849,7 @@ function Kong.init()
end

if config.request_debug and config.role ~= "control_plane" and is_http_module then
local token = config.request_debug_token or utils.uuid()
local token = config.request_debug_token or uuid()

local request_debug_token_file = pl_path.join(config.prefix,
constants.REQUEST_DEBUG_TOKEN_FILE)
Expand Down
9 changes: 5 additions & 4 deletions kong/pdk/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
-- @module kong.client


local utils = require "kong.tools.utils"
local phase_checker = require "kong.pdk.private.phases"
local consumer_group_helpers = require "kong.enterprise_edition.consumer_groups_helpers"
local get_groups_by_consumer = consumer_group_helpers.get_groups_by_consumer
local is_valid_uuid = require("kong.tools.uuid").is_valid_uuid
local check_https = require("kong.tools.http").check_https


local ngx = ngx
Expand Down Expand Up @@ -204,11 +205,11 @@ local function new(self)
error("consumer_id must be a string", 2)
end

if not utils.is_valid_uuid(consumer_id) and not search_by_username then
if not is_valid_uuid(consumer_id) and not search_by_username then
error("cannot load a consumer with an id that is not a uuid", 2)
end

if utils.is_valid_uuid(consumer_id) then
if is_valid_uuid(consumer_id) then
local result, err = kong.db.consumers:select({ id = consumer_id })

if result then
Expand Down Expand Up @@ -445,7 +446,7 @@ local function new(self)

if ngx.config.subsystem == "http" then
local is_trusted = self.ip.is_trusted(self.client.get_ip())
local is_https, err = utils.check_https(is_trusted, allow_terminated)
local is_https, err = check_https(is_trusted, allow_terminated)
if err then
return nil, err
end
Expand Down
9 changes: 5 additions & 4 deletions kong/pdk/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
--
-- @module kong.node

local utils = require "kong.tools.utils"
local ffi = require "ffi"
local private_node = require "kong.pdk.private.node"
local uuid = require("kong.tools.uuid").uuid
local bytes_to_str = require("kong.tools.string").bytes_to_str


local floor = math.floor
Expand Down Expand Up @@ -53,7 +54,7 @@ local function convert_bytes(bytes, unit, scale)
return floor(bytes)
end

return utils.bytes_to_str(bytes, unit, scale)
return bytes_to_str(bytes, unit, scale)
end


Expand All @@ -80,7 +81,7 @@ local function new(self)

local shm = ngx.shared.kong

local ok, err = shm:safe_add(NODE_ID_KEY, utils.uuid())
local ok, err = shm:safe_add(NODE_ID_KEY, uuid())
if not ok and err ~= "exists" then
error("failed to set 'node_id' in shm: " .. err)
end
Expand Down Expand Up @@ -167,7 +168,7 @@ local function new(self)
unit = unit or "b"
scale = scale or 2

local pok, perr = pcall(utils.bytes_to_str, 0, unit, scale)
local pok, perr = pcall(bytes_to_str, 0, unit, scale)
if not pok then
error(perr, 2)
end
Expand Down
8 changes: 4 additions & 4 deletions kong/pdk/private/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]

local log = require "kong.cmd.utils.log"
local utils = require "kong.tools.utils"
local uuid = require "kong.tools.uuid"
local pl_file = require "pl.file"
local pl_path = require "pl.path"
local pl_dir = require "pl.dir"
Expand Down Expand Up @@ -38,15 +38,15 @@ local function initialize_node_id(prefix)
return nil, fmt("failed to access file %s: %s", filename, err)
end

if not utils.is_valid_uuid(id) then
if not uuid.is_valid_uuid(id) then
log.debug("file %s contains invalid uuid: %s", filename, id)
-- set false to override it when it contains an invalid uuid.
file_exists = false
end
end

if not file_exists then
local id = utils.uuid()
local id = uuid.uuid()
log.debug("persisting node_id (%s) to %s", id, filename)

local ok, write_err = pl_file.write(filename, id)
Expand Down Expand Up @@ -96,7 +96,7 @@ local function load_node_id(prefix)
return nil, fmt("failed to access file %s: %s", filename, read_err)
end

if not utils.is_valid_uuid(id) then
if not uuid.is_valid_uuid(id) then
return nil, fmt("file %s contains invalid uuid: %q", filename, id)
end

Expand Down
8 changes: 4 additions & 4 deletions kong/plugins/acl/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]

local endpoints = require "kong.api.endpoints"
local utils = require "kong.tools.utils"
local uuid = require "kong.tools.uuid"


local ngx = ngx
Expand All @@ -20,10 +20,10 @@ return {
schema = kong.db.acls.schema,
before = function(self, db, helpers)
local group = unescape_uri(self.params.acls)
if not utils.is_valid_uuid(group) then
if not uuid.is_valid_uuid(group) then
local consumer_id = unescape_uri(self.params.consumers)

if not utils.is_valid_uuid(consumer_id) then
if not uuid.is_valid_uuid(consumer_id) then
local consumer, _, err_t = endpoints.select_entity(self, db, db.consumers.schema)
if err_t then
return endpoints.handle_error(err_t)
Expand All @@ -49,7 +49,7 @@ return {
return kong.response.error(404)
end

self.params.acls = utils.uuid()
self.params.acls = uuid.uuid()
end

self.params.group = group
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/correlation-id/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]

-- Copyright (C) Kong Inc.
local uuid = require "kong.tools.utils".uuid
local uuid = require "kong.tools.uuid".uuid
local kong_meta = require "kong.meta"


Expand Down
3 changes: 2 additions & 1 deletion kong/runloop/balancer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local pl_tablex = require "pl.tablex"
local utils = require "kong.tools.utils"
local hooks = require "kong.hooks"
local recreate_request = require("ngx.balancer").recreate_request
local uuid = require("kong.tools.uuid").uuid

local healthcheckers = require "kong.runloop.balancer.healthcheckers"
local balancers = require "kong.runloop.balancer.balancers"
Expand Down Expand Up @@ -152,7 +153,7 @@ local function get_value_to_hash(upstream, ctx)
ctx = ngx.ctx
end

identifier = utils.uuid()
identifier = uuid()

ctx.balancer_data.hash_cookie = {
key = upstream.hash_on_cookie,
Expand Down
Loading

0 comments on commit cd675c9

Please sign in to comment.