Skip to content

Commit 8c562d9

Browse files
Merge pull request #3 from netmanagers/master
Fix nested blocks parsing in the config file
2 parents 4944cdb + 782acd8 commit 8c562d9

10 files changed

Lines changed: 163 additions & 34 deletions

File tree

caddy/files/default/Caddyfile.tmpl.jinja

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
{%- for k, v in value.items() -%}
88
{%- if v is number or v is string -%}
99
{{ server_config([v], k, ind) }}
10-
{%- elif v|length() > 0 and (v[0] is number or v[0] is string) -%}
11-
{{ server_config(v, k, ind) }}
12-
{%- else -%}
10+
{%- elif v is iterable and v is not string -%}
1311
{{ '\t' * ind }}{{ k }}{{ operator }}{{ '{' }}
1412
{{ server_config(v, ind = ind + ind_increment) }}
1513
{{- '\t' * ind }}{{ '}' }}{{ lb }}
14+
{%- elif value is iterable and value is not string -%}
15+
{{ server_config(value, key, ind + ind_increment) }}
1616
{%- endif -%}
1717
{%- endfor -%}
18-
{%- elif value is iterable -%}
19-
{{ server_config(value, key, ind + ind_increment) }}
2018
{%- endif -%}
2119
{%- endfor -%}
2220
{%- endmacro -%}
@@ -32,4 +30,4 @@
3230
}
3331
# Vhosts
3432
# https://caddyserver.com/docs/caddyfile
35-
{{ server_config(caddy['servers']) }}
33+
{{ server_config(caddy['servers']) }}

caddy/parameters/defaults.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ values:
1313
config:
1414
dir: /etc/caddy
1515
file: Caddyfile
16-
validate: true
17-
format: true
1816
global_options:
1917
- email: webmaster@{{ grains.fqdn | lower }}
2018
- log main:
2119
- level: WARN
2220
- output: file /var/log/caddy/caddy-general.log
2321
service:
2422
name: caddy
25-
xcaddy: {}
2623
servers: {}

