Skip to content

Conversation

@faizanH
Copy link
Contributor

@faizanH faizanH commented May 12, 2025

Description

Currently, when a directory has a composer.json file and does not have a composer.lock file, we can not use our trivy SCA scanner. Now with this change, a composer.lock file will be auto generated when a directory contains a composer.json file.

Motivation and Context

To extend our SCA language coverage

How Has This Been Tested?

in a development environment

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation change

Checklist

  • My code follows conforms to the coding standards.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@faizanH faizanH requested a review from a team as a code owner May 12, 2025 17:05
def install_package_files(include_dev: bool, path: str, root_path: str):
# Create a composer.lock file if it doesn't already exist
logger.info(
f"Generating composer.lock for {path.replace(root_path, '')} (including dev dependencies: {include_dev}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) Missing end paren at the end of the log message.

docker_client = docker.from_env()


def install_package_files(include_dev: bool, path: str, root_path: str):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function doesn't report errors up, we should document the fact that this is "best effort", i.e. if the composer.lock couldn't be generated then we will continue anyway.

{"success": not bool(results), "details": results, "errors": lock_file_errors, "alerts": lock_file_alerts}
)
)
print(json.dumps({"success": not bool(results), "details": results, "errors": errors, "alerts": alerts}))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) Since our JSON results can be quite large, we should switch from using json.dumps (which renders the whole JSON to a string first) to json.dump that renders the output directly to the output, e.g.:

json.dump({ ... }, sys.stdout)


# Run Composer in a container
COMPOSER_IMG = "composer:latest"
container_name = "composer_runner"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container names must be unique, so we should append a UUID.

@breedenc breedenc marked this pull request as draft October 27, 2025 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants