replace some of the Nginx configuration to Lua code
This commit is contained in:
parent
4bee401d16
commit
496ff07bf1
5 changed files with 126 additions and 106 deletions
|
|
@ -132,6 +132,8 @@ var (
|
|||
"buildRateLimitZones": buildRateLimitZones,
|
||||
"buildRateLimit": buildRateLimit,
|
||||
"buildResolversForLua": buildResolversForLua,
|
||||
"configForLua": configForLua,
|
||||
"locationConfigForLua": locationConfigForLua,
|
||||
"buildResolvers": buildResolvers,
|
||||
"buildUpstreamName": buildUpstreamName,
|
||||
"isLocationInLocationList": isLocationInLocationList,
|
||||
|
|
@ -263,6 +265,51 @@ func buildResolversForLua(res interface{}, disableIpv6 interface{}) string {
|
|||
return strings.Join(r, ", ")
|
||||
}
|
||||
|
||||
// configForLua returns some general configuration as Lua table represented as string
|
||||
func configForLua(input interface{}) string {
|
||||
all, ok := input.(config.TemplateConfig)
|
||||
if !ok {
|
||||
klog.Errorf("expected a 'config.TemplateConfig' type but %T was given", input)
|
||||
return "{}"
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`{
|
||||
use_forwarded_headers = %t,
|
||||
is_ssl_passthrough_enabled = %t,
|
||||
http_redirect_code = %v,
|
||||
listen_ports = { ssl_proxy = "%v", https = "%v" },
|
||||
}`, all.Cfg.UseForwardedHeaders, all.IsSSLPassthroughEnabled, all.Cfg.HTTPRedirectCode, all.ListenPorts.SSLProxy, all.ListenPorts.HTTPS)
|
||||
}
|
||||
|
||||
// locationConfigForLua formats some location specific configuration into Lua table represented as string
|
||||
func locationConfigForLua(l interface{}, s interface{}, a interface{}) string {
|
||||
location, ok := l.(*ingress.Location)
|
||||
if !ok {
|
||||
klog.Errorf("expected an '*ingress.Location' type but %T was given", l)
|
||||
return "{}"
|
||||
}
|
||||
|
||||
server, ok := s.(*ingress.Server)
|
||||
if !ok {
|
||||
klog.Errorf("expected an '*ingress.Server' type but %T was given", s)
|
||||
return "{}"
|
||||
}
|
||||
|
||||
all, ok := a.(config.TemplateConfig)
|
||||
if !ok {
|
||||
klog.Errorf("expected a 'config.TemplateConfig' type but %T was given", a)
|
||||
return "{}"
|
||||
}
|
||||
|
||||
forceSSLRedirect := location.Rewrite.ForceSSLRedirect || (len(server.SSLCert.PemFileName) > 0 && location.Rewrite.SSLRedirect)
|
||||
forceSSLRedirect = forceSSLRedirect && !isLocationInLocationList(l, all.Cfg.NoTLSRedirectLocations)
|
||||
|
||||
return fmt.Sprintf(`{
|
||||
force_ssl_redirect = %t,
|
||||
use_port_in_redirects = %t,
|
||||
}`, forceSSLRedirect, location.UsePortInRedirects)
|
||||
}
|
||||
|
||||
// buildResolvers returns the resolvers reading the /etc/resolv.conf file
|
||||
func buildResolvers(res interface{}, disableIpv6 interface{}) string {
|
||||
// NGINX need IPV6 addresses to be surrounded by brackets
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue