From e0610431bd7d5e1c5ce670c82c0733199f1adfe2 Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 21 Apr 2025 08:02:52 -0700 Subject: [PATCH 1/2] Updated config params for support private/public repo setting --- pyproject.toml | 2 +- socketsecurity/__init__.py | 2 +- socketsecurity/config.py | 38 +++++++++++++++++++++++-------------- socketsecurity/socketcli.py | 6 +++++- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d500e71..f6ba24a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.0.52" +version = "2.0.53" requires-python = ">= 3.10" license = {"file" = "LICENSE"} dependencies = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 61801ac..097cd85 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.52' +__version__ = '2.0.53' diff --git a/socketsecurity/config.py b/socketsecurity/config.py index 007eae2..fe7c3eb 100644 --- a/socketsecurity/config.py +++ b/socketsecurity/config.py @@ -50,6 +50,7 @@ class CliConfig: timeout: Optional[int] = 1200 exclude_license_details: bool = False include_module_folders: bool = False + repo_is_public: bool = False version: str = __version__ jira_plugin: PluginConfig = field(default_factory=PluginConfig) slack_plugin: PluginConfig = field(default_factory=PluginConfig) @@ -94,6 +95,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, + 'repo_is_public': args.repo_is_public, 'version': __version__ } config_args.update({ @@ -147,30 +149,32 @@ def create_argument_parser() -> argparse.ArgumentParser: required=False ) repo_group.add_argument( + "--repo-is-public", + dest="default_branch", + action="store_true", + help="If set it will flag a new repository creation as public. Defaults to false." + ) + repo_group.add_argument( + "--branch", + metavar="", + help="Branch name", + default="" + ) + + integration_group = parser.add_argument_group('Integration') + integration_group.add_argument( "--integration", choices=INTEGRATION_TYPES, metavar="", - help="Integration type", + help="Integration type of api, github, gitlab, azure, or bitbucket. Defaults to api", default="api" ) - repo_group.add_argument( + integration_group.add_argument( "--owner", metavar="", help="Name of the integration owner, defaults to the socket organization slug", required=False ) - repo_group.add_argument( - "--branch", - metavar="", - help="Branch name", - default="" - ) - repo_group.add_argument( - "--committers", - metavar="", - help="Committer(s) to filter by", - nargs="*" - ) # Pull Request and Commit info pr_group = parser.add_argument_group('Pull Request and Commit') @@ -209,6 +213,12 @@ def create_argument_parser() -> argparse.ArgumentParser: dest="commit_sha", help=argparse.SUPPRESS ) + pr_group.add_argument( + "--committers", + metavar="", + help="Committer for the commit (comma separated)", + nargs="*" + ) # Path and File options path_group = parser.add_argument_group('Path and File') diff --git a/socketsecurity/socketcli.py b/socketsecurity/socketcli.py index 64c3f3c..81123a9 100644 --- a/socketsecurity/socketcli.py +++ b/socketsecurity/socketcli.py @@ -150,6 +150,10 @@ def main_code(): org_slug = core.config.org_slug integration_type = config.integration_type integration_org_slug = config.integration_org_slug or org_slug + try: + pr_number = int(config.pr_number) + except (ValueError, TypeError): + pr_number = 0 params = FullScanParams( org_slug=org_slug, @@ -159,7 +163,7 @@ def main_code(): branch=config.branch, commit_message=config.commit_message, commit_hash=config.commit_sha, - pull_request=config.pr_number, + pull_request=pr_number, committers=config.committers, make_default_branch=config.default_branch, set_as_pending_head=True From e3d8dc3dc114c373f4ec34dd188e495a974088fc Mon Sep 17 00:00:00 2001 From: Douglas Coburn Date: Mon, 21 Apr 2025 08:14:37 -0700 Subject: [PATCH 2/2] Added repo visibility to shared config --- pyproject.toml | 2 +- socketsecurity/__init__.py | 2 +- socketsecurity/config.py | 2 +- socketsecurity/core/__init__.py | 7 ++++++- socketsecurity/core/socket_config.py | 1 + socketsecurity/socketcli.py | 2 ++ 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1799b19..1808d35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "socketsecurity" -version = "2.0.54" +version = "2.0.55" requires-python = ">= 3.10" license = {"file" = "LICENSE"} dependencies = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 92958d3..3791e05 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,2 +1,2 @@ __author__ = 'socket.dev' -__version__ = '2.0.54' +__version__ = '2.0.55' diff --git a/socketsecurity/config.py b/socketsecurity/config.py index fe7c3eb..5542402 100644 --- a/socketsecurity/config.py +++ b/socketsecurity/config.py @@ -150,7 +150,7 @@ def create_argument_parser() -> argparse.ArgumentParser: ) repo_group.add_argument( "--repo-is-public", - dest="default_branch", + dest="repo_is_public", action="store_true", help="If set it will flag a new repository creation as public. Defaults to false." ) diff --git a/socketsecurity/core/__init__.py b/socketsecurity/core/__init__.py index 007af25..7329ea7 100644 --- a/socketsecurity/core/__init__.py +++ b/socketsecurity/core/__init__.py @@ -439,7 +439,12 @@ def get_repo_info(self, repo_slug: str, default_branch: str = "socket-default-br log.warning(f"Failed to get repository {repo_slug}, attempting to create it") try: - create_response = self.sdk.repos.post(self.config.org_slug, name=repo_slug, default_branch=default_branch) + create_response = self.sdk.repos.post( + self.config.org_slug, + name=repo_slug, + default_branch=default_branch, + visibility=self.config.repo_visibility + ) # Check if the response is empty (failure) or has content (success) if not create_response: diff --git a/socketsecurity/core/socket_config.py b/socketsecurity/core/socket_config.py index f119d4b..1b5676c 100644 --- a/socketsecurity/core/socket_config.py +++ b/socketsecurity/core/socket_config.py @@ -26,6 +26,7 @@ class SocketConfig: full_scan_path: Optional[str] = None repository_path: Optional[str] = None security_policy: Dict = None + repo_visibility: Optional[str] = 'private' all_issues: Optional['AllIssues'] = None excluded_dirs: Set[str] = field(default_factory=lambda: default_exclude_dirs) version: str = __version__ diff --git a/socketsecurity/socketcli.py b/socketsecurity/socketcli.py index 81123a9..fdb038e 100644 --- a/socketsecurity/socketcli.py +++ b/socketsecurity/socketcli.py @@ -148,6 +148,8 @@ def main_code(): log.debug("Found manifest files or forced scan, proceeding") org_slug = core.config.org_slug + if config.repo_is_public: + core.config.repo_visibility = "public" integration_type = config.integration_type integration_org_slug = config.integration_org_slug or org_slug try: