Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Doug/fix windows support #123

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

Merged
dacoburn merged 5 commits into main from doug/fix-windows-support
Oct 24, 2025
Merged
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
20 changes: 0 additions & 20 deletions Pipfile.lock
View file Open in desktop

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "hatchling.build"

[project]
name = "socketsecurity"
version = "2.2.12"
version = "2.2.15"
requires-python = ">= 3.10"
license = {"file" = "LICENSE"}
dependencies = [
Expand Down
3 changes: 2 additions & 1 deletion socketsecurity/__init__.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__author__ = 'socket.dev'
__version__ = '2.2.12'
__version__ = '2.2.15'
USER_AGENT = f'SocketPythonCLI/{__version__}'
3 changes: 2 additions & 1 deletion socketsecurity/core/__init__.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from socketdev.repos import RepositoryInfo
from socketdev.settings import SecurityPolicyRule
import copy
from socketsecurity import __version__
from socketsecurity import __version__, USER_AGENT
from socketsecurity.core.classes import (
Alert,
Diff,
Expand All @@ -39,6 +39,7 @@
"Core",
"log",
"__version__",
"USER_AGENT",
]

version = __version__
Expand Down
3 changes: 2 additions & 1 deletion socketsecurity/core/cli_client.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import requests

from socketsecurity import USER_AGENT
from .exceptions import APIFailure
from .socket_config import SocketConfig

Expand Down Expand Up @@ -31,7 +32,7 @@ def request(

default_headers = {
'Authorization': f"Basic {self._encoded_key}",
'User-Agent': 'SocketPythonCLI/0.0.1',
'User-Agent': USER_AGENT,
"accept": "application/json"
}

Expand Down
29 changes: 21 additions & 8 deletions socketsecurity/core/resource_utils.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
"""
System resource utilities for the Socket Security CLI.
"""
import resource
import logging
import sys

# The resource module is only available on Unix-like systems
resource_available = False
try:
import resource
resource_available = True
except ImportError:
# On Windows, the resource module is not available
pass

log = logging.getLogger("socketdev")


def get_file_descriptor_limit():
"""
Get the current file descriptor limit (equivalent to ulimit -n)

Returns:
tuple: (soft_limit, hard_limit) or (None, None) if error
tuple: (soft_limit, hard_limit) or (None, None) if error or on Windows
"""
if not resource_available:
# On Windows, resource module is not available
return None, None

try:
soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
return soft_limit, hard_limit
Expand All @@ -25,26 +38,26 @@ def get_file_descriptor_limit():
def check_file_count_against_ulimit(file_count, buffer_size=100):
"""
Check if the number of files would exceed the file descriptor limit

Args:
file_count (int): Number of files to check
buffer_size (int): Safety buffer to leave for other file operations

Returns:
dict: Information about the check
"""
soft_limit, hard_limit = get_file_descriptor_limit()

if soft_limit is None:
return {
"can_check": False,
"error": "Could not determine file descriptor limit",
"safe_to_process": True # Assume safe if we can't check
}

available_fds = soft_limit - buffer_size
would_exceed = file_count > available_fds

return {
"can_check": True,
"file_count": file_count,
Expand Down
5 changes: 3 additions & 2 deletions socketsecurity/core/scm/client.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import abstractmethod
from typing import Dict

from socketsecurity import USER_AGENT
from ..cli_client import CliClient


Expand Down Expand Up @@ -28,7 +29,7 @@ class GithubClient(ScmClient):
def get_headers(self) -> Dict:
return {
'Authorization': f"Bearer {self.token}",
'User-Agent': 'SocketPythonScript/0.0.1',
'User-Agent': USER_AGENT,
"accept": "application/json"
}

Expand All @@ -52,7 +53,7 @@ def _get_gitlab_auth_headers(token: str) -> dict:
import os

base_headers = {
'User-Agent': 'SocketPythonScript/0.0.1',
'User-Agent': USER_AGENT,
"accept": "application/json"
}

Expand Down
3 changes: 2 additions & 1 deletion socketsecurity/core/scm/github.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from git import Optional

from socketsecurity import USER_AGENT
from socketsecurity.core import log
from socketsecurity.core.classes import Comment
from socketsecurity.core.scm_comments import Comments
Expand Down Expand Up @@ -83,7 +84,7 @@ def from_env(cls, pr_number: Optional[str] = None) -> 'GithubConfig':
event_action=event_action,
headers={
'Authorization': f"Bearer {token}",
'User-Agent': 'SocketPythonScript/0.0.1',
'User-Agent': USER_AGENT,
"accept": "application/json"
}
)
Expand Down
15 changes: 8 additions & 7 deletions socketsecurity/core/scm/gitlab.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dataclasses import dataclass
from typing import Optional

from socketsecurity import USER_AGENT
from socketsecurity.core import log
from socketsecurity.core.classes import Comment
from socketsecurity.core.scm_comments import Comments
Expand Down Expand Up @@ -79,7 +80,7 @@ def _get_auth_headers(token: str) -> dict:
- Other tokens: Use PRIVATE-TOKEN as fallback
"""
base_headers = {
'User-Agent': 'SocketPythonScript/0.0.1',
'User-Agent': USER_AGENT,
"accept": "application/json"
}

Expand Down Expand Up @@ -150,7 +151,7 @@ def _get_fallback_headers(self, original_headers: dict) -> dict:
If using Bearer, fallback to PRIVATE-TOKEN and vice versa.
"""
base_headers = {
'User-Agent': 'SocketPythonScript/0.0.1',
'User-Agent': USER_AGENT,
"accept": "application/json"
}

Expand All @@ -171,11 +172,11 @@ def _get_fallback_headers(self, original_headers: dict) -> dict:
}

# No fallback available
return None
return {}

def check_event_type(self) -> str:
pipeline_source = self.config.pipeline_source.lower()
if pipeline_source in ["web", 'merge_request_event', "push", "api"]:
if pipeline_source in ["web", 'merge_request_event', "push", "api", 'pipeline']:
if not self.config.mr_iid:
return "main"
return "diff"
Expand Down Expand Up @@ -234,8 +235,8 @@ def add_socket_comments(
new_security_comment: bool = True,
new_overview_comment: bool = True
) -> None:
existing_overview_comment = comments.get("overview")
existing_security_comment = comments.get("security")
existing_overview_comment = comments.get("overview", "")
existing_security_comment = comments.get("security", "")
if new_overview_comment:
log.debug("New Dependency Overview comment")
if existing_overview_comment is not None:
Expand All @@ -256,7 +257,7 @@ def add_socket_comments(
self.post_comment(security_comment)

def remove_comment_alerts(self, comments: dict):
security_alert = comments.get("security")
security_alert = comments.get("security", "")
if security_alert is not None:
security_alert: Comment
new_body = Comments.process_security_comment(security_alert, comments)
Expand Down
2 changes: 1 addition & 1 deletion socketsecurity/socketcli.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def main_code():

# Git setup
is_repo = False
git_repo = None
git_repo: Git
try:
git_repo = Git(config.target_path)
is_repo = True
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_gitlab_auth.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
from unittest.mock import patch, MagicMock

from socketsecurity import USER_AGENT
from socketsecurity.core.scm.gitlab import GitlabConfig


Expand Down Expand Up @@ -58,7 +59,7 @@ def test_all_headers_include_base_headers(self):

for token in test_tokens:
headers = GitlabConfig._get_auth_headers(token)
assert headers['User-Agent'] == 'SocketPythonScript/0.0.1'
assert headers['User-Agent'] == USER_AGENT
assert headers['accept'] == 'application/json'

@patch.dict(os.environ, {'CI_JOB_TOKEN': 'ci-token-123'})
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /