set /configuration client body size dynamically
This commit is contained in:
parent
b21c721196
commit
6a293c7e11
3 changed files with 62 additions and 33 deletions
|
@ -133,36 +133,37 @@ var (
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
"escapeLiteralDollar": escapeLiteralDollar,
|
"escapeLiteralDollar": escapeLiteralDollar,
|
||||||
"shouldConfigureLuaRestyWAF": shouldConfigureLuaRestyWAF,
|
"shouldConfigureLuaRestyWAF": shouldConfigureLuaRestyWAF,
|
||||||
"buildLuaSharedDictionaries": buildLuaSharedDictionaries,
|
"buildLuaSharedDictionaries": buildLuaSharedDictionaries,
|
||||||
"buildLocation": buildLocation,
|
"luaConfigurationRequestBodySize": luaConfigurationRequestBodySize,
|
||||||
"buildAuthLocation": buildAuthLocation,
|
"buildLocation": buildLocation,
|
||||||
"shouldApplyGlobalAuth": shouldApplyGlobalAuth,
|
"buildAuthLocation": buildAuthLocation,
|
||||||
"buildAuthResponseHeaders": buildAuthResponseHeaders,
|
"shouldApplyGlobalAuth": shouldApplyGlobalAuth,
|
||||||
"buildProxyPass": buildProxyPass,
|
"buildAuthResponseHeaders": buildAuthResponseHeaders,
|
||||||
"filterRateLimits": filterRateLimits,
|
"buildProxyPass": buildProxyPass,
|
||||||
"buildRateLimitZones": buildRateLimitZones,
|
"filterRateLimits": filterRateLimits,
|
||||||
"buildRateLimit": buildRateLimit,
|
"buildRateLimitZones": buildRateLimitZones,
|
||||||
"configForLua": configForLua,
|
"buildRateLimit": buildRateLimit,
|
||||||
"locationConfigForLua": locationConfigForLua,
|
"configForLua": configForLua,
|
||||||
"buildResolvers": buildResolvers,
|
"locationConfigForLua": locationConfigForLua,
|
||||||
"buildUpstreamName": buildUpstreamName,
|
"buildResolvers": buildResolvers,
|
||||||
"isLocationInLocationList": isLocationInLocationList,
|
"buildUpstreamName": buildUpstreamName,
|
||||||
"isLocationAllowed": isLocationAllowed,
|
"isLocationInLocationList": isLocationInLocationList,
|
||||||
"buildLogFormatUpstream": buildLogFormatUpstream,
|
"isLocationAllowed": isLocationAllowed,
|
||||||
"buildDenyVariable": buildDenyVariable,
|
"buildLogFormatUpstream": buildLogFormatUpstream,
|
||||||
"getenv": os.Getenv,
|
"buildDenyVariable": buildDenyVariable,
|
||||||
"contains": strings.Contains,
|
"getenv": os.Getenv,
|
||||||
"hasPrefix": strings.HasPrefix,
|
"contains": strings.Contains,
|
||||||
"hasSuffix": strings.HasSuffix,
|
"hasPrefix": strings.HasPrefix,
|
||||||
"trimSpace": strings.TrimSpace,
|
"hasSuffix": strings.HasSuffix,
|
||||||
"toUpper": strings.ToUpper,
|
"trimSpace": strings.TrimSpace,
|
||||||
"toLower": strings.ToLower,
|
"toUpper": strings.ToUpper,
|
||||||
"formatIP": formatIP,
|
"toLower": strings.ToLower,
|
||||||
"quote": quote,
|
"formatIP": formatIP,
|
||||||
"buildNextUpstream": buildNextUpstream,
|
"quote": quote,
|
||||||
"getIngressInformation": getIngressInformation,
|
"buildNextUpstream": buildNextUpstream,
|
||||||
|
"getIngressInformation": getIngressInformation,
|
||||||
"serverConfig": func(all config.TemplateConfig, server *ingress.Server) interface{} {
|
"serverConfig": func(all config.TemplateConfig, server *ingress.Server) interface{} {
|
||||||
return struct{ First, Second interface{} }{all, server}
|
return struct{ First, Second interface{} }{all, server}
|
||||||
},
|
},
|
||||||
|
@ -272,6 +273,22 @@ func buildLuaSharedDictionaries(c interface{}, s interface{}, disableLuaRestyWAF
|
||||||
return strings.Join(out, ";\n") + ";\n"
|
return strings.Join(out, ";\n") + ";\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func luaConfigurationRequestBodySize(c interface{}) string {
|
||||||
|
cfg, ok := c.(config.Configuration)
|
||||||
|
if !ok {
|
||||||
|
klog.Errorf("expected a 'config.Configuration' type but %T was returned", c)
|
||||||
|
return "100" // just a default number
|
||||||
|
}
|
||||||
|
|
||||||
|
size := cfg.LuaSharedDicts["configuration_data"]
|
||||||
|
if size < cfg.LuaSharedDicts["certificate_data"] {
|
||||||
|
size = cfg.LuaSharedDicts["certificate_data"]
|
||||||
|
}
|
||||||
|
size = size + 1
|
||||||
|
|
||||||
|
return fmt.Sprintf("%d", size)
|
||||||
|
}
|
||||||
|
|
||||||
// configForLua returns some general configuration as Lua table represented as string
|
// configForLua returns some general configuration as Lua table represented as string
|
||||||
func configForLua(input interface{}) string {
|
func configForLua(input interface{}) string {
|
||||||
all, ok := input.(config.TemplateConfig)
|
all, ok := input.(config.TemplateConfig)
|
||||||
|
|
|
@ -225,6 +225,19 @@ func TestBuildLuaSharedDictionaries(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLuaConfigurationRequestBodySize(t *testing.T) {
|
||||||
|
cfg := config.Configuration{
|
||||||
|
LuaSharedDicts: map[string]int{
|
||||||
|
"configuration_data": 10, "certificate_data": 20,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
size := luaConfigurationRequestBodySize(cfg)
|
||||||
|
if "21" != size {
|
||||||
|
t.Errorf("expected the size to be 20 but got: %v", size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFormatIP(t *testing.T) {
|
func TestFormatIP(t *testing.T) {
|
||||||
cases := map[string]struct {
|
cases := map[string]struct {
|
||||||
Input, Output string
|
Input, Output string
|
||||||
|
|
|
@ -580,9 +580,8 @@ http {
|
||||||
}
|
}
|
||||||
|
|
||||||
location /configuration {
|
location /configuration {
|
||||||
# this should be equals to configuration_data dict
|
client_max_body_size {{ luaConfigurationRequestBodySize $cfg }}m;
|
||||||
client_max_body_size 10m;
|
client_body_buffer_size {{ luaConfigurationRequestBodySize $cfg }}m;
|
||||||
client_body_buffer_size 10m;
|
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
|
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
|
|
Loading…
Reference in a new issue