@@ -82,7 +82,12 @@ def new(
82
82
83
83
env = jinja2 .Environment (
84
84
loader = jinja2 .FileSystemLoader (
85
- searchpath = get_ctf_script_templates_directory (), encoding = "utf-8"
85
+ searchpath = (
86
+ new_template_path := os .path .join (
87
+ get_ctf_script_templates_directory (), "new"
88
+ )
89
+ ),
90
+ encoding = "utf-8" ,
86
91
)
87
92
)
88
93
@@ -106,7 +111,7 @@ def new(
106
111
ipv6_address = f"216:3eff:fe{ rb [0 ]} { rb [1 ]} :{ rb [2 ]} { rb [3 ]} { rb [4 ]} { rb [5 ]} "
107
112
full_ipv6_address = f"{ ipv6_subnet } :{ ipv6_address } "
108
113
109
- track_template = env .get_template (name = " track.yaml.j2" )
114
+ track_template = env .get_template (name = os . path . join ( "common" , " track.yaml.j2") )
110
115
render = track_template .render (
111
116
data = {
112
117
"name" : name ,
@@ -130,7 +135,7 @@ def new(
130
135
131
136
LOG .debug (msg = f"Directory { posts_directory } created." )
132
137
133
- track_template = env .get_template (name = " topic.yaml.j2" )
138
+ track_template = env .get_template (name = os . path . join ( "common" , " topic.yaml.j2") )
134
139
render = track_template .render (data = {"name" : name })
135
140
with open (
136
141
file = (p := os .path .join (posts_directory , f"{ name } .yaml" )),
@@ -141,7 +146,7 @@ def new(
141
146
142
147
LOG .debug (msg = f"Wrote { p } ." )
143
148
144
- track_template = env .get_template (name = " post.yaml.j2" )
149
+ track_template = env .get_template (name = os . path . join ( "common" , " post.yaml.j2") )
145
150
render = track_template .render (data = {"name" : name })
146
151
with open (
147
152
file = (p := os .path .join (posts_directory , f"{ name } _flag1.yaml" )),
@@ -170,7 +175,7 @@ def new(
170
175
171
176
LOG .debug (msg = f"Directory { terraform_directory } created." )
172
177
173
- track_template = env .get_template (name = " main.tf.j2" )
178
+ track_template = env .get_template (name = os . path . join ( "common" , " main.tf.j2") )
174
179
175
180
render = track_template .render (
176
181
data = {
@@ -215,7 +220,7 @@ def new(
215
220
216
221
LOG .debug (msg = f"Directory { ansible_directory } created." )
217
222
218
- track_template = env .get_template (name = f "deploy- { template } .yaml.j2" )
223
+ track_template = env .get_template (name = os . path . join ( template , "deploy.yaml.j2" ) )
219
224
render = track_template .render (data = {"name" : name })
220
225
with open (
221
226
file = (p := os .path .join (ansible_directory , "deploy.yaml" )),
@@ -226,7 +231,7 @@ def new(
226
231
227
232
LOG .debug (msg = f"Wrote { p } ." )
228
233
229
- track_template = env .get_template (name = " inventory.j2" )
234
+ track_template = env .get_template (name = os . path . join ( "common" , " inventory.j2") )
230
235
render = track_template .render (data = {"name" : name })
231
236
with open (
232
237
file = (p := os .path .join (ansible_directory , "inventory" )),
@@ -244,7 +249,9 @@ def new(
244
249
LOG .debug (msg = f"Directory { ansible_challenge_directory } created." )
245
250
246
251
if template == Template .APACHE_PHP :
247
- track_template = env .get_template (name = "index.php.j2" )
252
+ track_template = env .get_template (
253
+ name = os .path .join (Template .APACHE_PHP , "index.php.j2" )
254
+ )
248
255
render = track_template .render (data = {"name" : name })
249
256
with open (
250
257
file = (p := os .path .join (ansible_challenge_directory , "index.php" )),
@@ -256,7 +263,9 @@ def new(
256
263
LOG .debug (msg = f"Wrote { p } ." )
257
264
258
265
if template == Template .PYTHON_SERVICE :
259
- track_template = env .get_template (name = "app.py.j2" )
266
+ track_template = env .get_template (
267
+ name = os .path .join (Template .PYTHON_SERVICE , "app.py.j2" )
268
+ )
260
269
render = track_template .render (data = {"name" : name })
261
270
with open (
262
271
file = (p := os .path .join (ansible_challenge_directory , "app.py" )),
@@ -279,13 +288,19 @@ def new(
279
288
if template == Template .RUST_WEBSERVICE :
280
289
# Copy the entire challenge template
281
290
shutil .copytree (
282
- os .path .join (get_ctf_script_templates_directory (), "rust-webservice" ),
291
+ os .path .join (
292
+ new_template_path ,
293
+ Template .RUST_WEBSERVICE ,
294
+ "source" ,
295
+ ),
283
296
ansible_challenge_directory ,
284
297
dirs_exist_ok = True ,
285
298
)
286
299
LOG .debug (msg = f"Wrote files to { ansible_challenge_directory } " )
287
300
288
- manifest_template = env .get_template (name = "Cargo.toml.j2" )
301
+ manifest_template = env .get_template (
302
+ name = os .path .join (Template .RUST_WEBSERVICE , "Cargo.toml.j2" )
303
+ )
289
304
render = manifest_template .render (data = {"name" : name })
290
305
with open (
291
306
file = (p := os .path .join (ansible_challenge_directory , "Cargo.toml" )),
0 commit comments