Add apiId to access logs
diff --git a/conf.d/api_gateway_logging.conf b/conf.d/api_gateway_logging.conf
index 3b93eab..a988c6e 100644
--- a/conf.d/api_gateway_logging.conf
+++ b/conf.d/api_gateway_logging.conf
@@ -29,4 +29,5 @@
'status=$status bbs=$body_bytes_sent rl=$request_length rt=$request_time hr="$http_referer" '
'ua="$http_user_agent" xfwdf="$http_x_forwarded_for" '
'upadd="$upstream_addr" upstat=$upstream_status uprt=$upstream_response_time '
- 'tenantId="$tenant" tenantNamespace="$tenantNamespace" tenantInstance="$tenantInstance" reqid="$requestId"';
\ No newline at end of file
+ 'tenantId="$tenant" tenantNamespace="$tenantNamespace" tenantInstance="$tenantInstance" '
+ 'apiId="$apiId" reqid="$requestId"';
diff --git a/conf.d/managed_endpoints.conf b/conf.d/managed_endpoints.conf
index 5530112..bac8c7a 100644
--- a/conf.d/managed_endpoints.conf
+++ b/conf.d/managed_endpoints.conf
@@ -64,22 +64,23 @@
set $tenant $1;
set $tenantNamespace '';
set $tenantInstance '';
+ set $apiId '';
set $backendUrl '';
set $gatewayPath $2;
set $cors '';
set $cors_methods '';
-
+
access_by_lua_block {
local routing = require "routing"
routing.processCall()
local cors = require "cors"
ngx.var.cors, ngx.var.cors_methods = cors.processCall(ngx.var["tenant"], ngx.var["gatewayPath"])
}
-
+
proxy_pass $upstream;
-
+
header_filter_by_lua_block {
- if ngx.var.cors ~= nil then
+ if ngx.var.cors ~= nil then
if ngx.var.cors == 'false' then
ngx.header['Access-Control-Allow-Origin'] = nil
ngx.header['Access-Control-Allow-Methods'] = nil
@@ -91,7 +92,7 @@
ngx.header['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS'
end
end
- end
+ end
}
}
diff --git a/scripts/lua/policies/rateLimit.lua b/scripts/lua/policies/rateLimit.lua
index 8da8783..207a4fa 100644
--- a/scripts/lua/policies/rateLimit.lua
+++ b/scripts/lua/policies/rateLimit.lua
@@ -47,10 +47,8 @@
if obj.scope == 'tenant' then
k = utils.concatStrings({"tenant:", tenantId})
elseif obj.scope == 'api' then
- local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 10000)
- local apiId = redis.resourceToApi(red, utils.concatStrings({'resources:', tenantId, ':', gatewayPath}))
+ local apiId = ngx.var.apiId
k = utils.concatStrings({"tenant:", tenantId, ":api:", apiId})
- redis.close(red)
elseif obj.scope == 'resource' then
k = utils.concatStrings({"tenant:", tenantId, ":resource:", gatewayPath})
end
diff --git a/scripts/lua/routing.lua b/scripts/lua/routing.lua
index bfcc50a..dc25207 100644
--- a/scripts/lua/routing.lua
+++ b/scripts/lua/routing.lua
@@ -52,6 +52,7 @@
redis.close(red)
ngx.var.tenantNamespace = obj.tenantNamespace
ngx.var.tenantInstance = obj.tenantInstance
+ ngx.var.apiId = obj.apiId
for verb, opFields in pairs(obj.operations) do
if string.upper(verb) == ngx.req.get_method() then
-- Check if auth is required
@@ -60,7 +61,7 @@
for _, sec in ipairs(opFields.security) do
local result = utils.concatStrings({key, security.process(sec)})
if key == nil then
- key = result -- use the key from the first policy.
+ key = result -- use the key from the first policy.
end
end
end