diff --git a/kong/db/dao/vaults.lua b/kong/db/dao/vaults.lua index 1c7238b15b9..477f6960d7d 100644 --- a/kong/db/dao/vaults.lua +++ b/kong/db/dao/vaults.lua @@ -84,4 +84,14 @@ function Vaults:load_vault_schemas(vault_set) end +function Vaults:cache_key(prefix) + if type(prefix) == "table" then + prefix = prefix.prefix + end + + -- Always return the cache_key without a workspace because prefix is unique across workspaces + return "vaults:" .. prefix .. ":::::" +end + + return Vaults diff --git a/spec/02-integration/13-vaults/01-vault_spec.lua b/spec/02-integration/13-vaults/01-vault_spec.lua index 0457923e7c6..dd5a58c6de4 100644 --- a/spec/02-integration/13-vaults/01-vault_spec.lua +++ b/spec/02-integration/13-vaults/01-vault_spec.lua @@ -175,5 +175,10 @@ for _, strategy in helpers.each_strategy() do assert.is_equal("{vault://unknown/missing-key}", certificate.key_alt) assert.is_nil(certificate["$refs"]) end) + + it("generate correct cache key", function () + local cache_key = db.vaults:cache_key("test") + assert.equal("vaults:test:::::", cache_key) + end) end) end