Skip to content

Commit b862b71

Browse files
authored
Additional Jinja2 sequence/mapping fixes (#194)
1 parent c349901 commit b862b71

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ BUG FIXES:
99
* NGINX listen `so_keepalive` parameter was not working as intended when setting specific values.
1010
* Make sure all template objects are properly transformed into strings before doing Jinja2 operations.
1111
* Remove unnecessary parentheses.
12-
* Fix rewrite option in modules template.
1312

1413
## 0.4.1 (October 25, 2021)
1514

defaults/main/template.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ nginx_config_http_template:
175175
etag: true # Boolean
176176
if_modified_since: exact # Can be set to 'off', 'exact' or 'before'
177177
ignore_invalid_headers: true # Boolean -- Not available in the 'location' context
178-
include: path # Note -- This directive originally belongs in the NGINX core module, but we are making an exception here
178+
include: path # String or list. Note -- This directive originally belongs in the NGINX core module, but we are making an exception here.
179179
index: path # Note -- This directive originally belongs in the NGINX index module, but we are making an exception here
180180
internal: false # Boolean -- Only available in the 'location' context
181181
keepalive_disable: msie6 # String or a list
@@ -685,7 +685,7 @@ nginx_config_http_template:
685685
last_modified: false # Boolean
686686
once: true # Boolean
687687
types: text/html # String or a list
688-
custom_directives: # Custom directive for specific use cases not covered by templates -- you need to add a semi-colon at the end of each directive
688+
custom_directives: # String or list. Custom directive for specific use cases not covered by templates -- you need to add a semi-colon at the end of each directive.
689689
- fastcgi_split_path_info ^(.+\.php)(/.+)$;
690690
- fastcgi_pass unix:/run/php/php7.2-fpm.sock;
691691
servers:

templates/http/auth.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ auth_request_set {{ auth_request['set']['variable'] }} {{ auth_request['set']['v
4848
auth_jwt {{ 'off' if not auth_jwt['enable'] }}{{ auth_jwt['enable']['realm'] if auth_jwt['enable']['realm'] is defined }}{{ (' token=' + auth_jwt['enable']['token'] | string) if auth_jwt['enable']['token'] is defined }};
4949
{% endif %}
5050
{% if auth_jwt['claim_set'] is defined %}{# 'claim_set' is only available in the 'http' context #}
51-
{% for claim in auth_jwt['claim_set'] if (auth_jwt['claim_set'] is not mapping and auth_jwt['claim_set'] is not string) %}
51+
{% for claim in auth_jwt['claim_set'] if auth_jwt['claim_set'] is not mapping %}
5252
auth_jwt_claim_set {{ claim['variable'] }} {{ (claim['name'] if claim['name'] is string else claim['name'] | join(' ')) }};
5353
{% else %}
5454
auth_jwt_claim_set {{ auth_jwt['claim_set']['variable'] }} {{ (auth_jwt['claim_set']['name'] if auth_jwt['claim_set']['name'] is string else auth_jwt['claim_set']['name'] | join(' ')) }};
5555
{% endfor %}
5656
{% endif %}
5757
{% if auth_jwt['header_set'] is defined %}{# 'header_set' is only available in the 'http' context #}
58-
{% for claim in auth_jwt['header_set'] if (auth_jwt['header_set'] is not mapping and auth_jwt['header_set'] is not string) %}
58+
{% for claim in auth_jwt['header_set'] if auth_jwt['header_set'] is not mapping %}
5959
auth_jwt_header_set {{ claim['variable'] }} {{ (claim['name'] if claim['name'] is string else claim['name'] | join(' ')) }};
6060
{% else %}
6161
auth_jwt_header_set {{ auth_jwt['header_set']['variable'] }} {{ (auth_jwt['header_set']['name'] if auth_jwt['header_set']['name'] is string else auth_jwt['header_set']['name'] | join(' ')) }};

templates/http/core.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ if_modified_since {{ 'off' if not core['if_modified_since'] else core['if_modifi
8585
{% if core['ignore_invalid_headers'] is defined and core['ignore_invalid_headers'] is boolean %}{# 'ignore_invalid_headers' directive is not available in the 'location' context #}
8686
ignore_invalid_headers {{ core['ignore_invalid_headers'] | ternary('on', 'off') }};
8787
{% endif %}
88-
{% if core['include'] is defined and (core['include'] is string or core['include'] is sequence) %}{# ngx_core_module #}{# This does not belong here but we are making an exception #}
88+
{% if core['include'] is defined and core['include'] is not mapping %}{# ngx_core_module #}{# This does not belong here but we are making an exception #}
8989
{% for file in core['include'] if core['include'] is not string %}
9090
include {{ file }};
9191
{% else %}

templates/http/default.conf.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
{% from 'http/modules.j2' import sub_filter with context %}
8989
{{ sub_filter(item['config']['sub_filter']) }}
9090
{%- endif %}
91-
{% if item['config']['custom_directives'] is defined and item['config']['custom_directives'] is sequence %}
91+
{% if item['config']['custom_directives'] is defined and item['config']['custom_directives'] is not mapping %}
9292
{% for directive in item['config']['custom_directives'] if item['config']['custom_directives'] is not string %}
9393
{{ directive }}
9494
{% else %}
@@ -222,7 +222,7 @@ server {
222222
{{ sub_filter(server['sub_filter']) }}
223223
{%- endfilter %}
224224
{% endif %}
225-
{% if server['custom_directives'] is defined and server['custom_directives'] is sequence %}
225+
{% if server['custom_directives'] is defined and server['custom_directives'] is not mapping %}
226226
{% for directive in server['custom_directives'] if server['custom_directives'] is not string %}
227227
{% filter indent(4) %}
228228
{{ directive }}
@@ -352,7 +352,7 @@ server {
352352
{{ sub_filter(location['sub_filter']) }}
353353
{%- endfilter %}
354354
{% endif %}
355-
{% if location['custom_directives'] is defined and location['custom_directives'] is sequence %}
355+
{% if location['custom_directives'] is defined and location['custom_directives'] is not mapping %}
356356
{% for directive in location['custom_directives'] if location['custom_directives'] is not string %}
357357
{% filter indent(8) %}
358358
{{ directive }}

templates/http/modules.j2

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,17 @@ open_log_file_cache {{ 'off' if not log['open_log_file_cache'] else ('max=' + lo
199199
return {{ rewrite['return'] if (rewrite['return'] is string or rewrite['return'] is number) }}{{ rewrite['return']['code'] if rewrite['return']['code'] is defined }}{{ (' ' + rewrite['return']['text'] | string) if rewrite['return']['text'] is defined }}{{ (' ' + rewrite['return']['url'] | string) if rewrite['return']['url'] is defined }};
200200
{% endif %}
201201
{% if rewrite['rewrites'] is defined %}{# 'rewrite' directive is not available in the 'http' context #}
202-
{% for rewrite in rewrite['rewrites'] if (rewrite['rewrites'] is not mapping and rewrite['rewrites'] is not string) %}
202+
{% for rewrite in rewrite['rewrites'] if rewrite['rewrites'] is not mapping %}
203203
rewrite {{ rewrite['regex'] }} {{ rewrite['replacement'] }}{{ (' ' + rewrite['flag'] | string) if rewrite['flag'] is defined and rewrite['flag'] in ['last', 'break', 'redirect', 'permanent'] }};
204+
{% else %}
205+
rewrite {{ rewrite['rewrites']['regex'] }} {{ rewrite['rewrites']['replacement'] }}{{ (' ' + rewrite['rewrites']['flag'] | string) if rewrite['rewrites']['flag'] is defined and rewrite['rewrites']['flag'] in ['last', 'break', 'redirect', 'permanent'] }};
204206
{% endfor %}
205207
{% endif %}
206208
{% if rewrite['log'] is defined and rewrite['log'] is boolean %}
207209
rewrite_log {{ rewrite['log'] | ternary('on', 'off') }};
208210
{% endif %}
209211
{% if rewrite['set'] is defined %}{# 'set' directive is not available in the 'http' context #}
210-
{% for set in rewrite['set'] if (rewrite['set'] is not mapping and rewrite['set'] is not string) %}
212+
{% for set in rewrite['set'] if rewrite['set'] is not mapping %}
211213
set {{ set['variable'] }} {{ set['value'] }};
212214
{% else %}
213215
set {{ rewrite['set']['variable'] }} {{ rewrite['set']['value'] }};

0 commit comments

Comments
 (0)