Skip to content

Commit 4ec404a

Browse files
committed
Add validations for syc_files stage
Assisted-By: Claude (claude-4.5-sonnet) Signed-off-by: Harald Jensås <hjensas@redhat.com>
1 parent 66c4c0c commit 4ec404a

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

roles/hotloop/library/hotloop_stage_loader.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,48 @@ def _validate_kustomize(kustomize_config):
275275
)
276276

277277

278+
def _validate_sync_files(sync_files_config):
279+
"""Validates the 'sync_files' parameter.
280+
281+
This function checks if the 'sync_files' parameter is a dict with
282+
required fields and proper formatting.
283+
284+
:param sync_files_config: The 'sync_files' parameter to validate.
285+
"""
286+
if not isinstance(sync_files_config, dict):
287+
raise TypeError(
288+
"'sync_files' must be a dict, got {sync_files_type}".format(
289+
sync_files_type=type(sync_files_config)
290+
)
291+
)
292+
293+
if "src" not in sync_files_config:
294+
raise ValueError("sync_files must have a 'src' field")
295+
296+
if "dest" not in sync_files_config:
297+
raise ValueError("sync_files must have a 'dest' field")
298+
299+
if not isinstance(sync_files_config["src"], str):
300+
raise TypeError(
301+
"sync_files 'src' must be a string, got {src_type}".format(
302+
src_type=type(sync_files_config["src"])
303+
)
304+
)
305+
306+
if not isinstance(sync_files_config["dest"], str):
307+
raise TypeError(
308+
"sync_files 'dest' must be a string, got {dest_type}".format(
309+
dest_type=type(sync_files_config["dest"])
310+
)
311+
)
312+
313+
if not sync_files_config["src"].endswith("/"):
314+
raise ValueError(
315+
"sync_files 'src' must end with '/' to indicate directory sync. "
316+
"Got: {src}".format(src=sync_files_config["src"])
317+
)
318+
319+
278320
def _validate_stage(stage, nested=False):
279321
"""Validate a stage
280322
@@ -311,6 +353,9 @@ def _validate_stage(stage, nested=False):
311353
if "kustomize" in stage:
312354
_validate_kustomize(stage["kustomize"])
313355

356+
if "sync_files" in stage:
357+
_validate_sync_files(stage["sync_files"])
358+
314359
if "wait_pod_completion" in stage:
315360
_validate_wait_pod_completion(stage["wait_pod_completion"])
316361

0 commit comments

Comments
 (0)