Skip to content

Commit 1815b26

Browse files
ericnorrisfacebook-github-bot
authored andcommitted
fix(fb_apache): render arrays inside of hash configs (facebook#218)
Summary: ## Description This PR fixes a bug where the `template_hash_handler` in `fb_apache` silently skips over `Array` values. Now these values are rendered as if they were in the top-level `VirtualHost` directive. For example: ```ruby { ... 'Location /foo' => { 'Header' => [ 'unset Bar', 'unset Baz', ], ... ``` ...will now properly include multiple `Header ...` lines in the `Location /foo` directive. ## Impact These values were ignored previously, so it is possible that it would cause changes in hosts where this was happening. Pull Request resolved: facebook#218 Differential Revision: D45869664 fbshipit-source-id: 947ec76843416d411d4288c23bba4125de163185
1 parent e754f43 commit 1815b26

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

cookbooks/fb_apache/libraries/default.rb

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,55 @@ def self.indentstr(indent)
2828
' ' * indent
2929
end
3030

31-
# Map a hash to a apache-style syntax
32-
def self.template_hash_handler(buf, indent, kw, data)
33-
if HANDLERS.keys.include?(kw)
34-
self.send(HANDLERS[kw], buf, indent, kw, data)
35-
return
36-
end
37-
buf << indentstr(indent)
38-
buf << "<#{kw}>\n"
39-
data.each do |key, val|
31+
def self.render_apache_conf(buf, depth, config)
32+
config.each do |kw, val|
33+
if HANDLERS.keys.include?(kw)
34+
self.send(HANDLERS[kw], buf, depth, val)
35+
next
36+
end
37+
38+
indent = indentstr(depth)
39+
4040
case val
41-
when String
42-
buf << indentstr(indent + 1)
43-
buf << "#{key} #{val}\n"
41+
when String, Integer
42+
buf << indent
43+
buf << "#{kw} #{val}\n"
44+
45+
when Array
46+
val.each do |entry|
47+
buf << indent
48+
buf << "#{kw} #{entry}\n"
49+
end
50+
4451
when Hash
45-
template_hash_handler(buf, indent + 1, key, val)
52+
buf << indent
53+
buf << "<#{kw}>\n"
54+
55+
render_apache_conf(buf, depth + 1, val)
56+
57+
buf << indent
58+
buf << "</#{kw.split[0]}>\n"
59+
60+
else
61+
fail "fb_apache: bad type for value of #{kw}: #{val.class}"
4662
end
4763
end
48-
buf << indentstr(indent)
49-
buf << "</#{kw.split[0]}>\n"
5064
end
5165

5266
# Helper for rewrite syntax
53-
def self.template_rewrite_helper(buf, _indent, _key, rules)
67+
def self.template_rewrite_helper(buf, depth, rules)
68+
indent = indentstr(depth)
69+
5470
rules.each do |name, ruleset|
55-
buf << indentstr(1)
71+
buf << indent
5672
buf << "# #{name}\n"
73+
5774
ruleset['conditions']&.each do |cond|
58-
buf << indentstr(1)
75+
buf << indent
5976
buf << "RewriteCond #{cond}\n"
6077
end
61-
buf << indentstr(1)
78+
79+
buf << indent
6280
buf << "RewriteRule #{ruleset['rule']}\n\n"
6381
end
6482
end

cookbooks/fb_apache/templates/default/apache_conf.erb

Lines changed: 0 additions & 14 deletions
This file was deleted.

cookbooks/fb_apache/templates/default/fb_apache.conf.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
<%= render 'apache_modules.erb' %>
44

55
<% end %>
6-
<%= render 'apache_conf.erb',
7-
:variables => {:conf => node['fb_apache']['extra_configs']} %>
6+
<% FB::Apache.render_apache_conf(_buf, 0, node['fb_apache']['extra_configs']) %>

cookbooks/fb_apache/templates/default/fb_sites.conf.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<% realvhost = conf['_virtualhost'] || vhost %>
44
<VirtualHost <%= realvhost %>>
55
<% conf.reject! { |x, y| x == '_virtualhost' } %>
6-
<%= render 'apache_conf.erb', :variables => {:conf => conf} %>
6+
<% FB::Apache.render_apache_conf(_buf, 1, conf) %>
77
</VirtualHost>
88

99
<% end %>

0 commit comments

Comments
 (0)