From 4173e4b18f255886aafc689c2e0010a52d4babba Mon Sep 17 00:00:00 2001 From: Guilherme Gallo Date: Wed, 17 May 2023 01:12:28 -0300 Subject: ci/lava: Hide JWT block during YAML dump Make hide_sensitive_data work in a block fashion, not only hiding the JWT line, since these tokens are huge, it may break the line when it extrapolates the YAML dump width. Signed-off-by: Guilherme Gallo Part-of: --- .gitlab-ci/lava/utils/lava_job_definition.py | 6 +++--- .gitlab-ci/lava/utils/log_follower.py | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to '.gitlab-ci/lava') diff --git a/.gitlab-ci/lava/utils/lava_job_definition.py b/.gitlab-ci/lava/utils/lava_job_definition.py index b05961dfb53..55dbb902dac 100644 --- a/.gitlab-ci/lava/utils/lava_job_definition.py +++ b/.gitlab-ci/lava/utils/lava_job_definition.py @@ -127,9 +127,9 @@ def artifact_download_steps(args): if args.jwt_file: with open(args.jwt_file) as jwt_file: download_steps += [ - "set +x", - f'echo -n "{jwt_file.read()}" > "{args.jwt_file}" # HIDEME', - "set -x", + "set +x # HIDE_START", + f'echo -n "{jwt_file.read()}" > "{args.jwt_file}"', + "set -x # HIDE_END", f'echo "export CI_JOB_JWT_FILE={args.jwt_file}" >> /set-job-env-vars.sh', ] else: diff --git a/.gitlab-ci/lava/utils/log_follower.py b/.gitlab-ci/lava/utils/log_follower.py index 19837543833..1fdf490bcb8 100644 --- a/.gitlab-ci/lava/utils/log_follower.py +++ b/.gitlab-ci/lava/utils/log_follower.py @@ -293,5 +293,18 @@ def fatal_err(msg, exception=None): sys.exit(1) -def hide_sensitive_data(yaml_data: str, hide_tag: str ="HIDEME"): - return "".join(line for line in yaml_data.splitlines(True) if hide_tag not in line) +def hide_sensitive_data(yaml_data: str, start_hide: str = "HIDE_START", end_hide: str = "HIDE_END") -> str: + skip_line = False + dump_data: list[str] = [] + for line in yaml_data.splitlines(True): + if start_hide in line: + skip_line = True + elif end_hide in line: + skip_line = False + + if skip_line: + continue + + dump_data.append(line) + + return "".join(dump_data) -- cgit v1.2.3