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(http-log): support http_endpoint field to be referenceable #9714

Merged
merged 3 commits into from
Dec 7, 2022
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.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
- **OpenTelemetry**: add referenceable attribute to the `headers` field
that could be stored in vaults.
[#9611](https://github.com/Kong/kong/pull/9611)
- **HTTP-Log**: Support `http_endpoint` field to be referenceable
[#9714](https://github.com/Kong/kong/pull/9714)


#### Hybrid Mode

Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/http-log/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ return {
type = "record",
fields = {
-- NOTE: any field added here must be also included in the handler's get_queue_id method
{ http_endpoint = typedefs.url({ required = true, encrypted = true }) }, -- encrypted = true is a Kong-Enterprise exclusive feature, does nothing in Kong CE
{ http_endpoint = typedefs.url({ required = true, encrypted = true, referenceable = true }) }, -- encrypted = true is a Kong-Enterprise exclusive feature, does nothing in Kong CE
{ method = { type = "string", default = "POST", one_of = { "POST", "PUT", "PATCH" }, }, },
{ content_type = { type = "string", default = "application/json", one_of = { "application/json" }, }, },
{ timeout = { type = "number", default = 10000 }, },
Expand Down
45 changes: 45 additions & 0 deletions spec/03-plugins/03-http-log/03-schem-vault_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
local helpers = require "spec.helpers"
local Entity = require "kong.db.schema.entity"
local plugins_schema_def = require "kong.db.schema.entities.plugins"
local conf_loader = require "kong.conf_loader"

local PLUGIN_NAME = "http-log"


describe(PLUGIN_NAME .. ": (schema-vault)", function()
local plugins_schema = assert(Entity.new(plugins_schema_def))

lazy_setup(function()
local conf = assert(conf_loader(nil, {
vaults = "bundled",
plugins = "bundled",
}))

local kong_global = require "kong.global"
_G.kong = kong_global.new()
kong_global.init_pdk(kong, conf)

local plugin_schema = require("kong.plugins."..PLUGIN_NAME..".schema")
assert(plugins_schema:new_subschema(PLUGIN_NAME, plugin_schema))
end)

it("should dereference vault value", function()
local env_name = "HTTP_LOG_HTTP_ENDPOINT"
local env_value = "http://example.com"

finally(function()
helpers.unsetenv(env_name)
end)

helpers.setenv(env_name, env_value)

local entity = plugins_schema:process_auto_fields({
name = PLUGIN_NAME,
config = {
http_endpoint = "{vault://env/http-log-http-endpoint}"
},
}, "select")

assert.equal(env_value, entity.config.http_endpoint)
end)
end)