Skip to content

Commit

Permalink
feat(core): add /schemas/vaults/:name endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Schmid <[email protected]>
  • Loading branch information
jschmid1 committed Oct 10, 2023
1 parent f3094a0 commit ea147e2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
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 plugin", 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

0 comments on commit ea147e2

Please sign in to comment.