-
Notifications
You must be signed in to change notification settings - Fork 26
Add Neo4j output writer for Surfactant SBOM exports #629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
willis89pr
wants to merge
6
commits into
main
Choose a base branch
from
neo4j
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3cc04b5
feat(neo4j): add SBOM export writer
12bbc90
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 837522f
fix(neo4j): filter filesystem edges from logical graph export
21e8331
Merge.
f04d823
Merge.
6ff698c
chore(scripts): add PEP 723 metadata to Neo4j loader
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #!/usr/bin/env python3 | ||
| # /// script | ||
| # dependencies = [ | ||
| # "neo4j>=5", | ||
| # ] | ||
| # /// | ||
| """Standalone loader for importing an existing CyTRICS SBOM into Neo4j. | ||
|
|
||
| Usage: | ||
|
|
||
| export NEO4J_URI=neo4j://localhost:7687 | ||
| export NEO4J_USER=neo4j | ||
| export NEO4J_PASSWORD=your-password | ||
| python load_sbom_to_neo4j.py existing-sbom.json | ||
|
|
||
| This script assumes it is run inside a Surfactant checkout or environment where | ||
| `surfactant` is importable. It imports `export_sbom_to_neo4j` from the | ||
| surfactant.output.neo4j_writer module. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
|
|
||
| from neo4j import GraphDatabase | ||
|
|
||
| from surfactant.input_readers.cytrics_reader import read_sbom | ||
| from surfactant.output.neo4j_writer import export_sbom_to_neo4j | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser( | ||
| description="Import an existing Surfactant/CyTRICS SBOM into Neo4j" | ||
| ) | ||
| parser.add_argument("sbom_json", help="Path to an existing CyTRICS SBOM JSON file") | ||
| parser.add_argument("--database", default=os.environ.get("NEO4J_DATABASE", "neo4j")) | ||
| parser.add_argument( | ||
| "--batch-size", type=int, default=int(os.environ.get("NEO4J_BATCH_SIZE", "1000")) | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| if args.batch_size <= 0: | ||
| raise SystemExit("--batch-size must be greater than zero") | ||
|
|
||
| uri = os.environ.get("NEO4J_URI") | ||
| user = os.environ.get("NEO4J_USER", "neo4j") | ||
| password = os.environ.get("NEO4J_PASSWORD") | ||
| if not uri: | ||
| raise SystemExit("NEO4J_URI is required, for example neo4j://localhost:7687") | ||
| if password is None: | ||
| raise SystemExit("NEO4J_PASSWORD is required") | ||
|
|
||
| with open(args.sbom_json, encoding="utf-8") as infile: | ||
| sbom = read_sbom(infile) | ||
|
|
||
| with GraphDatabase.driver(uri, auth=(user, password)) as driver: | ||
| summary = export_sbom_to_neo4j( | ||
| sbom, | ||
| driver=driver, | ||
| database=args.database, | ||
| batch_size=args.batch_size, | ||
| ) | ||
|
|
||
| print(json.dumps(summary, indent=2, sort_keys=True)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.