Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# -*- coding: utf-8 -*-

def flatten(d, separator='.'):
def haproxy_flatten(d, separator='.'):
"""
Flatten a dictionary `d` by joining nested keys with `separator`.

Slightly modified from <http://codereview.stackexchange.com/a/21035>.

>>> flatten({'eggs': 'spam', 'sausage': {'eggs': 'bacon'}, 'spam': {'bacon': {'sausage': 'spam'}}})
>>> haproxy_flatten({'eggs': 'spam', 'sausage': {'eggs': 'bacon'}, 'spam': {'bacon': {'sausage': 'spam'}}})
{'spam.bacon.sausage': 'spam', 'eggs': 'spam', 'sausage.eggs': 'bacon'}
"""
def items():
for k, v in d.items():
try:
for sub_k, sub_v in flatten(v, separator).items():
for sub_k, sub_v in haproxy_flatten(v, separator).items():
yield separator.join([k, sub_k]), sub_v
except AttributeError:
yield k, v
Expand All @@ -21,4 +21,4 @@ def items():

class FilterModule(object):
def filters(self):
return {'flatten': flatten}
return {'haproxy_flatten': haproxy_flatten}
2 changes: 1 addition & 1 deletion templates/global.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ global
ssl-default-server-ciphers {{ haproxy_global.ssl_default_server_ciphers }}
{% endif -%}
{% if haproxy_global.tune is defined %}
{% for param, value in (haproxy_global.tune | flatten).items() -%}
{% for param, value in (haproxy_global.tune | haproxy_flatten).items() -%}
tune.{{ param }} {{ value }}
{% endfor -%}
{% endif %}