From d97cc438cfcebb76b5ce211fe792eec5944a0ba8 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Thu, 3 Apr 2025 11:43:54 -0700 Subject: [PATCH 1/3] Updated version --- pyproject.toml | 2 +- socketsecurity/__init__.py | 2 +- socketsecurity/config.py | 9 +++++++++ socketsecurity/core/__init__.py | 21 ++++++++++++++------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7125d24..b7d6513 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.0.35" +version = "2.0.36" requires-python = ">= 3.10" license = {"file" = "LICENSE"} dependencies = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 452a794..46d0887 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.0.35' +__version__ = '2.0.36' diff --git a/socketsecurity/config.py b/socketsecurity/config.py index 788c572..79b0031 100644 --- a/socketsecurity/config.py +++ b/socketsecurity/config.py @@ -2,6 +2,7 @@ import os from dataclasses import asdict, dataclass from typing import List, Optional +from socketdev import __version__ from socketdev import INTEGRATION_TYPES, IntegrationType @@ -35,6 +36,7 @@ class CliConfig: timeout: Optional[int] = 1200 exclude_license_details: bool = False include_module_folders: bool = False + version: str = __version__ @classmethod def from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig': parser = create_argument_parser() @@ -75,6 +77,7 @@ def from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig': 'timeout': args.timeout, 'exclude_license_details': args.exclude_license_details, 'include_module_folders': args.include_module_folders, + 'version': __version__ } if args.owner: @@ -360,4 +363,10 @@ def create_argument_parser() -> argparse.ArgumentParser: help="Enabling including module folders like node_modules" ) + parser.add_argument( + '--version', + action='version', + version=f'%(prog)s {__version__}' + ) + return parser \ No newline at end of file diff --git a/socketsecurity/core/__init__.py b/socketsecurity/core/__init__.py index 96aaa9e..4be798a 100644 --- a/socketsecurity/core/__init__.py +++ b/socketsecurity/core/__init__.py @@ -25,9 +25,11 @@ ) from socketsecurity.core.exceptions import APIResourceNotFound from socketsecurity.core.licenses import Licenses - from .socket_config import SocketConfig from .utils import socket_globs +import importlib +logging_std = importlib.import_module("logging") + __all__ = [ "Core", @@ -375,11 +377,12 @@ def create_packages_dict(self, sbom_artifacts: list[SocketArtifact]) -> dict[str else: package.license_text = self.get_package_license_text(package) packages[package.id] = package - for top_id in package.topLevelAncestors: - if top_id not in top_level_count: - top_level_count[top_id] = 1 - else: - top_level_count[top_id] += 1 + if package.topLevelAncestors: + for top_id in package.topLevelAncestors: + if top_id not in top_level_count: + top_level_count[top_id] = 1 + else: + top_level_count[top_id] += 1 for package_id, package in packages.items(): package.transitives = top_level_count.get(package_id, 0) @@ -424,10 +427,14 @@ def get_repo_info(self, repo_slug: str, default_branch: str = "socket-default-br Exception: If API request fails """ try: + sdk_logger = logging_std.getLogger("socketdev") + original_level = sdk_logger.level + sdk_logger.setLevel(logging_std.CRITICAL) response = self.sdk.repos.repo(self.config.org_slug, repo_slug, use_types=True) + sdk_logger.setLevel(original_level) if not response.success: log.error(f"Failed to get repository: {response.status}") - log.error(response.message) + # log.error(response.message) except APIFailure: log.warning(f"Failed to get repository {repo_slug}, attempting to create it") try: From 9e8f9eb1514ce86f2146210766e32ea76967f7da Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Thu, 3 Apr 2025 13:38:37 -0700 Subject: [PATCH 2/3] Updated version --- socketsecurity/__init__.py | 2 +- socketsecurity/config.py | 2 +- socketsecurity/core/socket_config.py | 2 ++ socketsecurity/socketcli.py | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 46d0887..77b33d1 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.0.36' +__version__ = '2.0.37' diff --git a/socketsecurity/config.py b/socketsecurity/config.py index 79b0031..6ff5f6d 100644 --- a/socketsecurity/config.py +++ b/socketsecurity/config.py @@ -2,7 +2,7 @@ import os from dataclasses import asdict, dataclass from typing import List, Optional -from socketdev import __version__ +from socketsecurity import __version__ from socketdev import INTEGRATION_TYPES, IntegrationType diff --git a/socketsecurity/core/socket_config.py b/socketsecurity/core/socket_config.py index f05a382..f119d4b 100644 --- a/socketsecurity/core/socket_config.py +++ b/socketsecurity/core/socket_config.py @@ -5,6 +5,7 @@ import os from socketsecurity.core.issues import AllIssues +from socketsecurity import __version__ default_exclude_dirs = { @@ -27,6 +28,7 @@ class SocketConfig: security_policy: Dict = None all_issues: Optional['AllIssues'] = None excluded_dirs: Set[str] = field(default_factory=lambda: default_exclude_dirs) + version: str = __version__ def __post_init__(self): """Validate configuration after initialization""" diff --git a/socketsecurity/socketcli.py b/socketsecurity/socketcli.py index 612ad1e..c471bc1 100644 --- a/socketsecurity/socketcli.py +++ b/socketsecurity/socketcli.py @@ -45,6 +45,7 @@ def cli(): def main_code(): config = CliConfig.from_args() + log.info(f"Starting Socket Security CLI version {config.version}") log.debug(f"config: {config.to_dict()}") output_handler = OutputHandler(config) From f0cccdea83f2bb528b0b9f1850a49afd7884b584 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Thu, 3 Apr 2025 14:12:16 -0700 Subject: [PATCH 3/3] Updated version --- pyproject.toml | 4 ++-- scripts/build_container.sh | 28 ++++++++++++++-------------- socketsecurity/__init__.py | 2 +- socketsecurity/core/__init__.py | 2 ++ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b7d6513..03af13b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.0.36" +version = "2.0.38" requires-python = ">= 3.10" license = {"file" = "LICENSE"} dependencies = [ @@ -16,7 +16,7 @@ dependencies = [ 'GitPython', 'packaging', 'python-dotenv', - 'socket-sdk-python>=2.0.15' + 'socket-sdk-python>=2.0.20' ] readme = "README.md" description = "Socket Security CLI for CI/CD" diff --git a/scripts/build_container.sh b/scripts/build_container.sh index 6e19511..f268246 100755 --- a/scripts/build_container.sh +++ b/scripts/build_container.sh @@ -32,20 +32,20 @@ fi if [ $ENABLE_PYPI_BUILD = "pypi-build=prod" ]; then echo "Doing production build" - if ! python -m build --wheel --sdist; then - echo "Build failed" - exit 1 - fi - - if ! twine upload dist/*$VERSION*; then - echo "Upload to PyPI failed" - exit 1 - fi - - if ! verify_package $VERSION "https://pypi.org/simple"; then - echo "Failed to verify package on PyPI" - exit 1 - fi +# if ! python -m build --wheel --sdist; then +# echo "Build failed" +# exit 1 +# fi +# +# if ! twine upload dist/*$VERSION*; then +# echo "Upload to PyPI failed" +# exit 1 +# fi +# +# if ! verify_package $VERSION "https://pypi.org/simple"; then +# echo "Failed to verify package on PyPI" +# exit 1 +# fi docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:$VERSION . \ && docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:latest . \ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 77b33d1..ef8d284 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.0.37' +__version__ = '2.0.38' diff --git a/socketsecurity/core/__init__.py b/socketsecurity/core/__init__.py index 4be798a..81cab93 100644 --- a/socketsecurity/core/__init__.py +++ b/socketsecurity/core/__init__.py @@ -736,6 +736,8 @@ def get_source_data(package: Package, packages: dict) -> list: source = ("direct", manifests) introduced_by.append(source) else: + if not package.topLevelAncestors: + return introduced_by for top_id in package.topLevelAncestors: top_package = packages.get(top_id) if top_package: