Skip to content

Commit

Permalink
feat(llm): add auth.can_override option for llm auth functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
oowl committed Aug 12, 2024
1 parent 12e2481 commit 31c7c09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions kong/llm/drivers/anthropic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,18 @@ function _M.configure_request(conf)
local auth_param_location = conf.auth and conf.auth.param_location

if auth_header_name and auth_header_value then
kong.service.request.set_header(auth_header_name, auth_header_value)
local exist_value = kong.request.get_header(auth_header_name)
if exist_value == nil or not conf.auth.can_override then
kong.service.request.set_header(auth_header_name, auth_header_value)
end
end

if auth_param_name and auth_param_value and auth_param_location == "query" then
local query_table = kong.request.get_query()
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
if query_table[auth_param_name] == nil or not conf.auth.can_override then
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
end
end

-- if auth_param_location is "form", it will have already been set in a pre-request hook
Expand Down
5 changes: 5 additions & 0 deletions kong/llm/schemas/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ local auth_schema = {
required = false,
encrypted = true,
referenceable = true }},
{ can_override = {
type = "boolean",
description = "If enabled, the auth header or param can be overridden by the request.",
required = false,
default = true }},
}
}

Expand Down

0 comments on commit 31c7c09

Please sign in to comment.