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

Commit cc45ff4

Browse files
Doug/fix windows support (#123)
* Added gates so that resources module doesn't break windows * feat: centralize User-Agent string across all API clients - Add USER_AGENT constant to socketsecurity/__init__.py - Replace hardcoded 'SocketPythonScript/0.0.1' and 'SocketPythonCLI/0.0.1' with centralized USER_AGENT - Update all SCM clients (GitHub, GitLab) and CLI client to use USER_AGENT - Update unit tests to reference centralized constant - Pin GitHub Actions to commit SHAs for improved security and reproducibility - Fix minor GitLab client bugs (return type, pipeline source support) * Updated version-check.yml to used commit hashes * Minor type fixes
1 parent ee8b836 commit cc45ff4

File tree

11 files changed

+44
-44
lines changed

11 files changed

+44
-44
lines changed

‎Pipfile.lock‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.12"
9+
version = "2.2.15"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

‎socketsecurity/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.12'
2+
__version__ = '2.2.15'
3+
USER_AGENT = f'SocketPythonCLI/{__version__}'

‎socketsecurity/core/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from socketdev.repos import RepositoryInfo
1919
from socketdev.settings import SecurityPolicyRule
2020
import copy
21-
from socketsecurity import __version__
21+
from socketsecurity import __version__, USER_AGENT
2222
from socketsecurity.core.classes import (
2323
Alert,
2424
Diff,
@@ -39,6 +39,7 @@
3939
"Core",
4040
"log",
4141
"__version__",
42+
"USER_AGENT",
4243
]
4344

4445
version = __version__

‎socketsecurity/core/cli_client.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import requests
66

7+
from socketsecurity import USER_AGENT
78
from .exceptions import APIFailure
89
from .socket_config import SocketConfig
910

@@ -31,7 +32,7 @@ def request(
3132

3233
default_headers = {
3334
'Authorization': f"Basic {self._encoded_key}",
34-
'User-Agent': 'SocketPythonCLI/0.0.1',
35+
'User-Agent': USER_AGENT,
3536
"accept": "application/json"
3637
}
3738

‎socketsecurity/core/resource_utils.py‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
"""
22
System resource utilities for the Socket Security CLI.
33
"""
4-
import resource
54
import logging
5+
import sys
6+
7+
# The resource module is only available on Unix-like systems
8+
resource_available = False
9+
try:
10+
import resource
11+
resource_available = True
12+
except ImportError:
13+
# On Windows, the resource module is not available
14+
pass
615

716
log = logging.getLogger("socketdev")
817

918

1019
def get_file_descriptor_limit():
1120
"""
1221
Get the current file descriptor limit (equivalent to ulimit -n)
13-
22+
1423
Returns:
15-
tuple: (soft_limit, hard_limit) or (None, None) if error
24+
tuple: (soft_limit, hard_limit) or (None, None) if error or on Windows
1625
"""
26+
if not resource_available:
27+
# On Windows, resource module is not available
28+
return None, None
29+
1730
try:
1831
soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
1932
return soft_limit, hard_limit
@@ -25,26 +38,26 @@ def get_file_descriptor_limit():
2538
def check_file_count_against_ulimit(file_count, buffer_size=100):
2639
"""
2740
Check if the number of files would exceed the file descriptor limit
28-
41+
2942
Args:
3043
file_count (int): Number of files to check
3144
buffer_size (int): Safety buffer to leave for other file operations
32-
45+
3346
Returns:
3447
dict: Information about the check
3548
"""
3649
soft_limit, hard_limit = get_file_descriptor_limit()
37-
50+
3851
if soft_limit is None:
3952
return {
4053
"can_check": False,
4154
"error": "Could not determine file descriptor limit",
4255
"safe_to_process": True # Assume safe if we can't check
4356
}
44-
57+
4558
available_fds = soft_limit - buffer_size
4659
would_exceed = file_count > available_fds
47-
60+
4861
return {
4962
"can_check": True,
5063
"file_count": file_count,

‎socketsecurity/core/scm/client.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from abc import abstractmethod
22
from typing import Dict
33

4+
from socketsecurity import USER_AGENT
45
from ..cli_client import CliClient
56

67

@@ -28,7 +29,7 @@ class GithubClient(ScmClient):
2829
def get_headers(self) -> Dict:
2930
return {
3031
'Authorization': f"Bearer {self.token}",
31-
'User-Agent': 'SocketPythonScript/0.0.1',
32+
'User-Agent': USER_AGENT,
3233
"accept": "application/json"
3334
}
3435

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

5455
base_headers = {
55-
'User-Agent': 'SocketPythonScript/0.0.1',
56+
'User-Agent': USER_AGENT,
5657
"accept": "application/json"
5758
}
5859

‎socketsecurity/core/scm/github.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from git import Optional
77

8+
from socketsecurity import USER_AGENT
89
from socketsecurity.core import log
910
from socketsecurity.core.classes import Comment
1011
from socketsecurity.core.scm_comments import Comments
@@ -83,7 +84,7 @@ def from_env(cls, pr_number: Optional[str] = None) -> 'GithubConfig':
8384
event_action=event_action,
8485
headers={
8586
'Authorization': f"Bearer {token}",
86-
'User-Agent': 'SocketPythonScript/0.0.1',
87+
'User-Agent': USER_AGENT,
8788
"accept": "application/json"
8889
}
8990
)

‎socketsecurity/core/scm/gitlab.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from dataclasses import dataclass
44
from typing import Optional
55

6+
from socketsecurity import USER_AGENT
67
from socketsecurity.core import log
78
from socketsecurity.core.classes import Comment
89
from socketsecurity.core.scm_comments import Comments
@@ -79,7 +80,7 @@ def _get_auth_headers(token: str) -> dict:
7980
- Other tokens: Use PRIVATE-TOKEN as fallback
8081
"""
8182
base_headers = {
82-
'User-Agent': 'SocketPythonScript/0.0.1',
83+
'User-Agent': USER_AGENT,
8384
"accept": "application/json"
8485
}
8586

@@ -150,7 +151,7 @@ def _get_fallback_headers(self, original_headers: dict) -> dict:
150151
If using Bearer, fallback to PRIVATE-TOKEN and vice versa.
151152
"""
152153
base_headers = {
153-
'User-Agent': 'SocketPythonScript/0.0.1',
154+
'User-Agent': USER_AGENT,
154155
"accept": "application/json"
155156
}
156157

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

173174
# No fallback available
174-
return None
175+
return {}
175176

176177
def check_event_type(self) -> str:
177178
pipeline_source = self.config.pipeline_source.lower()
178-
if pipeline_source in ["web", 'merge_request_event', "push", "api"]:
179+
if pipeline_source in ["web", 'merge_request_event', "push", "api", 'pipeline']:
179180
if not self.config.mr_iid:
180181
return "main"
181182
return "diff"
@@ -234,8 +235,8 @@ def add_socket_comments(
234235
new_security_comment: bool = True,
235236
new_overview_comment: bool = True
236237
) -> None:
237-
existing_overview_comment = comments.get("overview")
238-
existing_security_comment = comments.get("security")
238+
existing_overview_comment = comments.get("overview", "")
239+
existing_security_comment = comments.get("security", "")
239240
if new_overview_comment:
240241
log.debug("New Dependency Overview comment")
241242
if existing_overview_comment is not None:
@@ -256,7 +257,7 @@ def add_socket_comments(
256257
self.post_comment(security_comment)
257258

258259
def remove_comment_alerts(self, comments: dict):
259-
security_alert = comments.get("security")
260+
security_alert = comments.get("security", "")
260261
if security_alert is not None:
261262
security_alert: Comment
262263
new_body = Comments.process_security_comment(security_alert, comments)

‎socketsecurity/socketcli.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def main_code():
114114

115115
# Git setup
116116
is_repo = False
117-
git_repo=None
117+
git_repo: Git
118118
try:
119119
git_repo = Git(config.target_path)
120120
is_repo = True

0 commit comments

Comments
(0)

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