From 44653750b9f791d8fcd8ffd08e55094092dc5177 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Tue, 30 Jul 2024 09:48:41 -0700 Subject: [PATCH] put the socket subdir name into a constant --- kong/conf_loader/init.lua | 3 ++- kong/constants.lua | 2 ++ kong/runloop/events.lua | 3 ++- kong/tools/stream_api.lua | 4 +++- spec/helpers.lua | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/kong/conf_loader/init.lua b/kong/conf_loader/init.lua index e09d3e6e85f..14353cd4665 100644 --- a/kong/conf_loader/init.lua +++ b/kong/conf_loader/init.lua @@ -17,6 +17,7 @@ local pl_path = require "pl.path" local tablex = require "pl.tablex" local log = require "kong.cmd.utils.log" local env = require "kong.cmd.utils.env" +local constants = require "kong.constants" local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy @@ -484,7 +485,7 @@ local function load(path, custom_conf, opts) -- the socket path is where we store listening unix sockets for IPC and -- private APIs - conf.socket_path = pl_path.join(conf.prefix, "sockets") + conf.socket_path = pl_path.join(conf.prefix, constants.SOCKET_DIRECTORY) if conf.lua_ssl_trusted_certificate and #conf.lua_ssl_trusted_certificate > 0 then diff --git a/kong/constants.lua b/kong/constants.lua index 63df1f2f5a4..33b8dcaa0aa 100644 --- a/kong/constants.lua +++ b/kong/constants.lua @@ -280,6 +280,8 @@ local constants = { service = "upstream", } }, + + SOCKET_DIRECTORY = "sockets", } for _, v in ipairs(constants.CLUSTERING_SYNC_STATUS) do diff --git a/kong/runloop/events.lua b/kong/runloop/events.lua index eeccd9e6a87..7c4a7aaecf7 100644 --- a/kong/runloop/events.lua +++ b/kong/runloop/events.lua @@ -514,7 +514,8 @@ do if not socket_path then -- `kong.configuration.socket_path` is already normalized to an absolute -- path, but `ngx.config.prefix()` is not - socket_path = require("pl.path").abspath(ngx.config.prefix() .. "/sockets") + socket_path = require("pl.path").abspath(ngx.config.prefix() .. "/" + .. constants.SOCKET_DIRECTORY) end local STREAM_CONFIG_SOCK = "unix:" .. socket_path .. "/stream_config.sock" diff --git a/kong/tools/stream_api.lua b/kong/tools/stream_api.lua index 0fc0ae0846a..ac8d7c09b77 100644 --- a/kong/tools/stream_api.lua +++ b/kong/tools/stream_api.lua @@ -3,6 +3,7 @@ -- may changed or be removed in the future Kong releases once a better mechanism -- for inter subsystem communication in OpenResty became available. +local constants = require "kong.constants" local lpack = require "lua_pack" local kong = kong @@ -38,7 +39,8 @@ local MAX_DATA_LEN = 2^22 - 1 local HEADER_LEN = #st_pack(PACK_F, MAX_KEY_LEN, MAX_DATA_LEN) -- this module may be loaded before `kong.configuration` is initialized -local SOCKET_PATH = "unix:" .. ngx.config.prefix() .. "/sockets/stream_rpc.sock" +local SOCKET_PATH = "unix:" .. ngx.config.prefix() .. "/" + .. constants.SOCKET_DIRECTORY .. "/stream_rpc.sock" local stream_api = {} diff --git a/spec/helpers.lua b/spec/helpers.lua index 57733a0c047..5fb537e8c6e 100644 --- a/spec/helpers.lua +++ b/spec/helpers.lua @@ -3844,7 +3844,7 @@ end local function cleanup_kong(prefix, preserve_prefix, preserve_dc) -- remove socket files to ensure `pl.dir.rmtree()` ok prefix = prefix or conf.prefix - local socket_path = pl_path.join(prefix, "sockets") + local socket_path = pl_path.join(prefix, constants.SOCKET_DIRECTORY) for child in lfs.dir(socket_path) do if child:sub(-5) == ".sock" then local path = pl_path.join(socket_path, child)