Skip to content

Commit b6482dc

Browse files
committed
added the missing response for 429 in the decorator and also did a small improvement in the validatorsHandler and validator classes
1 parent 1585bd0 commit b6482dc

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/lua/api-gateway/validation/validator.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ end
114114
-- the method uses HSET redis command --
115115
-- it retuns true if the information is saved in the cache, false otherwise --
116116
function BaseValidator:setKeyInRedis(key, hash_name, keyexpires, value)
117+
ngx.log(ngx.DEBUG, "Storing in Redis the key [", tostring(key), "], expireat=", tostring(keyexpires), ", value=", tostring(value) )
117118
local rediss = redis:new()
118119
local redis_host, redis_port = self:getRedisUpstream(redis_RW_upstream)
119120
local ok, err = rediss:connect(redis_host, redis_port)

src/lua/api-gateway/validation/validatorsHandler.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ function ValidatorsHandler:new(o)
6161
return o
6262
end
6363

64-
function ValidatorsHandler:getValidatorsList()
65-
return
66-
{ validate_api_key = {
64+
local DEFAULT_VALIDATORS = {
65+
validate_api_key = {
6766
defaultProperties = {
6867
path = '/validate_api_key', order=1
6968
}
@@ -107,7 +106,10 @@ function ValidatorsHandler:getValidatorsList()
107106
request_validator_2 = { defaultProperties = { path = '/request_validator-2', order=1 } },
108107
request_validator_3 = { defaultProperties = { path = '/request_validator-3', order=1 } },
109108
request_validator_4 = { defaultProperties = { path = '/request_validator-4', order=1 } }
110-
}
109+
}
110+
111+
function ValidatorsHandler:getValidatorsList()
112+
return DEFAULT_VALIDATORS
111113
end
112114

113115
function ValidatorsHandler:trim(s)
@@ -120,7 +122,8 @@ function ValidatorsHandler:getValidatorsFromConfiguration( localContext )
120122
local defined_props = {}
121123
local request_props = {}
122124

123-
for validator_prop_name, validator_default_props in pairs(self:getValidatorsList()) do
125+
local validatorsList = self:getValidatorsList()
126+
for validator_prop_name, validator_default_props in pairs(validatorsList) do
124127
request_validator = {}
125128
defined_props = ngx.var[validator_prop_name]
126129
if ( defined_props ~= nil and self:trim(defined_props):sub(1,2) == "on") then

src/lua/api-gateway/validation/validatorsHandlerErrorDecorator.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ local DEFAULT_RESPONSES = {
6161
-- Service limit errrors
6262
LIMIT_EXCEEDED = { http_status = 429, error_code = 429001, message = '{"error_code":"429001","message":"Service usage limit reached"}' , headers = { ["X-Request-Id"] = "ngx.var.requestId" }},
6363
DEV_KEY_LIMIT_EXCEEDED = { http_status = 429, error_code = 429002, message = '{"error_code":"429002","message":"Developer key usage limit reached"}' , headers = { ["X-Request-Id"] = "ngx.var.requestId" }},
64+
BLOCK_REQUEST = { http_status = 429, error_code = 429050, message = '{"error_code":"429050","message":"Too many requests"}' , headers = { ["X-Request-Id"] = "ngx.var.requestId" }},
6465
-- App valdations
6566
DELAY_CLIENT_ON_REQUEST = { http_status = 503, error_code = 503071, messsage = '', headers = { ["Retry_After"] = "300s" } , headers = { ["X-Request-Id"] = "ngx.var.requestId" }},
6667
-- CC Link validation

test/perl/api-gateway/validation/validatorHandler.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ custom-header-2: this is a lua variable",
428428
--- http_config eval: $::HttpConfig
429429
--- config
430430
include ../../api-gateway/default_validators.conf;
431+
error_log ../test-logs/validatorHandler_test7_error.log debug;
431432
432433
location /validator_1 {
433434
return 200;

0 commit comments

Comments
 (0)