test/integration/default/controls/config.rb

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
'File managed by Salt at <salt://caddy/files/default/Caddyfile.tmpl.jinja>'
1414
)
1515
end
16+
# rubocop:disable Lint/RedundantCopDisableDirective
17+
# rubocop:disable Layout/LineLength
1618
its('content') do
17-
# rubocop:disable Lint/RedundantCopDisableDirective
18-
# rubocop:disable Layout/LineLength
1919
should match(
2020
"{\n"\
2121
"\temail webmaster@example.net\n"\
@@ -48,6 +48,7 @@
4848
its('content') do
4949
should match(
5050
"example.net {\n"\
51+
"\tencode gzip\n"\
5152
"\thandle_path /\\* {\n"\
5253
"\t\troot \\* /var/www/example.net/\n"\
5354
"\t\tfile_server\n"\
@@ -58,8 +59,36 @@
5859
"\t}\n"\
5960
'}'
6061
)
61-
# rubocop:enable Layout/LineLength
62-
# rubocop:enable Lint/RedundantCopDisableDirective
6362
end
63+
its('content') do
64+
should match(
65+
"multi.level.example.net {\n"\
66+
"\tencode gzip\n"\
67+
"\troute /path/\\* {\n"\
68+
"\t\tbasicauth \\* {\n"\
69+
"\t\t\tuser JDJhJDE0JFJxLjBBTXhVTHF2VHBoVU54LjFXQnVEQkZYdFhlVmUzSmxRL3VrQVcwS05IQnVIS2FBREIy\n"\
70+
"\t\t}\n"\
71+
"\t\troot \\* /var/www/html/\n"\
72+
"\t\ttry_files {path} /path/to/index.cgi\n"\
73+
"\t\t@cgi path \\*.cgi\n"\
74+
"\t\thandle /path/to/index.cgi {\n"\
75+
"\t\t\treverse_proxy @cgi unix//run/fcgiwrap.socket {\n"\
76+
"\t\t\t\ttransport fastcgi {\n"\
77+
"\t\t\t\t\tresolve_root_symlink\n"\
78+
"\t\t\t\t\tsplit .cgi\n"\
79+
"\t\t\t\t}\n"\
80+
"\t\t\t}\n"\
81+
"\t\t}\n"\
82+
"\t\tfile_server\n"\
83+
"\t}\n"\
84+
"\tlog {\n"\
85+
"\t\tlevel WARN\n"\
86+
"\t\toutput file /var/log/caddy/multi.level.example.net.log\n"\
87+
"\t}\n"\
88+
'}'
89+
)
90+
end
91+
# rubocop:enable Layout/LineLength
92+
# rubocop:enable Lint/RedundantCopDisableDirective
6493
end
6594
end

test/integration/default/files/_mapdata/debian-10.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ values:
55
config:
66
dir: /etc/caddy
77
file: Caddyfile
8-
format: true
98
global_options:
109
- email: webmaster@example.net
1110
- auto_https: 'off'
1211
- log main:
1312
- level: WARN
1413
- output: file /var/log/caddy/caddy-general.log
15-
validate: true
1614
group: caddy
1715
map_jinja:
1816
sources:
@@ -35,14 +33,31 @@ values:
3533
- example.com:80:
3634
- redir: https://example.net
3735
- example.net:
36+
- encode: gzip
3837
- handle_path /*:
3938
- root: '* /var/www/example.net/'
4039
- file_server
4140
- log:
4241
- level: WARN
4342
- output: file /var/log/caddy/example.net.log
43+
- multi.level.example.net:
44+
- encode: gzip
45+
- route /path/*:
46+
- basicauth *:
47+
- user: JDJhJDE0JFJxLjBBTXhVTHF2VHBoVU54LjFXQnVEQkZYdFhlVmUzSmxRL3VrQVcwS05IQnVIS2FBREIy
48+
- root: '* /var/www/html/'
49+
- try_files: '{path} /path/to/index.cgi'
50+
- '@cgi': path *.cgi
51+
- handle /path/to/index.cgi:
52+
- reverse_proxy @cgi unix//run/fcgiwrap.socket:
53+
- transport fastcgi:
54+
- resolve_root_symlink
55+
- split: .cgi
56+
- file_server
57+
- log:
58+
- level: WARN
59+
- output: file /var/log/caddy/multi.level.example.net.log
4460
service:
4561
name: caddy
4662
user: caddy
4763
version: 2.5.1
48-
xcaddy: {}

test/integration/default/files/_mapdata/debian-11.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ values:
55
config:
66
dir: /etc/caddy
77
file: Caddyfile
8-
format: true
98
global_options:
109
- email: webmaster@example.net
1110
- auto_https: 'off'
1211
- log main:
1312
- level: WARN
1413
- output: file /var/log/caddy/caddy-general.log
15-
validate: true
1614
group: caddy
1715
map_jinja:
1816
sources:
@@ -35,14 +33,31 @@ values:
3533
- example.com:80:
3634
- redir: https://example.net
3735
- example.net:
36+
- encode: gzip
3837
- handle_path /*:
3938
- root: '* /var/www/example.net/'
4039
- file_server
4140
- log:
4241
- level: WARN
4342
- output: file /var/log/caddy/example.net.log
43+
- multi.level.example.net:
44+
- encode: gzip
45+
- route /path/*:
46+
- basicauth *:
47+
- user: JDJhJDE0JFJxLjBBTXhVTHF2VHBoVU54LjFXQnVEQkZYdFhlVmUzSmxRL3VrQVcwS05IQnVIS2FBREIy
48+
- root: '* /var/www/html/'
49+
- try_files: '{path} /path/to/index.cgi'
50+
- '@cgi': path *.cgi
51+
- handle /path/to/index.cgi:
52+
- reverse_proxy @cgi unix//run/fcgiwrap.socket:
53+
- transport fastcgi:
54+
- resolve_root_symlink
55+
- split: .cgi
56+
- file_server
57+
- log:
58+
- level: WARN
59+
- output: file /var/log/caddy/multi.level.example.net.log
4460
service:
4561
name: caddy
4662
user: caddy
4763
version: 2.5.1
48-
xcaddy: {}

test/integration/default/files/_mapdata/debian-9.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ values:
55
config:
66
dir: /etc/caddy
77
file: Caddyfile
8-
format: true
98
global_options:
109
- email: webmaster@example.net
1110
- auto_https: 'off'
1211
- log main:
1312
- level: WARN
1413
- output: file /var/log/caddy/caddy-general.log
15-
validate: true
1614
group: caddy
1715
map_jinja:
1816
sources:
@@ -35,14 +33,31 @@ values:
3533
- example.com:80:
3634
- redir: https://example.net
3735
- example.net:
36+
- encode: gzip
3837
- handle_path /*:
3938
- root: '* /var/www/example.net/'
4039
- file_server
4140
- log:
4241
- level: WARN
4342
- output: file /var/log/caddy/example.net.log
43+
- multi.level.example.net:
44+
- encode: gzip
45+
- route /path/*:
46+
- basicauth *:
47+
- user: JDJhJDE0JFJxLjBBTXhVTHF2VHBoVU54LjFXQnVEQkZYdFhlVmUzSmxRL3VrQVcwS05IQnVIS2FBREIy
48+
- root: '* /var/www/html/'
49+
- try_files: '{path} /path/to/index.cgi'
50+
- '@cgi': path *.cgi
51+
- handle /path/to/index.cgi:
52+
- reverse_proxy @cgi unix//run/fcgiwrap.socket:
53+
- transport fastcgi:
54+
- resolve_root_symlink
55+
- split: .cgi
56+
- file_server
57+
- log:
58+
- level: WARN
59+
- output: file /var/log/caddy/multi.level.example.net.log
4460
service:
4561
name: caddy
4662
user: caddy
4763
version: 2.5.1
48-
xcaddy: {}

test/integration/default/files/_mapdata/ubuntu-18.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ values:
55
config:
66
dir: /etc/caddy
77
file: Caddyfile
8-
format: true
98
global_options:
109
- email: webmaster@example.net
1110
- auto_https: 'off'
1211
- log main:
1312
- level: WARN
1413
- output: file /var/log/caddy/caddy-general.log
15-
validate: true
1614
group: caddy
1715
map_jinja:
1816
sources:
@@ -35,14 +33,31 @@ values:
3533
- example.com:80:
3634
- redir: https://example.net
3735
- example.net:
36+
- encode: gzip
3837
- handle_path /*:
3938
- root: '* /var/www/example.net/'
4039
- file_server
4140
- log:
4241
- level: WARN
4342
- output: file /var/log/caddy/example.net.log
43+
- multi.level.example.net:
44+
- encode: gzip
45+
- route /path/*:
46+
- basicauth *:
47+
- user: JDJhJDE0JFJxLjBBTXhVTHF2VHBoVU54LjFXQnVEQkZYdFhlVmUzSmxRL3VrQVcwS05IQnVIS2FBREIy
48+
- root: '* /var/www/html/'
49+
- try_files: '{path} /path/to/index.cgi'
50+
- '@cgi': path *.cgi
51+
- handle /path/to/index.cgi:
52+
- reverse_proxy @cgi unix//run/fcgiwrap.socket:
53+
- transport fastcgi:
54+
- resolve_root_symlink
55+
- split: .cgi
56+
- file_server
57+
- log:
58+
- level: WARN
59+
- output: file /var/log/caddy/multi.level.example.net.log
4460
service:
4561
name: caddy
4662
user: caddy
4763
version: 2.5.1
48-
xcaddy: {}

test/integration/default/files/_mapdata/ubuntu-20.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ values:
55
config:
66
dir: /etc/caddy
77
file: Caddyfile
8-
format: true
98
global_options:
109
- email: webmaster@example.net
1110
- auto_https: 'off'
1211
- log main:
1312
- level: WARN
1413
- output: file /var/log/caddy/caddy-general.log
15-
validate: true
1614
group: caddy
1715
map_jinja:
1816
sources:
@@ -35,14 +33,31 @@ values:
3533
- example.com:80:
3634
- redir: https://example.net
3735
- example.net:
36+
- encode: gzip
3837
- handle_path /*:
3938
- root: '* /var/www/example.net/'
4039
- file_server
4140
- log:
4241
- level: WARN
4342
- output: file /var/log/caddy/example.net.log
43+
- multi.level.example.net:
44+
- encode: gzip
45+
- route /path/*:
46+
- basicauth *:
47+
- user: JDJhJDE0JFJxLjBBTXhVTHF2VHBoVU54LjFXQnVEQkZYdFhlVmUzSmxRL3VrQVcwS05IQnVIS2FBREIy
48+
- root: '* /var/www/html/'
49+
- try_files: '{path} /path/to/index.cgi'
50+
- '@cgi': path *.cgi
51+
- handle /path/to/index.cgi:
52+
- reverse_proxy @cgi unix//run/fcgiwrap.socket:
53+
- transport fastcgi:
54+
- resolve_root_symlink
55+
- split: .cgi
56+
- file_server
57+
- log:
58+
- level: WARN
59+
- output: file /var/log/caddy/multi.level.example.net.log
4460
service:
4561
name: caddy
4662
user: caddy
4763
version: 2.5.1
48-
xcaddy: {}

test/integration/default/files/_mapdata/ubuntu-22.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ values:
55
config:
66
dir: /etc/caddy
77
file: Caddyfile
8-
format: true
98
global_options:
109
- email: webmaster@example.net
1110
- auto_https: 'off'
1211
- log main:
1312
- level: WARN
1413
- output: file /var/log/caddy/caddy-general.log
15-
validate: true
1614
group: caddy
1715
map_jinja:
1816
sources:
@@ -35,14 +33,31 @@ values:
3533
- example.com:80:
3634
- redir: https://example.net
3735
- example.net:
36+
- encode: gzip
3837
- handle_path /*:
3938
- root: '* /var/www/example.net/'
4039
- file_server
4140
- log:
4241
- level: WARN
4342
- output: file /var/log/caddy/example.net.log
43+
- multi.level.example.net:
44+
- encode: gzip
45+
- route /path/*:
46+
- basicauth *:
47+
- user: JDJhJDE0JFJxLjBBTXhVTHF2VHBoVU54LjFXQnVEQkZYdFhlVmUzSmxRL3VrQVcwS05IQnVIS2FBREIy
48+
- root: '* /var/www/html/'
49+
- try_files: '{path} /path/to/index.cgi'
50+
- '@cgi': path *.cgi
51+
- handle /path/to/index.cgi:
52+
- reverse_proxy @cgi unix//run/fcgiwrap.socket:
53+
- transport fastcgi:
54+
- resolve_root_symlink
55+
- split: .cgi
56+
- file_server
57+
- log:
58+
- level: WARN
59+
- output: file /var/log/caddy/multi.level.example.net.log
4460
service:
4561
name: caddy
4662
user: caddy
4763
version: 2.5.1
48-
xcaddy: {}

0 commit comments

Comments
 (0)