From aae1815213790bb0bd53e2cf0aaceba50314c3a3 Mon Sep 17 00:00:00 2001 From: Chrono Date: Mon, 27 May 2024 19:08:50 +0800 Subject: [PATCH] refactor(tools/uuid): update UUID reference (#12952) --- kong/api/endpoints.lua | 11 +++--- kong/api/routes/certificates.lua | 6 ++-- kong/api/routes/upstreams.lua | 6 ++-- kong/cluster_events/strategies/postgres.lua | 4 +-- kong/db/dao/init.lua | 4 +-- kong/db/errors.lua | 4 +-- kong/db/migrations/core/013_220_to_230.lua | 4 +-- kong/db/schema/others/declarative_config.lua | 4 +-- kong/init.lua | 3 +- kong/pdk/client.lua | 9 ++--- kong/pdk/node.lua | 9 ++--- kong/pdk/private/node.lua | 8 ++--- kong/plugins/acl/api.lua | 8 ++--- kong/plugins/correlation-id/handler.lua | 2 +- kong/runloop/balancer/init.lua | 3 +- kong/runloop/handler.lua | 10 +++--- kong/runloop/plugins_iterator.lua | 9 ++--- kong/runloop/wasm.lua | 4 +-- kong/tools/utils.lua | 6 ++-- .../01-db/01-schema/07-plugins_spec.lua | 22 ++++++------ .../01-db/01-schema/08-targets_spec.lua | 4 +-- .../11-declarative_config/03-flatten_spec.lua | 4 +-- .../04-on-the-fly-migration_spec.lua | 4 +-- spec/01-unit/01-db/01-schema/11-snis_spec.lua | 4 +-- spec/01-unit/05-utils_spec.lua | 1 + spec/01-unit/08-router_spec.lua | 2 +- spec/01-unit/09-balancer/01-generic_spec.lua | 4 +-- .../09-balancer/02-least_connections_spec.lua | 4 +-- .../03-consistent_hashing_spec.lua | 4 +-- .../09-balancer/04-round_robin_spec.lua | 4 +-- .../05-worker_consistency_spec.lua | 3 +- spec/01-unit/09-balancer/06-latency_spec.lua | 4 +-- spec/01-unit/14-dns_spec.lua | 4 +-- spec/01-unit/27-queue_spec.lua | 6 ++-- .../03-db/02-db_core_entities_spec.lua | 30 ++++++++-------- spec/02-integration/03-db/07-tags_spec.lua | 2 +- .../03-db/10-db_unique_foreign_spec.lua | 10 +++--- spec/02-integration/03-db/14-dao_spec.lua | 4 +-- .../04-admin_api/03-consumers_routes_spec.lua | 10 +++--- .../04-admin_api/04-plugins_routes_spec.lua | 8 ++--- .../06-certificates_routes_spec.lua | 16 ++++----- .../04-admin_api/08-targets_routes_spec.lua | 6 ++-- .../04-admin_api/09-routes_routes_spec.lua | 32 ++++++++--------- .../04-admin_api/10-services_routes_spec.lua | 10 +++--- .../04-admin_api/15-off_spec.lua | 12 +++---- .../04-admin_api/17-foreign-entity_spec.lua | 10 +++--- .../04-admin_api/19-vaults_spec.lua | 6 ++-- .../05-proxy/04-plugins_triggering_spec.lua | 24 ++++++------- .../10-balancer/01-healthchecks_spec.lua | 4 +-- .../05-proxy/14-server_tokens_spec.lua | 4 +-- .../03-plugins_iterator_invalidation_spec.lua | 4 +-- .../09-hybrid_mode/01-sync_spec.lua | 6 ++-- .../09-hybrid_mode/09-config-compat_spec.lua | 36 +++++++++---------- .../09-node-id-persistence_spec.lua | 3 +- .../20-wasm/01-admin-api_spec.lua | 18 +++++----- spec/02-integration/20-wasm/02-db_spec.lua | 14 ++++---- .../03-plugins/03-http-log/02-schema_spec.lua | 4 +-- spec/03-plugins/05-syslog/01-log_spec.lua | 4 +-- .../03-plugins/09-key-auth/02-access_spec.lua | 4 +-- .../10-basic-auth/03-access_spec.lua | 4 +-- spec/03-plugins/16-jwt/03-access_spec.lua | 4 +-- spec/03-plugins/18-acl/01-api_spec.lua | 6 ++-- .../19-hmac-auth/03-access_spec.lua | 4 +-- .../20-ldap-auth/01-access_spec.lua | 4 +-- .../23-rate-limiting/02-policies_spec.lua | 2 +- .../06-shorthand_fields_spec.lua | 4 +-- .../02-policies_spec.lua | 2 +- .../06-shorthand_fields_spec.lua | 4 +-- spec/03-plugins/25-oauth2/01-schema_spec.lua | 14 ++++---- spec/03-plugins/25-oauth2/03-access_spec.lua | 4 +-- .../29-acme/07-shorthand_fields_spec.lua | 4 +-- .../01-access_spec.lua | 6 ++-- spec/fixtures/balancer_utils.lua | 9 ++--- spec/helpers.lua | 6 ++-- 74 files changed, 277 insertions(+), 269 deletions(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index eb995a357b76..3129fe6ddbe7 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -1,5 +1,5 @@ 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" @@ -17,7 +17,8 @@ local type = type local fmt = string.format local concat = table.concat local re_match = ngx.re.match -local split = utils.split +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 @@ -132,7 +133,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 @@ -241,7 +242,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] @@ -526,7 +527,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 diff --git a/kong/api/routes/certificates.lua b/kong/api/routes/certificates.lua index d0224f67aac6..7bdf6df80175 100644 --- a/kong/api/routes/certificates.lua +++ b/kong/api/routes/certificates.lua @@ -1,6 +1,6 @@ local endpoints = require "kong.api.endpoints" local arguments = require "kong.api.arguments" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local ngx = ngx @@ -15,7 +15,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) @@ -31,7 +31,7 @@ local function prepare_params(self) return kong.response.exit(404, { message = "SNI not found" }) end - id = utils.uuid() + id = uuid.uuid() end end diff --git a/kong/api/routes/upstreams.lua b/kong/api/routes/upstreams.lua index 83393a24cde1..614bef1721dc 100644 --- a/kong/api/routes/upstreams.lua +++ b/kong/api/routes/upstreams.lua @@ -1,5 +1,5 @@ local endpoints = require "kong.api.endpoints" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local kong = kong @@ -21,7 +21,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 @@ -90,7 +90,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 diff --git a/kong/cluster_events/strategies/postgres.lua b/kong/cluster_events/strategies/postgres.lua index 3399f49bb404..1658a314298b 100644 --- a/kong/cluster_events/strategies/postgres.lua +++ b/kong/cluster_events/strategies/postgres.lua @@ -1,4 +1,4 @@ -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local new_tab = require "table.new" @@ -97,7 +97,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) diff --git a/kong/db/dao/init.lua b/kong/db/dao/init.lua index e886b9f64dca..f84801c85a1e 100644 --- a/kong/db/dao/init.lua +++ b/kong/db/dao/init.lua @@ -1,12 +1,12 @@ 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 is_valid_uuid = require("kong.tools.uuid").is_valid_uuid local setmetatable = setmetatable local tostring = tostring @@ -174,7 +174,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 diff --git a/kong/db/errors.lua b/kong/db/errors.lua index 67276bf41b2b..a1f96cccd1bf 100644 --- a/kong/db/errors.lua +++ b/kong/db/errors.lua @@ -2,7 +2,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 @@ -757,7 +757,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 diff --git a/kong/db/migrations/core/013_220_to_230.lua b/kong/db/migrations/core/013_220_to_230.lua index 14f837d9c7be..4931865034ab 100644 --- a/kong/db/migrations/core/013_220_to_230.lua +++ b/kong/db/migrations/core/013_220_to_230.lua @@ -1,7 +1,7 @@ -local utils = require("kong.tools.utils") +local uuid = require("kong.tools.uuid") -local CLUSTER_ID = utils.uuid() +local CLUSTER_ID = uuid.uuid() return { diff --git a/kong/db/schema/others/declarative_config.lua b/kong/db/schema/others/declarative_config.lua index 48c8704c44d5..c6b9ede1c3ab 100644 --- a/kong/db/schema/others/declarative_config.lua +++ b/kong/db/schema/others/declarative_config.lua @@ -1,5 +1,4 @@ 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") @@ -8,6 +7,7 @@ local constants = require("kong.constants") 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 utils_uuid = require("kong.tools.uuid").uuid local null = ngx.null @@ -649,7 +649,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 diff --git a/kong/init.lua b/kong/init.lua index 225d6683174c..1378c1e91fb3 100644 --- a/kong/init.lua +++ b/kong/init.lua @@ -96,6 +96,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 kong = kong @@ -767,7 +768,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) diff --git a/kong/pdk/client.lua b/kong/pdk/client.lua index 9f74620c5a24..01592f42236b 100644 --- a/kong/pdk/client.lua +++ b/kong/pdk/client.lua @@ -8,8 +8,9 @@ -- @module kong.client -local utils = require "kong.tools.utils" local phase_checker = require "kong.pdk.private.phases" +local is_valid_uuid = require("kong.tools.uuid").is_valid_uuid +local check_https = require("kong.tools.http").check_https local ngx = ngx @@ -187,11 +188,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 @@ -289,7 +290,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 diff --git a/kong/pdk/node.lua b/kong/pdk/node.lua index abb338fa8fd3..9302c17cde1a 100644 --- a/kong/pdk/node.lua +++ b/kong/pdk/node.lua @@ -2,9 +2,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 @@ -46,7 +47,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 @@ -73,7 +74,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 @@ -160,7 +161,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 diff --git a/kong/pdk/private/node.lua b/kong/pdk/private/node.lua index ed299c999c3d..26441ed47807 100644 --- a/kong/pdk/private/node.lua +++ b/kong/pdk/private/node.lua @@ -1,5 +1,5 @@ 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" @@ -31,7 +31,7 @@ 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 @@ -39,7 +39,7 @@ local function initialize_node_id(prefix) 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) @@ -89,7 +89,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 diff --git a/kong/plugins/acl/api.lua b/kong/plugins/acl/api.lua index 95586593bd31..c6c6dd48d9aa 100644 --- a/kong/plugins/acl/api.lua +++ b/kong/plugins/acl/api.lua @@ -1,5 +1,5 @@ local endpoints = require "kong.api.endpoints" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local ngx = ngx @@ -13,10 +13,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) @@ -42,7 +42,7 @@ return { return kong.response.error(404) end - self.params.acls = utils.uuid() + self.params.acls = uuid.uuid() end self.params.group = group diff --git a/kong/plugins/correlation-id/handler.lua b/kong/plugins/correlation-id/handler.lua index b7d917dde305..5f1f82b9fdef 100644 --- a/kong/plugins/correlation-id/handler.lua +++ b/kong/plugins/correlation-id/handler.lua @@ -1,5 +1,5 @@ -- Copyright (C) Kong Inc. -local uuid = require "kong.tools.utils".uuid +local uuid = require "kong.tools.uuid".uuid local kong_meta = require "kong.meta" diff --git a/kong/runloop/balancer/init.lua b/kong/runloop/balancer/init.lua index 7515cfc1c875..0e8268323fdf 100644 --- a/kong/runloop/balancer/init.lua +++ b/kong/runloop/balancer/init.lua @@ -2,6 +2,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" @@ -145,7 +146,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, diff --git a/kong/runloop/handler.lua b/kong/runloop/handler.lua index b743e3241717..1f3210d2a889 100644 --- a/kong/runloop/handler.lua +++ b/kong/runloop/handler.lua @@ -1,7 +1,6 @@ -- Kong runloop local meta = require "kong.meta" -local utils = require "kong.tools.utils" local Router = require "kong.router" local balancer = require "kong.runloop.balancer" local events = require "kong.runloop.events" @@ -50,6 +49,7 @@ local http_version = ngx.req.http_version local request_id_get = request_id.get local escape = require("kong.tools.uri").escape local encode = require("string.buffer").encode +local uuid = require("kong.tools.uuid").uuid local req_dyn_hook_run_hook = req_dyn_hook.run_hook @@ -226,7 +226,7 @@ end -- or an error happened). -- @returns error message as a second return value in case of failure/error local function rebuild(name, callback, version, opts) - local current_version, err = kong.core_cache:get(name .. ":version", TTL_ZERO, utils.uuid) + local current_version, err = kong.core_cache:get(name .. ":version", TTL_ZERO, uuid) if err then return nil, "failed to retrieve " .. name .. " version: " .. err end @@ -333,7 +333,7 @@ end local function get_router_version() - return kong.core_cache:get("router:version", TTL_ZERO, utils.uuid) + return kong.core_cache:get("router:version", TTL_ZERO, uuid) end @@ -533,7 +533,7 @@ end local function update_plugins_iterator() - local version, err = kong.core_cache:get("plugins_iterator:version", TTL_ZERO, utils.uuid) + local version, err = kong.core_cache:get("plugins_iterator:version", TTL_ZERO, uuid) if err then return nil, "failed to retrieve plugins iterator version: " .. err end @@ -621,7 +621,7 @@ end local reconfigure_handler do - local get_monotonic_ms = utils.get_updated_monotonic_ms + local get_monotonic_ms = require("kong.tools.time").get_updated_monotonic_ms local ngx_worker_id = ngx.worker.id local exiting = ngx.worker.exiting diff --git a/kong/runloop/plugins_iterator.lua b/kong/runloop/plugins_iterator.lua index 515d14a947eb..6fe558004035 100644 --- a/kong/runloop/plugins_iterator.lua +++ b/kong/runloop/plugins_iterator.lua @@ -1,6 +1,5 @@ local workspaces = require "kong.workspaces" local constants = require "kong.constants" -local utils = require "kong.tools.utils" local tablepool = require "tablepool" @@ -16,6 +15,8 @@ local ipairs = ipairs local format = string.format local fetch_table = tablepool.fetch local release_table = tablepool.release +local uuid = require("kong.tools.uuid").uuid +local get_updated_monotonic_ms = require("kong.tools.time").get_updated_monotonic_ms local TTL_ZERO = { ttl = 0 } @@ -433,9 +434,9 @@ local function configure(configurable, ctx) local name = plugin.name kong_global.set_namespaced_log(kong, plugin.name, ctx) - local start = utils.get_updated_monotonic_ms() + local start = get_updated_monotonic_ms() local ok, err = pcall(plugin.handler[CONFIGURE_PHASE], plugin.handler, configurable[name]) - local elapsed = utils.get_updated_monotonic_ms() - start + local elapsed = get_updated_monotonic_ms() - start kong_global.reset_log(kong, ctx) if not ok then @@ -514,7 +515,7 @@ function PluginsIterator.new(version) end if is_not_dbless and counter > 0 and counter % page_size == 0 and kong.core_cache then - local new_version, err = kong.core_cache:get("plugins_iterator:version", TTL_ZERO, utils.uuid) + local new_version, err = kong.core_cache:get("plugins_iterator:version", TTL_ZERO, uuid) if err then return nil, "failed to retrieve plugins iterator version: " .. err end diff --git a/kong/runloop/wasm.lua b/kong/runloop/wasm.lua index 8ea57e2042b8..af9bbc2cbae8 100644 --- a/kong/runloop/wasm.lua +++ b/kong/runloop/wasm.lua @@ -31,7 +31,7 @@ local _M = { ---@field config_schema kong.db.schema.json.schema_doc|nil -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local reports = require "kong.reports" local clear_tab = require "table.clear" local cjson = require "cjson.safe" @@ -81,7 +81,7 @@ local FILTER_META_SCHEMA = { -- ---@return string local function get_version() - return kong.core_cache:get(VERSION_KEY, TTL_ZERO, utils.uuid) + return kong.core_cache:get(VERSION_KEY, TTL_ZERO, uuid.uuid) end diff --git a/kong/tools/utils.lua b/kong/tools/utils.lua index c410454b6857..aa75282f202b 100644 --- a/kong/tools/utils.lua +++ b/kong/tools/utils.lua @@ -18,10 +18,12 @@ local _M = {} do local modules = { + -- [[ keep it here for compatibility "kong.tools.table", - "kong.tools.string", "kong.tools.uuid", - "kong.tools.rand", -- keep it here for compatibility + "kong.tools.rand", + -- ]] keep it here for compatibility + "kong.tools.string", "kong.tools.time", "kong.tools.ip", "kong.tools.http", diff --git a/spec/01-unit/01-db/01-schema/07-plugins_spec.lua b/spec/01-unit/01-db/01-schema/07-plugins_spec.lua index 1bfc1efcefab..4de064d3861d 100644 --- a/spec/01-unit/01-db/01-schema/07-plugins_spec.lua +++ b/spec/01-unit/01-db/01-schema/07-plugins_spec.lua @@ -1,7 +1,7 @@ require "spec.helpers" -- initializes 'kong' global for plugins local Entity = require "kong.db.schema.entity" local typedefs = require "kong.db.schema.typedefs" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local routes_definition = require "kong.db.schema.entities.routes" local services_definition = require "kong.db.schema.entities.services" local consumers_definition = require "kong.db.schema.entities.consumers" @@ -78,7 +78,7 @@ describe("plugins", function() -- Success local plugin = { name = "key-auth", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, config = { key_names = { "x-kong-key" } } @@ -91,7 +91,7 @@ describe("plugins", function() -- Failure plugin = { name = "rate-limiting", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, config = { second = "hello" } @@ -112,7 +112,7 @@ describe("plugins", function() -- Insert key-auth, whose config has some default values that should be set local plugin = { name = "key-auth", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, } plugin = Plugins:process_auto_fields(plugin) local ok = Plugins:validate(plugin) @@ -133,7 +133,7 @@ describe("plugins", function() -- Insert response-transformer, whose default config has no default values, and should be empty local plugin = { name = "response-transformer", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, } plugin = Plugins:process_auto_fields(plugin) local ok = Plugins:validate(plugin) @@ -182,7 +182,7 @@ describe("plugins", function() local ok, err = Plugins:validate(Plugins:process_auto_fields({ name = "with-no-route", - route = { id = utils.uuid() }, + route = { id = uuid.uuid() }, config = { string = "foo", } @@ -219,7 +219,7 @@ describe("plugins", function() local ok, err = Plugins:validate(Plugins:process_auto_fields({ name = "with-no-service", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, config = { string = "foo", } @@ -256,7 +256,7 @@ describe("plugins", function() local ok, err = Plugins:validate(Plugins:process_auto_fields({ name = "with-no-consumer", - consumer = { id = utils.uuid() }, + consumer = { id = uuid.uuid() }, config = { string = "foo", } @@ -279,21 +279,21 @@ describe("plugins", function() it("accepts a plugin if configured for route", function() assert(Plugins:validate(Plugins:process_auto_fields({ name = "key-auth", - route = { id = utils.uuid() }, + route = { id = uuid.uuid() }, }))) end) it("accepts a plugin if configured for service", function() assert(Plugins:validate(Plugins:process_auto_fields({ name = "key-auth", - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, }))) end) it("accepts a plugin if configured for consumer", function() assert(Plugins:validate(Plugins:process_auto_fields({ name = "rate-limiting", - consumer = { id = utils.uuid() }, + consumer = { id = uuid.uuid() }, config = { second = 1, } diff --git a/spec/01-unit/01-db/01-schema/08-targets_spec.lua b/spec/01-unit/01-db/01-schema/08-targets_spec.lua index fb08ade2a428..d791f119d13d 100644 --- a/spec/01-unit/01-db/01-schema/08-targets_spec.lua +++ b/spec/01-unit/01-db/01-schema/08-targets_spec.lua @@ -2,7 +2,7 @@ local Schema = require "kong.db.schema" local targets = require "kong.db.schema.entities.targets" local certificates = require "kong.db.schema.entities.certificates" local upstreams = require "kong.db.schema.entities.upstreams" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local function setup_global_env() _G.kong = _G.kong or {} @@ -32,7 +32,7 @@ describe("targets", function() setup_global_env() describe("targets.target", function() it("validates", function() - local upstream = { id = utils.uuid() } + local upstream = { id = uuid.uuid() } local targets = { "valid.name", "valid.name:8080", "12.34.56.78", "1.2.3.4:123" } for _, target in ipairs(targets) do local ok, err = validate({ target = target, upstream = upstream }) diff --git a/spec/01-unit/01-db/01-schema/11-declarative_config/03-flatten_spec.lua b/spec/01-unit/01-db/01-schema/11-declarative_config/03-flatten_spec.lua index 9bdba912e43a..a869822e847e 100644 --- a/spec/01-unit/01-db/01-schema/11-declarative_config/03-flatten_spec.lua +++ b/spec/01-unit/01-db/01-schema/11-declarative_config/03-flatten_spec.lua @@ -3,7 +3,7 @@ local helpers = require "spec.helpers" local lyaml = require "lyaml" local cjson = require "cjson" local tablex = require "pl.tablex" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local null = ngx.null @@ -48,7 +48,7 @@ local function idempotent(tbl, err) local function recurse_fields(t) helpers.deep_sort(t) for k,v in sortedpairs(t) do - if k == "id" and utils.is_valid_uuid(v) then + if k == "id" and uuid.is_valid_uuid(v) then t[k] = "UUID" end if k == "client_id" or k == "client_secret" or k == "access_token" then diff --git a/spec/01-unit/01-db/01-schema/11-declarative_config/04-on-the-fly-migration_spec.lua b/spec/01-unit/01-db/01-schema/11-declarative_config/04-on-the-fly-migration_spec.lua index 7ceb873ebe5f..52e47441f8c1 100644 --- a/spec/01-unit/01-db/01-schema/11-declarative_config/04-on-the-fly-migration_spec.lua +++ b/spec/01-unit/01-db/01-schema/11-declarative_config/04-on-the-fly-migration_spec.lua @@ -6,7 +6,7 @@ local null = ngx.null local helpers = require "spec.helpers" local tablex = require "pl.tablex" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local function sort_by_key(t) return function(a, b) @@ -48,7 +48,7 @@ local function idempotent(tbl, err) local function recurse_fields(t) helpers.deep_sort(t) for k,v in sortedpairs(t) do - if k == "id" and utils.is_valid_uuid(v) then + if k == "id" and uuid.is_valid_uuid(v) then t[k] = "UUID" end if k == "client_id" or k == "client_secret" or k == "access_token" then diff --git a/spec/01-unit/01-db/01-schema/11-snis_spec.lua b/spec/01-unit/01-db/01-schema/11-snis_spec.lua index a5fdfa05ccaa..e7dac570e885 100644 --- a/spec/01-unit/01-db/01-schema/11-snis_spec.lua +++ b/spec/01-unit/01-db/01-schema/11-snis_spec.lua @@ -1,7 +1,7 @@ local Schema = require "kong.db.schema" local snis = require "kong.db.schema.entities.snis" local certificates = require "kong.db.schema.entities.certificates" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" Schema.new(certificates) local Snis = assert(Schema.new(snis)) @@ -27,7 +27,7 @@ end describe("snis", function() - local certificate = { id = utils.uuid() } + local certificate = { id = uuid.uuid() } setup_global_env() diff --git a/spec/01-unit/05-utils_spec.lua b/spec/01-unit/05-utils_spec.lua index ea467264b0af..2a65ea7bc850 100644 --- a/spec/01-unit/05-utils_spec.lua +++ b/spec/01-unit/05-utils_spec.lua @@ -56,6 +56,7 @@ describe("Utils", function() end) describe("is_valid_uuid()", function() + local utils = require "kong.tools.uuid" it("validates UUIDs from jit-uuid", function() assert.True (utils.is_valid_uuid("cbb297c0-a956-486d-ad1d-f9b42df9465a")) assert.False(utils.is_valid_uuid("cbb297c0-a956486d-ad1d-f9b42df9465a")) diff --git a/spec/01-unit/08-router_spec.lua b/spec/01-unit/08-router_spec.lua index 025120392ecf..1b164904f4e2 100644 --- a/spec/01-unit/08-router_spec.lua +++ b/spec/01-unit/08-router_spec.lua @@ -1,6 +1,6 @@ local Router local path_handling_tests = require "spec.fixtures.router_path_handling_tests" -local uuid = require("kong.tools.utils").uuid +local uuid = require("kong.tools.uuid").uuid local get_expression = require("kong.router.transform").get_expression local deep_copy = require("kong.tools.table").deep_copy diff --git a/spec/01-unit/09-balancer/01-generic_spec.lua b/spec/01-unit/09-balancer/01-generic_spec.lua index 6d2c6c1f38ca..ec4c58f1c60c 100644 --- a/spec/01-unit/09-balancer/01-generic_spec.lua +++ b/spec/01-unit/09-balancer/01-generic_spec.lua @@ -7,9 +7,9 @@ local dnsA = function(...) return helpers.dnsA(client, ...) end local dnsExpire = helpers.dnsExpire local mocker = require "spec.fixtures.mocker" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local hc_defaults = { active = { diff --git a/spec/01-unit/09-balancer/02-least_connections_spec.lua b/spec/01-unit/09-balancer/02-least_connections_spec.lua index 3617070d4309..3db545dec093 100644 --- a/spec/01-unit/09-balancer/02-least_connections_spec.lua +++ b/spec/01-unit/09-balancer/02-least_connections_spec.lua @@ -1,9 +1,9 @@ local dns_utils = require "kong.resty.dns.utils" local mocker = require "spec.fixtures.mocker" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local client, balancers, targets diff --git a/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua b/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua index 3e7566755624..17f46f46fa5b 100644 --- a/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua +++ b/spec/01-unit/09-balancer/03-consistent_hashing_spec.lua @@ -11,9 +11,9 @@ local targets, balancers require "spec.helpers" -- initialize db local dns_utils = require "kong.resty.dns.utils" local mocker = require "spec.fixtures.mocker" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local helpers = require "spec.helpers.dns" local gettime = helpers.gettime diff --git a/spec/01-unit/09-balancer/04-round_robin_spec.lua b/spec/01-unit/09-balancer/04-round_robin_spec.lua index 17fe3b837783..35f63f2c4522 100644 --- a/spec/01-unit/09-balancer/04-round_robin_spec.lua +++ b/spec/01-unit/09-balancer/04-round_robin_spec.lua @@ -9,9 +9,9 @@ local targets, balancers local dns_utils = require "kong.resty.dns.utils" local mocker = require "spec.fixtures.mocker" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local helpers = require "spec.helpers.dns" local gettime = helpers.gettime diff --git a/spec/01-unit/09-balancer/05-worker_consistency_spec.lua b/spec/01-unit/09-balancer/05-worker_consistency_spec.lua index 18784b4690c8..3dd7d3714358 100644 --- a/spec/01-unit/09-balancer/05-worker_consistency_spec.lua +++ b/spec/01-unit/09-balancer/05-worker_consistency_spec.lua @@ -1,9 +1,8 @@ -local utils = require "kong.tools.utils" local mocker = require "spec.fixtures.mocker" local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy -local ws_id = utils.uuid() +local ws_id = require("kong.tools.uuid").uuid() local function setup_it_block(consistency) diff --git a/spec/01-unit/09-balancer/06-latency_spec.lua b/spec/01-unit/09-balancer/06-latency_spec.lua index 1a0945e9c4a8..89def3b45299 100644 --- a/spec/01-unit/09-balancer/06-latency_spec.lua +++ b/spec/01-unit/09-balancer/06-latency_spec.lua @@ -1,9 +1,9 @@ local dns_utils = require "kong.resty.dns.utils" local mocker = require "spec.fixtures.mocker" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local client, balancers, targets diff --git a/spec/01-unit/14-dns_spec.lua b/spec/01-unit/14-dns_spec.lua index 3be181652ee4..fda591d4df64 100644 --- a/spec/01-unit/14-dns_spec.lua +++ b/spec/01-unit/14-dns_spec.lua @@ -1,8 +1,8 @@ local mocker = require "spec.fixtures.mocker" local balancer = require "kong.runloop.balancer" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" -local ws_id = utils.uuid() +local ws_id = uuid.uuid() local function setup_it_block() local client = require "kong.resty.dns.client" diff --git a/spec/01-unit/27-queue_spec.lua b/spec/01-unit/27-queue_spec.lua index 878d0f85892f..8960d5076198 100644 --- a/spec/01-unit/27-queue_spec.lua +++ b/spec/01-unit/27-queue_spec.lua @@ -1,10 +1,10 @@ local Queue = require "kong.tools.queue" local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy -local utils = require "kong.tools.utils" local helpers = require "spec.helpers" local mocker = require "spec.fixtures.mocker" local timerng = require "resty.timerng" local queue_schema = require "kong.tools.queue_schema" +local uuid = require("kong.tools.uuid").uuid local queue_num = 1 @@ -71,7 +71,7 @@ describe("plugin queue", function() err = function(message) return log('ERR', message) end, }, plugin = { - get_id = function () return utils.uuid() end, + get_id = function () return uuid() end, }, }, ngx = { @@ -128,7 +128,7 @@ describe("plugin queue", function() it("displays log_tag in log entries", function () local handler_invoked - local log_tag = utils.uuid() + local log_tag = uuid() Queue.enqueue( queue_conf({ name = "log-tag", log_tag = log_tag }), function () diff --git a/spec/02-integration/03-db/02-db_core_entities_spec.lua b/spec/02-integration/03-db/02-db_core_entities_spec.lua index 0dedb916f6b0..51e1c147a730 100644 --- a/spec/02-integration/03-db/02-db_core_entities_spec.lua +++ b/spec/02-integration/03-db/02-db_core_entities_spec.lua @@ -1,6 +1,6 @@ local Errors = require "kong.db.errors" local defaults = require "kong.db.strategies.connector".defaults -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local helpers = require "spec.helpers" local cjson = require "cjson" local ssl_fixtures = require "spec.fixtures.ssl" @@ -604,7 +604,7 @@ for _, strategy in helpers.each_strategy() do end) it("cannot insert if foreign primary_key is invalid", function() - local fake_id = utils.uuid() + local fake_id = uuid.uuid() local credentials, _, err_t = db.basicauth_credentials:insert({ username = "peter", password = "pan", @@ -618,7 +618,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("cannot insert if foreign Service does not exist", function() - local u = utils.uuid() + local u = uuid.uuid() local service = { id = u } @@ -687,7 +687,7 @@ for _, strategy in helpers.each_strategy() do assert.is_table(route) assert.is_number(route.created_at) assert.is_number(route.updated_at) - assert.is_true(utils.is_valid_uuid(route.id)) + assert.is_true(uuid.is_valid_uuid(route.id)) assert.same({ id = route.id, @@ -731,7 +731,7 @@ for _, strategy in helpers.each_strategy() do assert.is_table(route) assert.is_number(route.created_at) assert.is_number(route.updated_at) - assert.is_true(utils.is_valid_uuid(route.id)) + assert.is_true(uuid.is_valid_uuid(route.id)) assert.same({ id = route.id, @@ -773,7 +773,7 @@ for _, strategy in helpers.each_strategy() do assert.is_table(route) assert.is_number(route.created_at) assert.is_number(route.updated_at) - assert.is_true(utils.is_valid_uuid(route.id)) + assert.is_true(uuid.is_valid_uuid(route.id)) assert.same({ id = route.id, @@ -985,7 +985,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("return nothing on non-existing Route", function() - local route, err, err_t = db.routes:select({ id = utils.uuid() }) + local route, err, err_t = db.routes:select({ id = uuid.uuid() }) assert.is_nil(route) assert.is_nil(err_t) assert.is_nil(err) @@ -1060,7 +1060,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns not found error", function() - local pk = { id = utils.uuid() } + local pk = { id = uuid.uuid() } local new_route, err, err_t = db.routes:update(pk, { protocols = { "https" }, hosts = { "example.com" }, @@ -1274,7 +1274,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns nothing if the Route does not exist", function() - local u = utils.uuid() + local u = uuid.uuid() local ok, err, err_t = db.routes:delete({ id = u }) @@ -1354,7 +1354,7 @@ for _, strategy in helpers.each_strategy() do assert.is_table(service) assert.is_number(service.created_at) assert.is_number(service.updated_at) - assert.is_true(utils.is_valid_uuid(service.id)) + assert.is_true(uuid.is_valid_uuid(service.id)) assert.same({ id = service.id, @@ -1401,7 +1401,7 @@ for _, strategy in helpers.each_strategy() do assert.is_table(service) assert.is_number(service.created_at) assert.is_number(service.updated_at) - assert.is_true(utils.is_valid_uuid(service.id)) + assert.is_true(uuid.is_valid_uuid(service.id)) assert.same({ id = service.id, @@ -1601,7 +1601,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns nothing on non-existing Service", function() local service, err, err_t = db.services:select({ - id = utils.uuid() + id = uuid.uuid() }) assert.is_nil(err_t) assert.is_nil(err) @@ -1682,7 +1682,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns not found error", function() - local pk = { id = utils.uuid() } + local pk = { id = uuid.uuid() } local service, err, err_t = db.services:update(pk, { protocol = "http" }) assert.is_nil(service) local message = fmt( @@ -1863,7 +1863,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns nothing if the Service does not exist", function() - local u = utils.uuid() + local u = uuid.uuid() local ok, err, err_t = db.services:delete({ id = u }) @@ -2010,7 +2010,7 @@ for _, strategy in helpers.each_strategy() do it(":update() cannot attach a Route to a non-existing Service", function() local service = { - id = utils.uuid() + id = uuid.uuid() } local route = bp.routes:insert({ diff --git a/spec/02-integration/03-db/07-tags_spec.lua b/spec/02-integration/03-db/07-tags_spec.lua index 2327a15bce7b..86f93d52ed8a 100644 --- a/spec/02-integration/03-db/07-tags_spec.lua +++ b/spec/02-integration/03-db/07-tags_spec.lua @@ -190,7 +190,7 @@ for _, strategy in helpers.each_strategy() do -- note this is different from test "update row in tags table with" -- as this test actually creates new records local scenarios = { - { "upsert", { id = require("kong.tools.utils").uuid() }, { "service-upsert-1" } }, + { "upsert", { id = require("kong.tools.uuid").uuid() }, { "service-upsert-1" } }, { "upsert_by_name", "service-upsert-2", { "service-upsert-2" } }, } for _, scenario in pairs(scenarios) do diff --git a/spec/02-integration/03-db/10-db_unique_foreign_spec.lua b/spec/02-integration/03-db/10-db_unique_foreign_spec.lua index 8a154b0b1e1c..7ab5ba0d054c 100644 --- a/spec/02-integration/03-db/10-db_unique_foreign_spec.lua +++ b/spec/02-integration/03-db/10-db_unique_foreign_spec.lua @@ -1,6 +1,6 @@ local Errors = require "kong.db.errors" local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local fmt = string.format @@ -78,7 +78,7 @@ for _, strategy in helpers.each_strategy() do it("returns nothing on non-existing Unique Foreign", function() for i = 1, 5 do local unique_reference, err, err_t = db.unique_references:select_by_unique_foreign({ - id = utils.uuid() + id = uuid.uuid() }) assert.is_nil(err) @@ -116,7 +116,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns not found error", function() - local uuid = utils.uuid() + local uuid = uuid.uuid() local unique_reference, err, err_t = db.unique_references:update_by_unique_foreign({ id = uuid, }, { @@ -193,7 +193,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns not found error", function() - local uuid = utils.uuid() + local uuid = uuid.uuid() local unique_reference, err, err_t = db.unique_references:upsert_by_unique_foreign({ id = uuid, }, { @@ -305,7 +305,7 @@ for _, strategy in helpers.each_strategy() do -- I/O it("returns nothing if the Unique Foreign does not exist", function() local ok, err, err_t = db.unique_references:delete_by_unique_foreign({ - id = utils.uuid() + id = uuid.uuid() }) assert.is_true(ok) assert.is_nil(err_t) diff --git a/spec/02-integration/03-db/14-dao_spec.lua b/spec/02-integration/03-db/14-dao_spec.lua index d71d59dc1bac..313ebd9bd650 100644 --- a/spec/02-integration/03-db/14-dao_spec.lua +++ b/spec/02-integration/03-db/14-dao_spec.lua @@ -1,7 +1,7 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local declarative = require "kong.db.declarative" local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy +local uuid = require("kong.tools.uuid").uuid -- Note: include "off" strategy here as well for _, strategy in helpers.all_strategies() do @@ -162,7 +162,7 @@ for _, strategy in helpers.all_strategies() do -- new plugin upsert (insert part of upsert) local new_plugin_config = { - id = utils.uuid(), + id = uuid(), enabled = true, name = "rate-limiting", instance_name = 'rate-limiting-instance-2', diff --git a/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua b/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua index d5251bd7c676..06fbb8968899 100644 --- a/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua +++ b/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua @@ -2,7 +2,7 @@ local helpers = require "spec.helpers" local cjson = require "cjson" local escape = require("socket.url").escape local Errors = require "kong.db.errors" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local function it_content_types(title, fn) @@ -267,7 +267,7 @@ describe("Admin API (#" .. strategy .. "): ", function() assert.same(c, json.data[1]) end) it("allows filtering by uuid-like custom_id", function() - local custom_id = utils.uuid() + local custom_id = uuid.uuid() local c = bp.consumers:insert({ custom_id = custom_id }, { nulls = true }) local res = client:get("/consumers?custom_id=" .. custom_id) @@ -472,7 +472,7 @@ describe("Admin API (#" .. strategy .. "): ", function() it_content_types("creates if not exists", function(content_type) return function() local custom_id = gensym() - local id = utils.uuid() + local id = uuid.uuid() local res = client:put("/consumers/" .. id, { body = { custom_id = custom_id }, headers = { ["Content-Type"] = content_type } @@ -556,7 +556,7 @@ describe("Admin API (#" .. strategy .. "): ", function() it_content_types("handles invalid input", function(content_type) return function() -- Missing params - local res = client:put("/consumers/" .. utils.uuid(), { + local res = client:put("/consumers/" .. uuid.uuid(), { body = {}, headers = { ["Content-Type"] = content_type } }) @@ -954,7 +954,7 @@ describe("Admin API (#" .. strategy .. "): ", function() for content_type, input in pairs(inputs) do it("creates if not found with " .. content_type, function() local consumer = bp.consumers:insert() - local plugin_id = utils.uuid() + local plugin_id = uuid.uuid() local res = assert(client:send { method = "PUT", diff --git a/spec/02-integration/04-admin_api/04-plugins_routes_spec.lua b/spec/02-integration/04-admin_api/04-plugins_routes_spec.lua index f1f52be07870..f59c2fa61e92 100644 --- a/spec/02-integration/04-admin_api/04-plugins_routes_spec.lua +++ b/spec/02-integration/04-admin_api/04-plugins_routes_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local admin_api = require "spec.fixtures.admin_api" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" for _, strategy in helpers.each_strategy() do @@ -187,7 +187,7 @@ for _, strategy in helpers.each_strategy() do }) local res = assert(client:send { method = "PUT", - path = "/plugins/" .. utils.uuid(), + path = "/plugins/" .. uuid.uuid(), body = { name = "key-auth", service = { @@ -201,7 +201,7 @@ for _, strategy in helpers.each_strategy() do it("can create a plugin by instance_name", function() local service = admin_api.services:insert() - local instance_name = "name-" .. utils.uuid() + local instance_name = "name-" .. uuid.uuid() local res = assert(client:send { method = "PUT", path = "/plugins/" .. instance_name, @@ -221,7 +221,7 @@ for _, strategy in helpers.each_strategy() do it("can upsert a plugin by instance_name", function() -- create a plugin by instance_name local service = admin_api.services:insert() - local instance_name = "name-" .. utils.uuid() + local instance_name = "name-" .. uuid.uuid() local plugin_id local res = assert(client:send { method = "PUT", diff --git a/spec/02-integration/04-admin_api/06-certificates_routes_spec.lua b/spec/02-integration/04-admin_api/06-certificates_routes_spec.lua index 848885c81670..c0fde48646cd 100644 --- a/spec/02-integration/04-admin_api/06-certificates_routes_spec.lua +++ b/spec/02-integration/04-admin_api/06-certificates_routes_spec.lua @@ -1,7 +1,7 @@ local ssl_fixtures = require "spec.fixtures.ssl" local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local Errors = require "kong.db.errors" @@ -341,7 +341,7 @@ describe("Admin API: #" .. strategy, function() end) it("returns 404 for a random non-existing uuid", function() - local res = client:get("/certificates/" .. utils.uuid()) + local res = client:get("/certificates/" .. uuid.uuid()) assert.res_status(404, res) end) @@ -354,7 +354,7 @@ describe("Admin API: #" .. strategy, function() describe("PUT", function() it("creates if not found", function() local n1 = get_name() - local id = utils.uuid() + local id = uuid.uuid() local res = client:put("/certificates/" .. id, { body = { cert = ssl_fixtures.cert, @@ -478,7 +478,7 @@ describe("Admin API: #" .. strategy, function() it("handles invalid input", function() -- Missing params - local res = client:put("/certificates/" .. utils.uuid(), { + local res = client:put("/certificates/" .. uuid.uuid(), { body = {}, headers = { ["Content-Type"] = "application/json" } }) @@ -496,7 +496,7 @@ describe("Admin API: #" .. strategy, function() it("handles invalid input with alternate certificate", function() -- Missing params - local res = client:put("/certificates/" .. utils.uuid(), { + local res = client:put("/certificates/" .. uuid.uuid(), { body = { cert = ssl_fixtures.cert, key = ssl_fixtures.key, @@ -788,7 +788,7 @@ describe("Admin API: #" .. strategy, function() it("returns 404 for a random non-existing id", function() local n1 = get_name() - local res = client:patch("/certificates/" .. utils.uuid(), { + local res = client:patch("/certificates/" .. uuid.uuid(), { body = { cert = ssl_fixtures.cert, key = ssl_fixtures.key, @@ -1206,7 +1206,7 @@ describe("Admin API: #" .. strategy, function() it("creates if not found", function() local certificate = add_certificate() local n1 = get_name() - local id = utils.uuid() + local id = uuid.uuid() local res = client:put("/snis/" .. id, { body = { certificate = { id = certificate.id }, @@ -1251,7 +1251,7 @@ describe("Admin API: #" .. strategy, function() it("handles invalid input", function() -- Missing params - local res = client:put("/snis/" .. utils.uuid(), { + local res = client:put("/snis/" .. uuid.uuid(), { body = {}, headers = { ["Content-Type"] = "application/json" } }) diff --git a/spec/02-integration/04-admin_api/08-targets_routes_spec.lua b/spec/02-integration/04-admin_api/08-targets_routes_spec.lua index 3f58cf6024e0..10d39ed3a03d 100644 --- a/spec/02-integration/04-admin_api/08-targets_routes_spec.lua +++ b/spec/02-integration/04-admin_api/08-targets_routes_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local tablex = require "pl.tablex" local function it_content_types(title, fn) @@ -797,8 +797,8 @@ describe("Admin API #" .. strategy, function() end) it("checks every combination of valid and invalid upstream and target", function() - for i, u in ipairs({ utils.uuid(), "invalid", upstream.name, upstream.id }) do - for j, t in ipairs({ utils.uuid(), "invalid:1234", wrong_target.id, target.target, target.id }) do + for i, u in ipairs({ uuid.uuid(), "invalid", upstream.name, upstream.id }) do + for j, t in ipairs({ uuid.uuid(), "invalid:1234", wrong_target.id, target.target, target.id }) do for _, e in ipairs({ "healthy", "unhealthy" }) do local expected = (i >= 3 and j >= 4) and 204 or 404 local path = "/upstreams/" .. u .. "/targets/" .. t .. "/" .. e diff --git a/spec/02-integration/04-admin_api/09-routes_routes_spec.lua b/spec/02-integration/04-admin_api/09-routes_routes_spec.lua index e358bf1d7062..3746e8c53bf0 100644 --- a/spec/02-integration/04-admin_api/09-routes_routes_spec.lua +++ b/spec/02-integration/04-admin_api/09-routes_routes_spec.lua @@ -1,5 +1,5 @@ local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local helpers = require "spec.helpers" local Errors = require "kong.db.errors" @@ -668,7 +668,7 @@ for _, strategy in helpers.each_strategy() do end) it("returns 404 if not found", function() - local res = client:get("/routes/" .. utils.uuid()) + local res = client:get("/routes/" .. uuid.uuid()) assert.res_status(404, res) end) @@ -709,7 +709,7 @@ for _, strategy in helpers.each_strategy() do end local service = bp.services:insert() - local id = utils.uuid() + local id = uuid.uuid() local res = client:put("/routes/" .. id, { headers = { ["Content-Type"] = content_type @@ -738,7 +738,7 @@ for _, strategy in helpers.each_strategy() do return end - local id = utils.uuid() + local id = uuid.uuid() local res = client:put("/routes/" .. id, { headers = { ["Content-Type"] = content_type @@ -896,7 +896,7 @@ for _, strategy in helpers.each_strategy() do end -- Missing params - local res = client:put("/routes/" .. utils.uuid(), { + local res = client:put("/routes/" .. uuid.uuid(), { body = {}, headers = { ["Content-Type"] = content_type } }) @@ -916,7 +916,7 @@ for _, strategy in helpers.each_strategy() do }, cjson.decode(body)) -- Invalid parameter - res = client:put("/routes/" .. utils.uuid(), { + res = client:put("/routes/" .. uuid.uuid(), { body = { methods = { "GET" }, protocols = { "foo", "http" }, @@ -1242,7 +1242,7 @@ for _, strategy in helpers.each_strategy() do return end - local res = client:patch("/routes/" .. utils.uuid(), { + local res = client:patch("/routes/" .. uuid.uuid(), { headers = { ["Content-Type"] = content_type }, @@ -1309,7 +1309,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it("returns HTTP 204 even if not found", function() - local res = client:delete("/routes/" .. utils.uuid()) + local res = client:delete("/routes/" .. uuid.uuid()) assert.res_status(204, res) end) end) @@ -1342,7 +1342,7 @@ for _, strategy in helpers.each_strategy() do end) it("returns 404 if not found", function() - local res = client:get("/routes/" .. utils.uuid() .. "/service") + local res = client:get("/routes/" .. uuid.uuid() .. "/service") assert.res_status(404, res) end) @@ -1461,7 +1461,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it_content_types("returns 404 if not found", function(content_type) return function() - local res = client:patch("/routes/" .. utils.uuid() .. "/service", { + local res = client:patch("/routes/" .. uuid.uuid() .. "/service", { headers = { ["Content-Type"] = content_type }, @@ -1511,7 +1511,7 @@ for _, strategy in helpers.each_strategy() do end) it("returns HTTP 404 with non-existing route", function() - local res = client:delete("/routes/" .. utils.uuid() .. "/service") + local res = client:delete("/routes/" .. uuid.uuid() .. "/service") assert.res_status(404, res) end) @@ -1645,7 +1645,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it_content_types("returns 404 if not found", function(content_type) return function() - local res = client:put("/routes/" .. utils.uuid() .. "/service", { + local res = client:put("/routes/" .. uuid.uuid() .. "/service", { headers = { ["Content-Type"] = content_type }, @@ -1902,7 +1902,7 @@ for _, strategy in helpers.each_strategy() do hosts = { "example.test" }, }) local plugin = bp.key_auth_plugins:insert({ - instance_name = "name-" .. utils.uuid(), + instance_name = "name-" .. uuid.uuid(), route = route, }) local res = client:get("/routes/" .. route.id .. "/plugins/" .. plugin.instance_name) @@ -1915,7 +1915,7 @@ for _, strategy in helpers.each_strategy() do describe("DELETE", function() it("deletes a plugin by id", function() - local route = bp.routes:insert({ paths = { "/route-" .. utils.uuid() }}) + local route = bp.routes:insert({ paths = { "/route-" .. uuid.uuid() }}) local plugin = bp.key_auth_plugins:insert({ route = route, }) @@ -1927,9 +1927,9 @@ for _, strategy in helpers.each_strategy() do assert.is_nil(in_db) end) it("deletes a plugin by instance_name", function() - local route = bp.routes:insert({ paths = { "/route-" .. utils.uuid() }}) + local route = bp.routes:insert({ paths = { "/route-" .. uuid.uuid() }}) local plugin = bp.key_auth_plugins:insert({ - instance_name = "name-" .. utils.uuid(), + instance_name = "name-" .. uuid.uuid(), route = route, }) local res = assert(client:delete("/routes/" .. route.id .. "/plugins/" .. plugin.instance_name)) diff --git a/spec/02-integration/04-admin_api/10-services_routes_spec.lua b/spec/02-integration/04-admin_api/10-services_routes_spec.lua index 32dbcd052ff3..8588e71b0c51 100644 --- a/spec/02-integration/04-admin_api/10-services_routes_spec.lua +++ b/spec/02-integration/04-admin_api/10-services_routes_spec.lua @@ -1,5 +1,5 @@ local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local helpers = require "spec.helpers" local Errors = require "kong.db.errors" @@ -272,7 +272,7 @@ for _, strategy in helpers.each_strategy() do end) it("returns 404 if not found", function() - local res = client:get("/services/" .. utils.uuid()) + local res = client:get("/services/" .. uuid.uuid()) assert.res_status(404, res) end) @@ -454,7 +454,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it("returns HTTP 204 even if not found", function() - local res = client:delete("/services/" .. utils.uuid()) + local res = client:delete("/services/" .. uuid.uuid()) assert.res_status(204, res) end) @@ -814,7 +814,7 @@ for _, strategy in helpers.each_strategy() do it("retrieves a plugin by instance_name", function() local service = bp.services:insert() local plugin = bp.key_auth_plugins:insert({ - instance_name = "name-" .. utils.uuid(), + instance_name = "name-" .. uuid.uuid(), service = service, }) local res = client:get("/services/" .. service.id .. "/plugins/" .. plugin.instance_name) @@ -841,7 +841,7 @@ for _, strategy in helpers.each_strategy() do it("deletes a plugin by instance_name", function() local service = bp.services:insert() local plugin = bp.key_auth_plugins:insert({ - instance_name = "name-" .. utils.uuid(), + instance_name = "name-" .. uuid.uuid(), service = service, }) local res = assert(client:delete("/services/" .. service.id .. "/plugins/" .. plugin.instance_name)) diff --git a/spec/02-integration/04-admin_api/15-off_spec.lua b/spec/02-integration/04-admin_api/15-off_spec.lua index b4acd359d301..069a51b4b829 100644 --- a/spec/02-integration/04-admin_api/15-off_spec.lua +++ b/spec/02-integration/04-admin_api/15-off_spec.lua @@ -1,6 +1,5 @@ local cjson = require "cjson" local lyaml = require "lyaml" -local utils = require "kong.tools.utils" local kong_table = require "kong.tools.table" local pl_utils = require "pl.utils" local helpers = require "spec.helpers" @@ -11,6 +10,7 @@ local inspect = require "inspect" local nkeys = require "table.nkeys" local typedefs = require "kong.db.schema.typedefs" local schema = require "kong.db.schema" +local uuid = require("kong.tools.uuid").uuid local WORKER_SYNC_TIMEOUT = 10 local LMDB_MAP_SIZE = "10m" @@ -84,7 +84,7 @@ describe("Admin API #off", function() body = { protocols = { "http" }, hosts = { "my.route.test" }, - service = { id = utils.uuid() }, + service = { id = uuid() }, }, headers = { ["Content-Type"] = content_type } }) @@ -111,7 +111,7 @@ describe("Admin API #off", function() methods = { "GET", "POST", "PATCH" }, hosts = { "foo.api.test", "bar.api.test" }, paths = { "/foo", "/bar" }, - service = { id = utils.uuid() }, + service = { id = uuid() }, }, headers = { ["Content-Type"] = content_type } }) @@ -160,7 +160,7 @@ describe("Admin API #off", function() path = "/routes", body = { paths = { "/" }, - service = { id = utils.uuid() } + service = { id = uuid() } }, headers = { ["Content-Type"] = "application/json" @@ -188,10 +188,10 @@ describe("Admin API #off", function() for i = 1, #methods do local res = assert(client:send { method = methods[i], - path = "/routes/" .. utils.uuid(), + path = "/routes/" .. uuid(), body = { paths = { "/" }, - service = { id = utils.uuid() } + service = { id = uuid() } }, headers = { ["Content-Type"] = "application/json" diff --git a/spec/02-integration/04-admin_api/17-foreign-entity_spec.lua b/spec/02-integration/04-admin_api/17-foreign-entity_spec.lua index afb94cfe24ac..4bb758634dd9 100644 --- a/spec/02-integration/04-admin_api/17-foreign-entity_spec.lua +++ b/spec/02-integration/04-admin_api/17-foreign-entity_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local Errors = require "kong.db.errors" @@ -99,7 +99,7 @@ for _, strategy in helpers.each_strategy() do end) it("returns 404 if not found", function() - local res = client:get("/foreign-references/" .. utils.uuid() .. "/same") + local res = client:get("/foreign-references/" .. uuid.uuid() .. "/same") assert.res_status(404, res) end) @@ -190,7 +190,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it_content_types("returns 404 if not found", function(content_type) return function() - local res = client:patch("/foreign-references/" .. utils.uuid() .. "/same", { + local res = client:patch("/foreign-references/" .. uuid.uuid() .. "/same", { headers = { ["Content-Type"] = content_type }, @@ -245,12 +245,12 @@ for _, strategy in helpers.each_strategy() do end) it("returns HTTP 404 with non-existing foreign entity ", function() - local res = client:delete("/foreign-entities/" .. utils.uuid() .. "/foreign-references/" .. utils.uuid()) + local res = client:delete("/foreign-entities/" .. uuid.uuid() .. "/foreign-references/" .. uuid.uuid()) assert.res_status(404, res) end) it("returns HTTP 404 with non-existing foreign reference", function() - local res = client:delete("/foreign-references/" .. utils.uuid() .. "/same") + local res = client:delete("/foreign-references/" .. uuid.uuid() .. "/same") assert.res_status(404, res) end) diff --git a/spec/02-integration/04-admin_api/19-vaults_spec.lua b/spec/02-integration/04-admin_api/19-vaults_spec.lua index 08063e30fe07..1f0a48bcd8a7 100644 --- a/spec/02-integration/04-admin_api/19-vaults_spec.lua +++ b/spec/02-integration/04-admin_api/19-vaults_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" @@ -103,7 +103,7 @@ for _, strategy in helpers.each_strategy() do describe("PUT", function() it("can create a vault by id", function() - local res = client:put("/vaults/" .. utils.uuid(), { + local res = client:put("/vaults/" .. uuid.uuid(), { headers = HEADERS, body = { name = "env", @@ -151,7 +151,7 @@ for _, strategy in helpers.each_strategy() do describe("errors", function() it("handles invalid input by id", function() - local res = client:put("/vaults/" .. utils.uuid(), { + local res = client:put("/vaults/" .. uuid.uuid(), { headers = HEADERS, body = { name = "env", diff --git a/spec/02-integration/05-proxy/04-plugins_triggering_spec.lua b/spec/02-integration/05-proxy/04-plugins_triggering_spec.lua index 5f729b221947..09551259bad8 100644 --- a/spec/02-integration/05-proxy/04-plugins_triggering_spec.lua +++ b/spec/02-integration/05-proxy/04-plugins_triggering_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" local pl_path = require "pl.path" local pl_file = require "pl.file" @@ -415,7 +415,7 @@ for _, strategy in helpers.each_strategy() do end) it("execute a log plugin", function() - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -470,7 +470,7 @@ for _, strategy in helpers.each_strategy() do -- regression test for bug spotted in 0.12.0rc2 it("responses.send stops plugin but runloop continues", function() - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -766,7 +766,7 @@ for _, strategy in helpers.each_strategy() do it("executes a log plugin on Bad Gateway (HTTP 502)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -787,7 +787,7 @@ for _, strategy in helpers.each_strategy() do it("log plugins sees same request in error_page handler (HTTP 502)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "POST", @@ -818,7 +818,7 @@ for _, strategy in helpers.each_strategy() do it("executes a log plugin on Service Unavailable (HTTP 503)", function() -- Does not trigger error_page directive (no proxy_intercept_errors) - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -839,7 +839,7 @@ for _, strategy in helpers.each_strategy() do it("executes a log plugin on Gateway Timeout (HTTP 504)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -860,7 +860,7 @@ for _, strategy in helpers.each_strategy() do it("log plugins sees same request in error_page handler (HTTP 504)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "POST", @@ -891,7 +891,7 @@ for _, strategy in helpers.each_strategy() do it("executes a global log plugin on Nginx-produced client errors (HTTP 400)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -919,7 +919,7 @@ for _, strategy in helpers.each_strategy() do it("log plugins sees same request in error_page handler (HTTP 400)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "POST", @@ -954,7 +954,7 @@ for _, strategy in helpers.each_strategy() do it("executes a global log plugin on Nginx-produced client errors (HTTP 414)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "GET", @@ -982,7 +982,7 @@ for _, strategy in helpers.each_strategy() do it("log plugins sees same request in error_page handler (HTTP 414)", function() -- triggers error_page directive - local uuid = utils.uuid() + local uuid = uuid.uuid() local res = assert(proxy_client:send { method = "POST", diff --git a/spec/02-integration/05-proxy/10-balancer/01-healthchecks_spec.lua b/spec/02-integration/05-proxy/10-balancer/01-healthchecks_spec.lua index 9de7aacc4f18..0d3872c093c8 100644 --- a/spec/02-integration/05-proxy/10-balancer/01-healthchecks_spec.lua +++ b/spec/02-integration/05-proxy/10-balancer/01-healthchecks_spec.lua @@ -1,7 +1,7 @@ local bu = require "spec.fixtures.balancer_utils" local cjson = require "cjson" local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local https_server = helpers.https_server @@ -1099,7 +1099,7 @@ for _, strategy in helpers.each_strategy() do local api_host, service_id = bu.add_api(bp, upstream_name, { connect_timeout = 50, }) -- add a plugin - local plugin_id = utils.uuid() + local plugin_id = uuid.uuid() bp.plugins:insert({ id = plugin_id, service = { id = service_id }, diff --git a/spec/02-integration/05-proxy/14-server_tokens_spec.lua b/spec/02-integration/05-proxy/14-server_tokens_spec.lua index 6cee745a1354..95447d9b371e 100644 --- a/spec/02-integration/05-proxy/14-server_tokens_spec.lua +++ b/spec/02-integration/05-proxy/14-server_tokens_spec.lua @@ -2,7 +2,7 @@ local meta = require "kong.meta" local helpers = require "spec.helpers" local constants = require "kong.constants" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require("kong.tools.uuid").uuid local default_server_header = meta._SERVER_TOKENS @@ -455,7 +455,7 @@ describe("headers [#" .. strategy .. "]", function() if strategy ~= "off" then it("should not be returned when plugin errors on rewrite phase", function() local admin_client = helpers.admin_client() - local uuid = utils.uuid() + local uuid = uuid() local res = assert(admin_client:send { method = "PUT", path = "/plugins/" .. uuid, diff --git a/spec/02-integration/06-invalidations/03-plugins_iterator_invalidation_spec.lua b/spec/02-integration/06-invalidations/03-plugins_iterator_invalidation_spec.lua index e0ab5ccba749..c61794489324 100644 --- a/spec/02-integration/06-invalidations/03-plugins_iterator_invalidation_spec.lua +++ b/spec/02-integration/06-invalidations/03-plugins_iterator_invalidation_spec.lua @@ -1,6 +1,6 @@ local cjson = require "cjson" local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require("kong.tools.uuid").uuid local POLL_INTERVAL = 0.3 @@ -273,7 +273,7 @@ for _, strategy in helpers.each_strategy() do -- A regression test for https://github.com/Kong/kong/issues/4191 local admin_res_plugin = assert(admin_client_1:send { method = "PUT", - path = "/plugins/" .. utils.uuid(), + path = "/plugins/" .. uuid(), body = { name = "dummy", service = { id = service_fixture.id }, diff --git a/spec/02-integration/09-hybrid_mode/01-sync_spec.lua b/spec/02-integration/09-hybrid_mode/01-sync_spec.lua index 0573be38d667..71bb46ead473 100644 --- a/spec/02-integration/09-hybrid_mode/01-sync_spec.lua +++ b/spec/02-integration/09-hybrid_mode/01-sync_spec.lua @@ -1,5 +1,4 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local cjson = require "cjson.safe" local _VERSION_TABLE = require "kong.meta" ._VERSION_TABLE local MAJOR = _VERSION_TABLE.major @@ -7,6 +6,7 @@ local MINOR = _VERSION_TABLE.minor local PATCH = _VERSION_TABLE.patch local CLUSTERING_SYNC_STATUS = require("kong.constants").CLUSTERING_SYNC_STATUS local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy +local uuid = require("kong.tools.uuid").uuid local KEY_AUTH_PLUGIN @@ -480,7 +480,7 @@ describe("CP/DP #version check #" .. strategy, function() for desc, harness in pairs(allowed_cases) do it(desc .. ", sync is allowed", function() - local uuid = utils.uuid() + local uuid = uuid() local res = assert(helpers.clustering_client({ host = "127.0.0.1", @@ -567,7 +567,7 @@ describe("CP/DP #version check #" .. strategy, function() for desc, harness in pairs(blocked_cases) do it(desc ..", sync is blocked", function() - local uuid = utils.uuid() + local uuid = uuid() local res, err = helpers.clustering_client({ host = "127.0.0.1", diff --git a/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua b/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua index 1c8f7bd26ee5..53d21bf08a0d 100644 --- a/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua +++ b/spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua @@ -1,8 +1,8 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local cjson = require "cjson" local CLUSTERING_SYNC_STATUS = require("kong.constants").CLUSTERING_SYNC_STATUS local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy +local uuid = require("kong.tools.uuid").uuid local admin = require "spec.fixtures.admin_api" @@ -20,7 +20,7 @@ local function cluster_client(opts) cert = "spec/fixtures/kong_clustering.crt", cert_key = "spec/fixtures/kong_clustering.key", node_hostname = opts.hostname or "test", - node_id = opts.id or utils.uuid(), + node_id = opts.id or uuid(), node_version = opts.version, node_plugins_list = PLUGIN_LIST, }) @@ -142,7 +142,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected.config.error_code = nil expected.config.error_message = nil expected.config.sync_rate = nil - do_assert(utils.uuid(), "3.0.0", expected) + do_assert(uuid(), "3.0.0", expected) --[[ @@ -153,7 +153,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected = cycle_aware_deep_copy(rate_limit) expected.config.redis = nil expected.config.sync_rate = nil - do_assert(utils.uuid(), "3.2.0", expected) + do_assert(uuid(), "3.2.0", expected) --[[ @@ -164,7 +164,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected = cycle_aware_deep_copy(rate_limit) expected.config.redis = nil expected.config.sync_rate = nil - do_assert(utils.uuid(), "3.3.0", expected) + do_assert(uuid(), "3.3.0", expected) -- cleanup admin.plugins:remove({ id = rate_limit.id }) @@ -191,7 +191,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() local expected = cycle_aware_deep_copy(rate_limit) expected.config.redis = nil - do_assert(utils.uuid(), "3.4.0", expected) + do_assert(uuid(), "3.4.0", expected) -- cleanup admin.plugins:remove({ id = rate_limit.id }) @@ -212,7 +212,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() assert.not_nil(cors.config.private_network) local expected_cors = cycle_aware_deep_copy(cors) expected_cors.config.private_network = nil - do_assert(utils.uuid(), "3.4.0", expected_cors) + do_assert(uuid(), "3.4.0", expected_cors) -- cleanup admin.plugins:remove({ id = cors.id }) @@ -228,7 +228,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() -- ]] } } - do_assert(utils.uuid(), "3.5.0", cors) + do_assert(uuid(), "3.5.0", cors) -- cleanup admin.plugins:remove({ id = cors.id }) @@ -253,7 +253,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_otel_prior_35.config.header_type = "preserve" expected_otel_prior_35.config.sampling_rate = nil expected_otel_prior_35.config.propagation = nil - do_assert(utils.uuid(), "3.4.0", expected_otel_prior_35) + do_assert(uuid(), "3.4.0", expected_otel_prior_35) -- cleanup admin.plugins:remove({ id = opentelemetry.id }) @@ -274,7 +274,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_otel_prior_34.config.header_type = "preserve" expected_otel_prior_34.config.sampling_rate = nil expected_otel_prior_34.config.propagation = nil - do_assert(utils.uuid(), "3.3.0", expected_otel_prior_34) + do_assert(uuid(), "3.3.0", expected_otel_prior_34) -- cleanup admin.plugins:remove({ id = opentelemetry.id }) @@ -300,7 +300,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_zipkin_prior_35.config.header_type = "preserve" expected_zipkin_prior_35.config.default_header_type = "b3" expected_zipkin_prior_35.config.propagation = nil - do_assert(utils.uuid(), "3.4.0", expected_zipkin_prior_35) + do_assert(uuid(), "3.4.0", expected_zipkin_prior_35) -- cleanup admin.plugins:remove({ id = zipkin.id }) @@ -321,7 +321,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_zipkin_prior_34.config.header_type = "preserve" expected_zipkin_prior_34.config.default_header_type = "b3" expected_zipkin_prior_34.config.propagation = nil - do_assert(utils.uuid(), "3.3.0", expected_zipkin_prior_34) + do_assert(uuid(), "3.3.0", expected_zipkin_prior_34) -- cleanup admin.plugins:remove({ id = zipkin.id }) @@ -372,7 +372,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() namespace = "test_namespace", scan_count = 13 } - do_assert(utils.uuid(), "3.5.0", expected_acme_prior_36) + do_assert(uuid(), "3.5.0", expected_acme_prior_36) -- cleanup admin.plugins:remove({ id = acme.id }) @@ -417,7 +417,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_rl_prior_36.config.redis_server_name = "example.test" - do_assert(utils.uuid(), "3.5.0", expected_rl_prior_36) + do_assert(uuid(), "3.5.0", expected_rl_prior_36) -- cleanup admin.plugins:remove({ id = rl.id }) @@ -466,7 +466,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_response_rl_prior_36.config.redis_server_name = "example.test" - do_assert(utils.uuid(), "3.5.0", expected_response_rl_prior_36) + do_assert(uuid(), "3.5.0", expected_response_rl_prior_36) -- cleanup admin.plugins:remove({ id = response_rl.id }) @@ -505,7 +505,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() expected_ai_proxy_prior_37.config.model.options.upstream_path = nil expected_ai_proxy_prior_37.config.route_type = "llm/v1/chat" - do_assert(utils.uuid(), "3.6.0", expected_ai_proxy_prior_37) + do_assert(uuid(), "3.6.0", expected_ai_proxy_prior_37) -- cleanup admin.plugins:remove({ id = ai_proxy.id }) @@ -544,7 +544,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() local expected_ai_request_transformer_prior_37 = cycle_aware_deep_copy(ai_request_transformer) expected_ai_request_transformer_prior_37.config.llm.model.options.upstream_path = nil - do_assert(utils.uuid(), "3.6.0", expected_ai_request_transformer_prior_37) + do_assert(uuid(), "3.6.0", expected_ai_request_transformer_prior_37) -- cleanup admin.plugins:remove({ id = ai_request_transformer.id }) @@ -581,7 +581,7 @@ describe("CP/DP config compat transformations #" .. strategy, function() local expected_ai_response_transformer_prior_37 = cycle_aware_deep_copy(ai_response_transformer) expected_ai_response_transformer_prior_37.config.llm.model.options.upstream_path = nil - do_assert(utils.uuid(), "3.6.0", expected_ai_response_transformer_prior_37) + do_assert(uuid(), "3.6.0", expected_ai_response_transformer_prior_37) -- cleanup admin.plugins:remove({ id = ai_response_transformer.id }) diff --git a/spec/02-integration/09-hybrid_mode/09-node-id-persistence_spec.lua b/spec/02-integration/09-hybrid_mode/09-node-id-persistence_spec.lua index 2d507dda2fc9..cd67cd502c27 100644 --- a/spec/02-integration/09-hybrid_mode/09-node-id-persistence_spec.lua +++ b/spec/02-integration/09-hybrid_mode/09-node-id-persistence_spec.lua @@ -1,7 +1,6 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" -local is_valid_uuid = utils.is_valid_uuid +local is_valid_uuid = require("kong.tools.uuid").is_valid_uuid local PREFIX = "servroot.dp" local NODE_ID = PREFIX .. "/kong.id" diff --git a/spec/02-integration/20-wasm/01-admin-api_spec.lua b/spec/02-integration/20-wasm/01-admin-api_spec.lua index ee9c3ce8316a..6ca6d75798c1 100644 --- a/spec/02-integration/20-wasm/01-admin-api_spec.lua +++ b/spec/02-integration/20-wasm/01-admin-api_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local fmt = string.format @@ -99,7 +99,7 @@ describe("wasm admin API [#" .. strategy .. "]", function() local body = assert.response(res).has.jsonbody() assert.is_string(body.id) - assert.truthy(utils.is_valid_uuid(body.id)) + assert.truthy(uuid.is_valid_uuid(body.id)) assert.equals(1, #body.filters) assert.equals("tests", body.filters[1].name) @@ -172,7 +172,7 @@ describe("wasm admin API [#" .. strategy .. "]", function() it("returns 404 if not found", function() assert.response( - admin:get("/filter-chains/" .. utils.uuid()) + admin:get("/filter-chains/" .. uuid.uuid()) ).has.status(404) end) end) @@ -234,7 +234,7 @@ describe("wasm admin API [#" .. strategy .. "]", function() end) - unsupported("POST", "/filter-chains/" .. utils.uuid()) + unsupported("POST", "/filter-chains/" .. uuid.uuid()) end) end -- each { "id", "name" } @@ -270,7 +270,7 @@ describe("wasm admin API [#" .. strategy .. "]", function() local body = assert.response(res).has.jsonbody() assert.is_string(body.id) - assert.truthy(utils.is_valid_uuid(body.id)) + assert.truthy(uuid.is_valid_uuid(body.id)) assert.equals(1, #body.filters) assert.equals("tests", body.filters[1].name) @@ -340,7 +340,7 @@ describe("wasm admin API [#" .. strategy .. "]", function() it("returns 404 if not found", function() assert.response( - admin:get(path .. utils.uuid()) + admin:get(path .. uuid.uuid()) ).has.status(404) end) end) @@ -666,7 +666,7 @@ describe("wasm admin API - wasm = off [#" .. strategy .. "]", function() it("PATCH returns 400", function() assert.response( - admin:patch(path .. "/" .. utils.uuid()), json({ + admin:patch(path .. "/" .. uuid.uuid()), json({ filters = { { name = "tests" } }, service = { id = service.id }, }) @@ -675,7 +675,7 @@ describe("wasm admin API - wasm = off [#" .. strategy .. "]", function() it("PUT returns 400", function() assert.response( - admin:put(path .. "/" .. utils.uuid()), json({ + admin:put(path .. "/" .. uuid.uuid()), json({ filters = { { name = "tests" } }, service = { id = service.id }, }) @@ -684,7 +684,7 @@ describe("wasm admin API - wasm = off [#" .. strategy .. "]", function() it("DELETE returns 400", function() assert.response( - admin:delete(path .. "/" .. utils.uuid()) + admin:delete(path .. "/" .. uuid.uuid()) ).has.status(400) end) diff --git a/spec/02-integration/20-wasm/02-db_spec.lua b/spec/02-integration/20-wasm/02-db_spec.lua index be7e2ec7e2bd..cd3d1ee34652 100644 --- a/spec/02-integration/20-wasm/02-db_spec.lua +++ b/spec/02-integration/20-wasm/02-db_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local schema_lib = require "kong.db.schema.json" local FILTER_PATH = assert(helpers.test_conf.wasm_filters_path) @@ -63,11 +63,11 @@ describe("wasm DB entities [#" .. strategy .. "]", function() })) assert.is_string(chain.id) - assert.truthy(utils.is_valid_uuid(chain.id)) + assert.truthy(uuid.is_valid_uuid(chain.id)) end) it("can be user-generated", function() - local id = utils.uuid() + local id = uuid.uuid() local chain = assert(dao:insert({ id = id, service = make_service(), @@ -76,7 +76,7 @@ describe("wasm DB entities [#" .. strategy .. "]", function() assert.is_string(chain.id) assert.equals(id, chain.id) - assert.truthy(utils.is_valid_uuid(chain.id)) + assert.truthy(uuid.is_valid_uuid(chain.id)) end) it("must be a valid uuid", function() @@ -178,7 +178,7 @@ describe("wasm DB entities [#" .. strategy .. "]", function() it("requires the route to exist", function() local chain, err, err_t = dao:insert({ filters = { { name = "test" } }, - route = { id = utils.uuid() }, + route = { id = uuid.uuid() }, }) assert.is_nil(chain) @@ -210,7 +210,7 @@ describe("wasm DB entities [#" .. strategy .. "]", function() it("requires the service to exist", function() local chain, err, err_t = dao:insert({ filters = { { name = "test" } }, - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, }) assert.is_nil(chain) @@ -247,7 +247,7 @@ describe("wasm DB entities [#" .. strategy .. "]", function() helpers.wait_until(function() local updated = assert(dao:update( { id = chain.id }, - { tags = { utils.uuid() } } + { tags = { uuid.uuid() } } )) return updated.updated_at > chain.updated_at diff --git a/spec/03-plugins/03-http-log/02-schema_spec.lua b/spec/03-plugins/03-http-log/02-schema_spec.lua index f96b4eadb0ac..2bd01c54c178 100644 --- a/spec/03-plugins/03-http-log/02-schema_spec.lua +++ b/spec/03-plugins/03-http-log/02-schema_spec.lua @@ -2,7 +2,7 @@ local PLUGIN_NAME = "http-log" local Queue = require "kong.tools.queue" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local mocker = require "spec.fixtures.mocker" -- helper function to validate data against a schema @@ -37,7 +37,7 @@ describe(PLUGIN_NAME .. ": (schema)", function() err = function(message) return log('ERR', message) end, }, plugin = { - get_id = function () return utils.uuid() end, + get_id = function () return uuid.uuid() end, }, }, ngx = { diff --git a/spec/03-plugins/05-syslog/01-log_spec.lua b/spec/03-plugins/05-syslog/01-log_spec.lua index c84c55213c68..9f913dd36c6c 100644 --- a/spec/03-plugins/05-syslog/01-log_spec.lua +++ b/spec/03-plugins/05-syslog/01-log_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" local pl_stringx = require "pl.stringx" @@ -159,7 +159,7 @@ for _, strategy in helpers.each_strategy() do end) local function do_test(host, expecting_same, grpc) - local uuid = utils.uuid() + local uuid = uuid.uuid() local ok, resp if not grpc then diff --git a/spec/03-plugins/09-key-auth/02-access_spec.lua b/spec/03-plugins/09-key-auth/02-access_spec.lua index 49f3f3561a1e..6c63dbde3edb 100644 --- a/spec/03-plugins/09-key-auth/02-access_spec.lua +++ b/spec/03-plugins/09-key-auth/02-access_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local http_mock = require "spec.helpers.http_mock" local MOCK_PORT = helpers.get_available_port() @@ -117,7 +117,7 @@ for _, strategy in helpers.each_strategy() do name = "key-auth", route = { id = route4.id }, config = { - anonymous = utils.uuid(), -- unknown consumer + anonymous = uuid.uuid(), -- unknown consumer }, } diff --git a/spec/03-plugins/10-basic-auth/03-access_spec.lua b/spec/03-plugins/10-basic-auth/03-access_spec.lua index 765a3a4aa77b..34560721de35 100644 --- a/spec/03-plugins/10-basic-auth/03-access_spec.lua +++ b/spec/03-plugins/10-basic-auth/03-access_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" for _, strategy in helpers.each_strategy() do @@ -104,7 +104,7 @@ for _, strategy in helpers.each_strategy() do name = "basic-auth", route = { id = route4.id }, config = { - anonymous = utils.uuid(), -- a non-existing consumer id + anonymous = uuid.uuid(), -- a non-existing consumer id }, } diff --git a/spec/03-plugins/16-jwt/03-access_spec.lua b/spec/03-plugins/16-jwt/03-access_spec.lua index d091fb8e478d..972749f604e0 100644 --- a/spec/03-plugins/16-jwt/03-access_spec.lua +++ b/spec/03-plugins/16-jwt/03-access_spec.lua @@ -2,7 +2,7 @@ local cjson = require "cjson" local helpers = require "spec.helpers" local fixtures = require "spec.03-plugins.16-jwt.fixtures" local jwt_encoder = require "kong.plugins.jwt.jwt_parser" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local PAYLOAD = { @@ -121,7 +121,7 @@ for _, strategy in helpers.each_strategy() do plugins:insert({ name = "jwt", route = { id = routes[7].id }, - config = { anonymous = utils.uuid() }, + config = { anonymous = uuid.uuid() }, }) plugins:insert({ diff --git a/spec/03-plugins/18-acl/01-api_spec.lua b/spec/03-plugins/18-acl/01-api_spec.lua index dd84c9eb292f..202ba067ab38 100644 --- a/spec/03-plugins/18-acl/01-api_spec.lua +++ b/spec/03-plugins/18-acl/01-api_spec.lua @@ -1,4 +1,4 @@ -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" local helpers = require "spec.helpers" @@ -466,7 +466,7 @@ for _, strategy in helpers.each_strategy() do end) it("does not create acl when missing consumer", function() - local res = admin_client:put("/acls/" .. utils.uuid(), { + local res = admin_client:put("/acls/" .. uuid.uuid(), { body = { group = "test-group" }, headers = { ["Content-Type"] = "application/json" @@ -478,7 +478,7 @@ for _, strategy in helpers.each_strategy() do end) it("creates acl", function() - local res = admin_client:put("/acls/" .. utils.uuid(), { + local res = admin_client:put("/acls/" .. uuid.uuid(), { body = { group = "test-group", consumer = { diff --git a/spec/03-plugins/19-hmac-auth/03-access_spec.lua b/spec/03-plugins/19-hmac-auth/03-access_spec.lua index 643ed1adfcf6..4e3a1920d0fe 100644 --- a/spec/03-plugins/19-hmac-auth/03-access_spec.lua +++ b/spec/03-plugins/19-hmac-auth/03-access_spec.lua @@ -1,7 +1,7 @@ local cjson = require "cjson" local openssl_mac = require "resty.openssl.mac" local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local resty_sha256 = require "resty.sha256" local fmt = string.format @@ -95,7 +95,7 @@ for _, strategy in helpers.each_strategy() do name = "hmac-auth", route = { id = route3.id }, config = { - anonymous = utils.uuid(), -- non existing consumer + anonymous = uuid.uuid(), -- non existing consumer clock_skew = 3000 } } diff --git a/spec/03-plugins/20-ldap-auth/01-access_spec.lua b/spec/03-plugins/20-ldap-auth/01-access_spec.lua index f0aa66e60ad9..f106076e58b6 100644 --- a/spec/03-plugins/20-ldap-auth/01-access_spec.lua +++ b/spec/03-plugins/20-ldap-auth/01-access_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local cjson = require "cjson" @@ -136,7 +136,7 @@ for _, ldap_strategy in pairs(ldap_strategies) do base_dn = "ou=scientists,dc=ldap,dc=mashape,dc=com", attribute = "uid", cache_ttl = 2, - anonymous = utils.uuid(), -- non existing consumer + anonymous = uuid.uuid(), -- non existing consumer } } diff --git a/spec/03-plugins/23-rate-limiting/02-policies_spec.lua b/spec/03-plugins/23-rate-limiting/02-policies_spec.lua index 640de183f1db..f28dc47f445b 100644 --- a/spec/03-plugins/23-rate-limiting/02-policies_spec.lua +++ b/spec/03-plugins/23-rate-limiting/02-policies_spec.lua @@ -1,4 +1,4 @@ -local uuid = require("kong.tools.utils").uuid +local uuid = require("kong.tools.uuid").uuid local helpers = require "spec.helpers" local timestamp = require "kong.tools.timestamp" diff --git a/spec/03-plugins/23-rate-limiting/06-shorthand_fields_spec.lua b/spec/03-plugins/23-rate-limiting/06-shorthand_fields_spec.lua index d5c122fb62a8..19d8d20d6e3d 100644 --- a/spec/03-plugins/23-rate-limiting/06-shorthand_fields_spec.lua +++ b/spec/03-plugins/23-rate-limiting/06-shorthand_fields_spec.lua @@ -1,11 +1,11 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local cjson = require "cjson" +local uuid = require("kong.tools.uuid").uuid describe("Plugin: rate-limiting (shorthand fields)", function() local bp, route, admin_client - local plugin_id = utils.uuid() + local plugin_id = uuid() lazy_setup(function() bp = helpers.get_db_utils(nil, { diff --git a/spec/03-plugins/24-response-rate-limiting/02-policies_spec.lua b/spec/03-plugins/24-response-rate-limiting/02-policies_spec.lua index 38b3a240f0c3..dbc848b6631c 100644 --- a/spec/03-plugins/24-response-rate-limiting/02-policies_spec.lua +++ b/spec/03-plugins/24-response-rate-limiting/02-policies_spec.lua @@ -1,4 +1,4 @@ -local uuid = require("kong.tools.utils").uuid +local uuid = require("kong.tools.uuid").uuid local helpers = require "spec.helpers" local timestamp = require "kong.tools.timestamp" diff --git a/spec/03-plugins/24-response-rate-limiting/06-shorthand_fields_spec.lua b/spec/03-plugins/24-response-rate-limiting/06-shorthand_fields_spec.lua index 69275b322887..3d2de4c436a2 100644 --- a/spec/03-plugins/24-response-rate-limiting/06-shorthand_fields_spec.lua +++ b/spec/03-plugins/24-response-rate-limiting/06-shorthand_fields_spec.lua @@ -1,11 +1,11 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local cjson = require "cjson" +local uuid = require("kong.tools.uuid").uuid describe("Plugin: response-ratelimiting (shorthand fields)", function() local bp, route, admin_client - local plugin_id = utils.uuid() + local plugin_id = uuid() lazy_setup(function() bp = helpers.get_db_utils(nil, { diff --git a/spec/03-plugins/25-oauth2/01-schema_spec.lua b/spec/03-plugins/25-oauth2/01-schema_spec.lua index f0de8317a158..13a6c31c936d 100644 --- a/spec/03-plugins/25-oauth2/01-schema_spec.lua +++ b/spec/03-plugins/25-oauth2/01-schema_spec.lua @@ -1,5 +1,5 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local schema_def = require "kong.plugins.oauth2.schema" local DAO_MAX_TTL = require("kong.constants").DATABASE.DAO_MAX_TTL local v = require("spec.helpers").validate_plugin_config_schema @@ -118,7 +118,7 @@ for _, strategy in helpers.each_strategy() do local ok, err_t = oauth2_tokens_schema:validate_insert({ credential = { id = "foo" }, - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, expires_in = 1, }) assert.falsy(ok) @@ -129,8 +129,8 @@ for _, strategy in helpers.each_strategy() do local ok, err_t = oauth2_tokens_schema:validate_insert({ - credential = { id = utils.uuid() }, - service = { id = utils.uuid() }, + credential = { id = uuid.uuid() }, + service = { id = uuid.uuid() }, expires_in = 1, token_type = "bearer", }) @@ -152,7 +152,7 @@ for _, strategy in helpers.each_strategy() do local ok, err_t = oauth2_authorization_codes_schema:validate_insert({ credential = { id = "foo" }, - service = { id = utils.uuid() }, + service = { id = uuid.uuid() }, }) assert.falsy(ok) assert.same({ @@ -160,8 +160,8 @@ for _, strategy in helpers.each_strategy() do }, err_t) local ok, err_t = oauth2_authorization_codes_schema:validate_insert({ - credential = { id = utils.uuid() }, - service = { id = utils.uuid() }, + credential = { id = uuid.uuid() }, + service = { id = uuid.uuid() }, }) assert.truthy(ok) diff --git a/spec/03-plugins/25-oauth2/03-access_spec.lua b/spec/03-plugins/25-oauth2/03-access_spec.lua index 48e1cf018a28..e941769b6027 100644 --- a/spec/03-plugins/25-oauth2/03-access_spec.lua +++ b/spec/03-plugins/25-oauth2/03-access_spec.lua @@ -1,6 +1,6 @@ local cjson = require "cjson" local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" local admin_api = require "spec.fixtures.admin_api" local sha256 = require "resty.sha256" local jwt_encoder = require "kong.plugins.jwt.jwt_parser" @@ -510,7 +510,7 @@ describe("Plugin: oauth2 [#" .. strategy .. "]", function() config = { scopes = { "email", "profile", "user.email" }, global_credentials = true, - anonymous = utils.uuid(), -- a non existing consumer + anonymous = uuid.uuid(), -- a non existing consumer }, }) diff --git a/spec/03-plugins/29-acme/07-shorthand_fields_spec.lua b/spec/03-plugins/29-acme/07-shorthand_fields_spec.lua index f40b47f9af6f..ba199a7440bb 100644 --- a/spec/03-plugins/29-acme/07-shorthand_fields_spec.lua +++ b/spec/03-plugins/29-acme/07-shorthand_fields_spec.lua @@ -1,11 +1,11 @@ local helpers = require "spec.helpers" -local utils = require "kong.tools.utils" local cjson = require "cjson" +local uuid = require("kong.tools.uuid").uuid describe("Plugin: acme (shorthand fields)", function() local bp, route, admin_client - local plugin_id = utils.uuid() + local plugin_id = uuid() lazy_setup(function() bp = helpers.get_db_utils(nil, { diff --git a/spec/03-plugins/39-reconfiguration-completion/01-access_spec.lua b/spec/03-plugins/39-reconfiguration-completion/01-access_spec.lua index 83768ef7ab89..436256de6cd3 100644 --- a/spec/03-plugins/39-reconfiguration-completion/01-access_spec.lua +++ b/spec/03-plugins/39-reconfiguration-completion/01-access_spec.lua @@ -1,6 +1,6 @@ local helpers = require "spec.helpers" local cjson = require "cjson" -local utils = require "kong.tools.utils" +local uuid = require "kong.tools.uuid" describe("Reconfiguration completion detection plugin", function() @@ -11,7 +11,7 @@ describe("Reconfiguration completion detection plugin", function() local function plugin_tests() - local configuration_version = utils.uuid() + local configuration_version = uuid.uuid() local res = admin_client:post("/plugins", { body = { @@ -72,7 +72,7 @@ describe("Reconfiguration completion detection plugin", function() }) assert.res_status(201, res) - configuration_version = utils.uuid() + configuration_version = uuid.uuid() res = admin_client:patch("/plugins/" .. reconfiguration_completion_plugin_id, { body = { config = { diff --git a/spec/fixtures/balancer_utils.lua b/spec/fixtures/balancer_utils.lua index 644d80befb9e..fdac769de7e5 100644 --- a/spec/fixtures/balancer_utils.lua +++ b/spec/fixtures/balancer_utils.lua @@ -4,6 +4,7 @@ local helpers = require "spec.helpers" local utils = require "kong.tools.utils" local kong_table = require "kong.tools.table" local https_server = require "spec.fixtures.https_server" +local uuid = require("kong.tools.uuid").uuid local CONSISTENCY_FREQ = 1 @@ -228,7 +229,7 @@ do end add_certificate = function(bp, data) - local certificate_id = utils.uuid() + local certificate_id = uuid() local req = kong_table.cycle_aware_deep_copy(data) or {} req.id = certificate_id bp.certificates:insert(req) @@ -236,7 +237,7 @@ do end add_upstream = function(bp, data) - local upstream_id = utils.uuid() + local upstream_id = uuid() local req = kong_table.cycle_aware_deep_copy(data) or {} local upstream_name = req.name or gen_sym("upstream") req.name = upstream_name @@ -336,8 +337,8 @@ do add_api = function(bp, upstream_name, opts) opts = opts or {} - local route_id = utils.uuid() - local service_id = utils.uuid() + local route_id = uuid() + local service_id = uuid() local route_host = gen_sym("host") local sproto = opts.service_protocol or opts.route_protocol or "http" local rproto = opts.route_protocol or "http" diff --git a/spec/helpers.lua b/spec/helpers.lua index ed6170ec64fb..57b9fea00da3 100644 --- a/spec/helpers.lua +++ b/spec/helpers.lua @@ -61,7 +61,6 @@ local pl_Set = require "pl.Set" local Schema = require "kong.db.schema" local Entity = require "kong.db.schema.entity" local cjson = require "cjson.safe" -local utils = require "kong.tools.utils" local kong_table = require "kong.tools.table" local http = require "resty.http" local pkey = require "resty.openssl.pkey" @@ -78,6 +77,7 @@ local stress_generator = require "spec.fixtures.stress_generator" local resty_signal = require "resty.signal" local lfs = require "lfs" local luassert = require "luassert.assert" +local uuid = require("kong.tools.uuid").uuid ffi.cdef [[ int setenv(const char *name, const char *value, int overwrite); @@ -594,7 +594,7 @@ local plugins_schema = assert(Entity.new(plugins_schema_def)) local function validate_plugin_config_schema(config, schema_def) assert(plugins_schema:new_subschema(schema_def.name, schema_def)) local entity = { - id = utils.uuid(), + id = uuid(), name = schema_def.name, config = config } @@ -4061,7 +4061,7 @@ local function clustering_client(opts) local c = assert(ws_client:new()) local uri = "wss://" .. opts.host .. ":" .. opts.port .. - "/v1/outlet?node_id=" .. (opts.node_id or utils.uuid()) .. + "/v1/outlet?node_id=" .. (opts.node_id or uuid()) .. "&node_hostname=" .. (opts.node_hostname or kong.node.get_hostname()) .. "&node_version=" .. (opts.node_version or KONG_VERSION)