Skip to content

Commit

Permalink
Audit: Update the path to get the right version of tools like poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jun 16, 2024
1 parent 33ac8b2 commit 5134fe4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions github_app_geo_project/module/audit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""the audit modules."""

import datetime
import glob
import json
import logging
import os
Expand Down Expand Up @@ -198,11 +199,11 @@ async def _process_snyk_dpkg(
break

if python_version:
_use_python_version(python_version)
env = _use_python_version(python_version)

logs_url = urllib.parse.urljoin(context.service_url, f"logs/{context.job_id}")
result, body, short_message, new_success = await audit_utils.snyk(
branch, context.module_config.get("snyk", {}), local_config.get("snyk", {}), logs_url
branch, context.module_config.get("snyk", {}), local_config.get("snyk", {}), logs_url, env
)
success &= new_success
output_url = _process_error(
Expand Down Expand Up @@ -264,7 +265,7 @@ async def _process_snyk_dpkg(
return short_message, success


def _use_python_version(python_version: str) -> None:
def _use_python_version(python_version: str) -> dict[str, str]:
proc = subprocess.run( # nosec # pylint: disable=subprocess-run-check
["pyenv", "local", python_version],
capture_output=True,
Expand All @@ -281,10 +282,19 @@ def _use_python_version(python_version: str) -> None:
proc = subprocess.run( # nosec # pylint: disable=subprocess-run-check
["python", "--version"], capture_output=True, encoding="utf-8", timeout=5
)

# Get path from /pyenv/versions/{python_version}.*/bin/
env = os.environ.copy()
bin_paths = glob.glob(f"/pyenv/versions/{python_version}.*/bin")
if bin_paths:
env["PATH"] = f'{bin_paths[0]}:{env["PATH"]}'

message = module_utils.ansi_proc_message(proc)
message.title = "Python version"
_LOGGER.debug(message)

return env


class Audit(module.Module[configuration.AuditConfiguration, _EventData, _TransversalStatus]):
"""The audit module."""
Expand Down
2 changes: 1 addition & 1 deletion github_app_geo_project/module/audit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ async def snyk(
config: configuration.SnykConfiguration,
local_config: configuration.SnykConfiguration,
logs_url: str,
env: dict[str, str],
) -> tuple[list[module_utils.Message], module_utils.Message | None, list[str], bool]:
"""
Audit the code with Snyk.
Expand All @@ -103,7 +104,6 @@ async def snyk(
"""
result: list[module_utils.Message] = []

env = os.environ.copy()
env["PATH"] = f'{env["HOME"]}/.local/bin:{env["PATH"]}'
_LOGGER.debug("Updated path: %s", env["PATH"])

Expand Down

0 comments on commit 5134fe4

Please sign in to comment.