Skip to content

Commit

Permalink
get_default_workspace, fix 02-cmd/14-vault_spec.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Sep 26, 2024
1 parent 56ae93b commit c950a2b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
19 changes: 17 additions & 2 deletions kong/db/strategies/off/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ local _mt = {}
_mt.__index = _mt


local DEFAULT_WORKSPACE_ID = "00000000-0000-0000-0000-000000000000"


local function get_default_workspace()
local ws_id = kong.default_workspace

if ws_id == DEFAULT_WORKSPACE_ID then
local res = assert(kong.db.workspaces:select_by_name("default"))
ws_id = res.id
end

return ws_id
end


local function process_ttl_field(entity)
if entity and entity.ttl and entity.ttl ~= null then
local ttl_value = entity.ttl - ngx.time()
Expand Down Expand Up @@ -209,7 +224,7 @@ local function select_by_field(self, field, value, options)
assert(not options or options.workspace ~= null or unique_across_ws)

if unique_across_ws then
ws_id = kong.default_workspace
ws_id = get_default_workspace()
end

key = unique_field_key(schema.name, ws_id, field, value)
Expand Down Expand Up @@ -275,7 +290,7 @@ function off.new(connector, schema, errors)
-- This is not the id for the default workspace in DB-less.
-- This is a sentinel value for the init() phase before
-- the declarative config is actually loaded.
kong.default_workspace = "00000000-0000-0000-0000-000000000000"
kong.default_workspace = DEFAULT_WORKSPACE_ID
end

local name = schema.name
Expand Down
7 changes: 2 additions & 5 deletions spec/02-integration/02-cmd/14-vault_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ describe("kong vault #" .. strategy, function()
end)

describe("[env] instantiated #" .. strategy, function()
-- XXX FIXME
local skip_off_strategy = strategy == "off" and pending or it

local db, _, yaml_file
lazy_setup(function()
_, db = helpers.get_db_utils(strategy, {
Expand Down Expand Up @@ -137,7 +134,7 @@ describe("kong vault #" .. strategy, function()
helpers.stop_kong()
end)

skip_off_strategy("vault get env", function()
it("vault get env", function()
finally(function()
helpers.unsetenv("SECRETS_TEST")
end)
Expand All @@ -152,7 +149,7 @@ describe("kong vault #" .. strategy, function()
assert.is_true(ok)
end)

skip_off_strategy("vault get non-existing env", function()
it("vault get non-existing env", function()
if strategy == "off" then
return
end
Expand Down

0 comments on commit c950a2b

Please sign in to comment.