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

feat: Add configuration option to enable/disable Docker Scout #326

Merged
merged 7 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ Getting the currently set value for the option would then be done with:
surfactant config core.recorded_institution
```

### Configuration Options

- **docker.enable_docker_scout**: Controls whether Docker Scout is enabled. Default is `true`. To disable Docker Scout, run:

```bash
surfactant config docker.enable_docker_scout false
```

nightlark marked this conversation as resolved.
Show resolved Hide resolved
### Manual Editing

If desired, the settings config file can also be manually edited. The location of the file will depend on your platform.
Expand Down
23 changes: 20 additions & 3 deletions surfactant/infoextractors/docker_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,27 @@
from loguru import logger

import surfactant.plugin
from surfactant.configmanager import ConfigManager
from surfactant.sbomtypes import SBOM, Software


class DockerScoutManager:
def __init__(self) -> None:
self.disable_docker_scout = True
# Initialize ConfigManager
config_manager = ConfigManager()

# Retrieve the configuration option
enable_docker_scout = config_manager.get("docker", "enable_docker_scout", True)

# Set disable_docker_scout based on the configuration
self.disable_docker_scout = not enable_docker_scout
self.docker_scout_installed = False

def check_docker_scout_installed(self) -> None:
"""Check if Docker Scout is installed and update the state accordingly."""
if self.disable_docker_scout:
return # Do nothing if Docker Scout is disabled by config

try:
result = subprocess.run(["docker", "scout"], capture_output=True, check=False)
self.docker_scout_installed = result.returncode == 0
Expand All @@ -29,10 +40,16 @@ def check_docker_scout_installed(self) -> None:

self.disable_docker_scout = not self.docker_scout_installed
if not self.docker_scout_installed:
logger.warning("Install Docker Scout to scan containers for additional information")
logger.warning(
"Install Docker Scout to scan containers for additional information. "
"You can also disable this check by running 'surfactant config docker.enable_docker_scout false'."
)

def run_docker_scout(self, filename: str) -> object:
"""Run Docker Scout on the given file and return the results."""
if self.disable_docker_scout:
return {} # Do nothing if Docker Scout is disabled by config

try:
result = subprocess.run(
["docker", "scout", "sbom", "--format", "spdx", f"fs://{filename}"],
Expand Down Expand Up @@ -80,5 +97,5 @@ def extract_docker_info(filetype: str, filename: str) -> object:

@surfactant.plugin.hookimpl
def init_hook(command_name: Optional[str] = None) -> None:
if command_name != "update-db":
if command_name != "update-db" and not dsManager.disable_docker_scout:
dsManager.check_docker_scout_installed()
Loading