Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add /schemas/vaults/:name endpoint #11727

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/11727.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "Add a new endpoint `/schemas/vaults/:name` to retrieve the schema of a vault."
type: feature
scope: Core
13 changes: 13 additions & 0 deletions kong/api/routes/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ return {
return validate_schema(db_entity_name, self.params)
end
},

["/schemas/vaults/:name"] = {
GET = function(self, db, helpers)
local subschema = kong.db.vaults.schema.subschemas[self.params.name]
if not subschema then
return kong.response.exit(404, { message = "No vault named '"
.. self.params.name .. "'" })
end
local copy = api_helpers.schema_to_jsonable(subschema)
strip_foreign_schemas(copy.fields)
return kong.response.exit(200, copy)
end
},
["/schemas/plugins/:name"] = {
GET = function(self, db, helpers)
local subschema = kong.db.plugins.schema.subschemas[self.params.name]
Expand Down
2 changes: 1 addition & 1 deletion kong/vaults/env/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ return {
config = {
type = "record",
fields = {
{ prefix = { type = "string", match = [[^[%a_-][%a%d_-]*$]] } },
{ prefix = { type = "string", match = [[^[%a_-][%a%d_-]*$]], description = "The prefix for the environment variable that the value will be stored in." } },
},
},
},
Expand Down
24 changes: 24 additions & 0 deletions spec/02-integration/04-admin_api/02-kong_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,30 @@ describe("Admin API - Kong routes with strategy #" .. strategy, function()
end)
end)

describe("/schemas/vaults/:name", function()
it("returns schema of all vaults", function()
for _, vault in ipairs({"env"}) do
local res = assert(client:send {
method = "GET",
path = "/schemas/vaults/" .. vault,
})
local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.is_table(json.fields)
end
end)

it("returns 404 on a non-existent vault", function()
local res = assert(client:send {
method = "GET",
path = "/schemas/vaults/not-present",
})
local body = assert.res_status(404, res)
local json = cjson.decode(body)
assert.same({ message = "No vault named 'not-present'" }, json)
end)
end)

describe("/schemas/:entity", function()
it("returns schema of all plugins", function()
for plugin, _ in pairs(helpers.test_conf.loaded_plugins) do
Expand Down