Skip to content

Commit

Permalink
add repository cleanup-hook (post job-run) (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Sep 17, 2024
1 parent fc4c13f commit 8f3d56c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/ansibleguy-webui/aw/api_endpoints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ def not_implemented(*args, **kwargs):
return JsonResponse({'error': 'Not yet implemented'}, status=404)


def validate_no_xss(value: str, field: str, shell_cmd: bool = False):
def validate_no_xss(value: str, field: str, shell_cmd: bool = False, single_quote: bool = False):
if is_set(value) and isinstance(value, str):
if shell_cmd:
# ignore characters shell-commands may need
# ignore characters shell-commands may need
if single_quote or shell_cmd:
value = value.replace("'", '')

if shell_cmd:
value = value.replace('&', '')

if value != escape_html(value):
Expand Down
1 change: 1 addition & 0 deletions src/ansibleguy-webui/aw/config/form_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'git_isolate': 'Git Isolate Directory',
'git_hook_pre': 'Git Pre-Hook',
'git_hook_post': 'Git Post-Hook',
'git_hook_cleanup': 'Git Cleanup-Hook',
'git_override_initialize': 'Git Override Initialize-Command',
'git_override_update': 'Git Override Update-Command',
},
Expand Down
1 change: 1 addition & 0 deletions src/ansibleguy-webui/aw/execute/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def cleanup_repository(self):
for attr in BaseJobCredentials.SECRET_ATTRS:
overwrite_and_delete_file(get_pwd_file(path_run=path_run_repo, attr=attr))

self._run_repo_config_cmds(cmds=self.repository.git_hook_cleanup, env=self._git_env())
if self.repository.git_isolate:
rmtree(self.get_path_repo(), ignore_errors=True)

Expand Down
10 changes: 7 additions & 3 deletions src/ansibleguy-webui/aw/model/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class Repository(BaseModel):
form_fields_git = [
'name', 'git_origin', 'git_credentials', 'git_branch', 'git_isolate', 'git_lfs', 'git_limit_depth',
'git_playbook_base',
'git_hook_pre', 'git_hook_post', 'git_override_initialize', 'git_override_update',
'git_hook_pre', 'git_hook_post', 'git_hook_cleanup', 'git_override_initialize', 'git_override_update',
]
form_fields_static = ['name', 'static_path']
form_fields = [
'name', 'rtype', 'static_path', 'git_origin', 'git_credentials', 'git_branch', 'git_isolate', 'git_lfs',
'git_limit_depth', 'git_hook_pre', 'git_hook_post', 'git_override_initialize', 'git_override_update',
'git_limit_depth', 'git_hook_pre', 'git_hook_post', 'git_hook_cleanup',
'git_override_initialize', 'git_override_update',
'git_playbook_base',
]
api_fields_read = form_fields.copy()
Expand All @@ -31,7 +32,9 @@ class Repository(BaseModel):

])
api_fields_write = form_fields
fields_shell_cmds = ['git_hook_pre', 'git_hook_post', 'git_override_initialize', 'git_override_update']
fields_shell_cmds = [
'git_hook_pre', 'git_hook_post', 'git_hook_cleanup', 'git_override_initialize', 'git_override_update',
]

name = models.CharField(max_length=100, null=False, blank=False)
rtype = models.PositiveSmallIntegerField(choices=CHOICES_REPOSITORY)
Expand All @@ -49,6 +52,7 @@ class Repository(BaseModel):
git_limit_depth = models.PositiveIntegerField(**DEFAULT_NONE)
git_hook_pre = models.CharField(max_length=1000, **DEFAULT_NONE)
git_hook_post = models.CharField(max_length=1000, **DEFAULT_NONE)
git_hook_cleanup = models.CharField(max_length=1000, **DEFAULT_NONE)
git_override_initialize = models.CharField(max_length=1000, **DEFAULT_NONE)
git_override_update = models.CharField(max_length=1000, **DEFAULT_NONE)
git_playbook_base = models.CharField(max_length=300, **DEFAULT_NONE)
Expand Down

0 comments on commit 8f3d56c

Please sign in to comment.