|
22 | 22 | from macaron.config.global_config import global_config |
23 | 23 | from macaron.console import RichConsoleHandler, access_handler |
24 | 24 | from macaron.errors import ConfigurationError |
| 25 | +from macaron.output_reporter import find_report_output_path |
25 | 26 | from macaron.output_reporter.reporter import HTMLReporter, JSONReporter, PolicyReporter |
26 | 27 | from macaron.policy_engine.policy_engine import run_policy_engine, show_prelude |
27 | 28 | from macaron.repo_finder import repo_finder |
@@ -280,22 +281,22 @@ def verify_policy(verify_policy_args: argparse.Namespace) -> int: |
280 | 281 | rich_handler = access_handler.get_handler() |
281 | 282 | if vsa is not None: |
282 | 283 | vsa_filepath = os.path.join(global_config.output_path, "vsa.intoto.jsonl") |
283 | | - rich_handler.update_vsa(os.path.relpath(vsa_filepath, os.getcwd())) |
| 284 | + rich_handler.update_vsa(find_report_output_path(vsa_filepath)) |
284 | 285 | logger.info( |
285 | 286 | "Generating the Verification Summary Attestation (VSA) to %s.", |
286 | | - os.path.relpath(vsa_filepath, os.getcwd()), |
| 287 | + find_report_output_path(vsa_filepath), |
287 | 288 | ) |
288 | 289 | logger.info( |
289 | 290 | "To decode and inspect the payload, run `cat %s | jq -r '.payload' | base64 -d | jq`.", |
290 | | - os.path.relpath(vsa_filepath, os.getcwd()), |
| 291 | + find_report_output_path(vsa_filepath), |
291 | 292 | ) |
292 | 293 | try: |
293 | 294 | with open(vsa_filepath, mode="w", encoding="utf-8") as file: |
294 | 295 | file.write(json.dumps(vsa)) |
295 | 296 | except OSError as err: |
296 | 297 | logger.error( |
297 | 298 | "Could not generate the VSA to %s. Error: %s", |
298 | | - os.path.relpath(vsa_filepath, os.getcwd()), |
| 299 | + find_report_output_path(vsa_filepath), |
299 | 300 | err, |
300 | 301 | ) |
301 | 302 | else: |
@@ -372,7 +373,7 @@ def perform_action(action_args: argparse.Namespace) -> None: |
372 | 373 | if not action_args.disable_rich_output: |
373 | 374 | rich_handler.start("dump-defaults") |
374 | 375 | # Create the defaults.ini file in the output dir and exit. |
375 | | - create_defaults(action_args.output, os.getcwd()) |
| 376 | + create_defaults(action_args.output) |
376 | 377 | sys.exit(os.EX_OK) |
377 | 378 |
|
378 | 379 | case "verify-policy": |
@@ -466,6 +467,9 @@ def main(argv: list[str] | None = None) -> None: |
466 | 467 | global_config.gl_token = _get_token_from_dict_or_env("MCN_GITLAB_TOKEN", token_dict) |
467 | 468 | global_config.gl_self_host_token = _get_token_from_dict_or_env("MCN_SELF_HOSTED_GITLAB_TOKEN", token_dict) |
468 | 469 |
|
| 470 | + # Set the host output path, which would be set if Macaron is running inside a container. |
| 471 | + global_config.host_output_path = _get_host_output_path_env() |
| 472 | + |
469 | 473 | main_parser = argparse.ArgumentParser(prog="macaron") |
470 | 474 |
|
471 | 475 | main_parser.add_argument( |
@@ -735,12 +739,12 @@ def main(argv: list[str] | None = None) -> None: |
735 | 739 | if os.path.isdir(args.output): |
736 | 740 | logger.info( |
737 | 741 | "Setting the output directory to %s", |
738 | | - os.path.relpath(args.output, os.getcwd()), |
| 742 | + find_report_output_path(args.output), |
739 | 743 | ) |
740 | 744 | else: |
741 | 745 | logger.info( |
742 | 746 | "No directory at %s. Creating one ...", |
743 | | - os.path.relpath(args.output, os.getcwd()), |
| 747 | + find_report_output_path(args.output), |
744 | 748 | ) |
745 | 749 | os.makedirs(args.output) |
746 | 750 |
|
@@ -800,5 +804,17 @@ def _get_token_from_dict_or_env(token: str, token_dict: dict[str, str]) -> str: |
800 | 804 | return token_dict[token] if token in token_dict else os.environ.get(token) or "" |
801 | 805 |
|
802 | 806 |
|
| 807 | +def _get_host_output_path_env() -> str: |
| 808 | + """ |
| 809 | + Get the host output path from the HOST_OUTPUT environment variable. |
| 810 | +
|
| 811 | + Returns |
| 812 | + ------- |
| 813 | + str |
| 814 | + The HOST_OUTPUT environment variable or an empty string. |
| 815 | + """ |
| 816 | + return os.environ.get("HOST_OUTPUT") or "" |
| 817 | + |
| 818 | + |
803 | 819 | if __name__ == "__main__": |
804 | 820 | main() |
0 commit comments