Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 8 additions & 8 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
with:
fetch-depth: 0
- uses: actions/setup-python@v5
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
with:
python-version: '3.x'

Expand Down Expand Up @@ -43,14 +43,14 @@ jobs:

- name: Publish to Test PyPI
if: steps.version_check.outputs.exists != 'true'
uses: pypa/gh-action-pypi-publish@v1.12.4
uses: pypa/gh-action-pypi-publish@ab69e431e9c9f48a3310be0a56527c679f56e04d
with:
repository-url: https://test.pypi.org/legacy/
verbose: true

- name: Comment on PR
if: steps.version_check.outputs.exists != 'true'
uses: actions/github-script@v7
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
env:
VERSION: ${{ env.VERSION }}
with:
Expand Down Expand Up @@ -120,21 +120,21 @@ jobs:
exit 1

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349

- name: Login to Docker Hub with Organization Token
if: steps.verify_package.outputs.success == 'true'
uses: docker/login-action@v3
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build & Push Docker Preview
if: steps.verify_package.outputs.success == 'true'
uses: docker/build-push-action@v5
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
env:
VERSION: ${{ env.VERSION }}
with:
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
with:
fetch-depth: 0
- uses: actions/setup-python@v5
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
with:
python-version: '3.x'

Expand Down Expand Up @@ -66,16 +66,16 @@ jobs:

- name: Publish to PyPI
if: steps.version_check.outputs.pypi_exists != 'true'
uses: pypa/gh-action-pypi-publish@v1.12.4
uses: pypa/gh-action-pypi-publish@ab69e431e9c9f48a3310be0a56527c679f56e04d

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349

- name: Login to Docker Hub with Organization Token
uses: docker/login-action@v3
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand All @@ -102,7 +102,7 @@ jobs:
if: |
steps.verify_package.outputs.success == 'true' &&
steps.docker_check.outputs.docker_exists != 'true'
uses: docker/build-push-action@v5
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
env:
VERSION: ${{ env.VERSION }}
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/version-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
check_version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
with:
fetch-depth: 0 # Fetch all history for all branches

Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
"

- name: Manage PR Comment
uses: actions/github-script@v7
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
if: always()
env:
MAIN_VERSION: ${{ env.MAIN_VERSION }}
Expand Down
20 changes: 0 additions & 20 deletions Pipfile.lock

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
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.11"
version = "2.2.14"
requires-python = ">= 3.10"
license = {"file" = "LICENSE"}
dependencies = [
Expand Down
3 changes: 2 additions & 1 deletion socketsecurity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__author__ = 'socket.dev'
__version__ = '2.2.11'
__version__ = '2.2.14'
USER_AGENT = f'SocketPythonCLI/{__version__}'
3 changes: 2 additions & 1 deletion socketsecurity/core/__init__.py
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
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
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
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
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
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
3 changes: 2 additions & 1 deletion tests/unit/test_gitlab_auth.py
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