Skip to content
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

Add include/exclude extensions options #262

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ A configuration file for a sample contains the information about the sample to g

**extractPaths**: (required) the absolute path or relative path from location of current working directory that `surfactant` is being run from to the sample folders, cannot be a file (Note that even on Windows, Unix style `/` directory separators should be used in paths)\
**archive**: (optional) the full path, including file name, of the zip, exe installer, or other archive file that the folders in **extractPaths** were extracted from. This is used to collect metadata about the overall sample and will be added as a "Contains" relationship to all software entries found in the various **extractPaths**\
**installPrefix**: (optional) where the files in **extractPaths** would be if installed correctly on an actual system i.e. "C:/", "C:/Program Files/", etc (Note that even on Windows, Unix style `/` directory separators should be used in the path). If not given then the **extractPaths** will be used as the install paths
**includeAllFiles**: (optional) If present and set to true, include all files in the SBOM, rather than only those recognized by Surfactant.
**installPrefix**: (optional) where the files in **extractPaths** would be if installed correctly on an actual system i.e. "C:/", "C:/Program Files/", etc (Note that even on Windows, Unix style `/` directory separators should be used in the path). If not given then the **extractPaths** will be used as the install\
**includeAllFiles**: (optional) If present and set to true, include all files in the SBOM, rather than only those recognized by Surfactant\
**includeFileExts**: (optional) A list of file extensions to include, even if not recognized by Surfactant\
**excludeFileExts**: (optional) A list of file extensions to exclude, even if recognized by Surfactant. Note that setting both this and includeAllFiles will still exclude the specified extensions

#### Create config command

Expand Down
6 changes: 4 additions & 2 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ A sample configuration file contains the information about the sample to gather

**extractPaths**: (required) the absolute path or relative path from location of current working directory that `surfactant` is being run from to the sample folders, cannot be a file (Note that even on Windows, Unix style `/` directory separators should be used in paths)\
**archive**: (optional) the full path, including file name, of the zip, exe installer, or other archive file that the folders in **extractPaths** were extracted from. This is used to collect metadata about the overall sample and will be added as a "Contains" relationship to all software entries found in the various **extractPaths**\
**installPrefix**: (optional) where the files in **extractPaths** would be if installed correctly on an actual system i.e. "C:/", "C:/Program Files/", etc (Note that even on Windows, Unix style `/` directory separators should be used in the path). If not given then the **extractPaths** will be used as the install paths
**includeAllFiles**: (optional) If present and set to true, include all files in the SBOM, rather than only those recognized by Surfactant.
**installPrefix**: (optional) where the files in **extractPaths** would be if installed correctly on an actual system i.e. "C:/", "C:/Program Files/", etc (Note that even on Windows, Unix style `/` directory separators should be used in the path). If not given then the **extractPaths** will be used as the install paths\
**includeAllFiles**: (optional) If present and set to true, include all files in the SBOM, rather than only those recognized by Surfactant\
**includeFileExts**: (optional) A list of file extensions to include, even if not recognized by Surfactant\
**excludeFileExts**: (optional) A list of file extensions to exclude, even if recognized by Surfactant. Note that setting both this and includeAllFiles will still exclude the specified extensions

## Example configuration files

Expand Down
8 changes: 7 additions & 1 deletion surfactant/cmd/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,16 @@ def sbom(
except Exception as e:
raise RuntimeError(f"Unable to process: {filepath}") from e

if not entry.includeFileExts:
entry.includeFileExts = []
if not entry.excludeFileExts:
entry.excludeFileExts = []

if (
ftype := pm.hook.identify_file_type(filepath=filepath)
or include_all_files
):
or os.path.splitext(filepath)[1] in entry.includeFileExts
) and os.path.splitext(filepath)[1] not in entry.excludeFileExts:
try:
sw_parent, sw_children = get_software_entry(
context,
Expand Down
2 changes: 2 additions & 0 deletions surfactant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ class ContextEntry:
archive: Optional[str] = None
installPrefix: Optional[str] = None
includeAllFiles: Optional[bool] = None
includeFileExts: Optional[List[str]] = None
excludeFileExts: Optional[List[str]] = None
Loading