{% macro simple_item_list(item_list, indent=bind9_config_indent) %} {# This macro is for use in simple address lists #} {% filter indent(indent, true) %} {{ item_list | join(';\n') }}; {% endfilter %} {% endmacro %} {% macro list_address_port_key_tls(dict, indent=bind9_config_indent) %} {% filter indent(indent, true) %} {% for item in dict %} {% if item is not mapping %} {{ item -}}; {% else %} {{ item.address -}} {{- (' port ' + item.port | string) if item.port is defined -}} {{- (' key ' + item.key | string) if item.key is defined -}} {{- (' tls ' + item.tls | string) if item.tls is defined -}}; {% endif %} {% endfor %} {% endfilter %} {% endmacro %} {% macro parent_address_key_tls(name, dict) %} {# This macro is for use for statements with grammar like #} {# statement port 00 dscp 00 { address port 00 key str tls str; address port 00 key str tls str; } #} {# the list inside the statement is handled by list_address_port_key_tls #} {% if dict is not mapping and dict is iterable %} {{ name }} { {{ list_address_port_key_tls(dict) }}}; {% else %} {{ name }} {{- (' port ' + dict.port | string) if dict.port is defined and dict.port -}} {{- (' dscp ' + dict.dscp | string) if dict.dscp is defined and dict.dscp }} { {{ list_address_port_key_tls(dict.addresses) }}}; {% endif %} {% endmacro %} {% macro list_address_port_dscp(dict, indent=bind9_config_indent) %} {# This macro is for use for statements with grammar like #} {# address port 00 dscp 00; address port 00 dscp 00; #} {# it is usually called by a parent macro #} {% filter indent(indent, true) %} {% for item in dict %} {% if item is not mapping %} {{ item }}; {% else %} {{ item.address }} {{- (' port ' + item.port | string) if item.port is defined and item.port -}} {{- (' dscp ' + item.dscp | string) if item.dscp is defined and item.dscp -}}; {% endif %} {% endfor %} {% endfilter %} {% endmacro %} {% macro parent_address_port_dscp(name, dict) %} {# This macro is for use for statements with grammar like #} {# statement port 00 dscp 00 { address port 00 dscp 00; address port 00 dscp 00; } #} {# the list inside the statement is handled by list_address_port #} {% if dict is not mapping and dict is iterable %} {{ name }} { {{ list_address_port_dscp(dict) }}}; {% else %} {{ name }} {{- (' port ' + dict.port | string) if dict.port is defined and dict.port -}} {{- (' dscp ' + dict.dscp | string) if dict.dscp is defined and dict.dscp }} { {{ list_address_port_dscp(dict.addresses) }}}; {% endif %} {% endmacro %} {% macro single_ip_port_dscp(name, dict) %} {# This macro is for the "statement ip(v6) [port xx] [dscp xx] statements "#} {{ name }} {{ dict.address -}} {{- (' port ' + dict.port | string) if dict.port is defined and dict.port -}} {{- (' dscp ' + dict.dscp | string) if dict.dscp is defined and dict.dscp }}; {% endmacro %} {% macro boolean_option(name, value) %} {# Converts YAML booleans "True" and "False" into bind9 "yes "and "no" #} {{ name }} {{ named_boolean(value) }}; {%- endmacro %} {% macro named_boolean(value) %} {# input: value: YAML boolean #} {# output: str: yes or no #} {{- value | ternary('yes', 'no') | string -}} {% endmacro %} {% macro boolean_or_string(value) %} {# input: value: boolean or string #} {# output: str: ((yes or no) or input) #} {% if value is boolean -%} {{- named_boolean(value) -}} {% else %} {{- (value | string) -}} {% endif %} {% endmacro %} {% macro reserved_or_quoted(name, value, reserved_keywords) %} {# reserved_or_quoted checks if value contains a reserved keyword, #} {# then prints it without quotes if it's reserved, or quoted if it is not #} {% if value in reserved_keywords %} {{ name }} {{ value }}; {% else %} {{ name }} "{{ value }}"; {% endif %} {% endmacro %}