Skip to content

Commit 808f31c

Browse files
committed
Add support for basics API and pinned workflow actions to commit hash
1 parent 0a7f7ad commit 808f31c

File tree

8 files changed

+134
-11
lines changed

8 files changed

+134
-11
lines changed

.github/workflows/pr-preview.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
contents: read
1212
pull-requests: write
1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
1515
with:
1616
fetch-depth: 0
17-
- uses: actions/setup-python@v5
17+
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
1818
with:
1919
python-version: '3.x'
2020

@@ -57,14 +57,14 @@ jobs:
5757
5858
- name: Publish to Test PyPI
5959
if: steps.version_check.outputs.exists != 'true'
60-
uses: pypa/gh-action-pypi-publish@v1.12.4
60+
uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.4
6161
with:
6262
repository-url: https://test.pypi.org/legacy/
6363
verbose: true
6464

6565
- name: Comment on PR
6666
if: steps.version_check.outputs.exists != 'true'
67-
uses: actions/github-script@v7
67+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
6868
env:
6969
VERSION: ${{ env.VERSION }}
7070
with:

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
id-token: write
1111
contents: read
1212
steps:
13-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
1414
with:
1515
fetch-depth: 0
16-
- uses: actions/setup-python@v5
16+
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
1717
with:
1818
python-version: '3.x'
1919

@@ -54,7 +54,7 @@ jobs:
5454
5555
- name: Publish to PyPI
5656
if: steps.version_check.outputs.pypi_exists != 'true'
57-
uses: pypa/gh-action-pypi-publish@v1.12.4
57+
uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.4
5858

5959
- name: Verify package is installable
6060
id: verify_package

.github/workflows/version-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
check_version:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
1515
with:
1616
fetch-depth: 0 # Fetch all history for all branches
1717

@@ -39,7 +39,7 @@ jobs:
3939
"
4040
4141
- name: Manage PR Comment
42-
uses: actions/github-script@v7
42+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
4343
if: always()
4444
env:
4545
MAIN_VERSION: ${{ env.MAIN_VERSION }}

pyproject.toml

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

55
[project]
66
name = "socketdev"
7-
version = "3.0.7"
7+
version = "3.0.8"
88
requires-python = ">= 3.9"
99
dependencies = [
1010
'requests',

socketdev/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from socketdev.auditlog import AuditLog
2525
from socketdev.analytics import Analytics
2626
from socketdev.alerttypes import AlertTypes
27+
from socketdev.basics import Basics
2728
from socketdev.log import log
2829

2930
__author__ = "socket.dev"
@@ -72,6 +73,7 @@ def __init__(self, token: str, timeout: int = 1200):
7273
self.auditlog = AuditLog(self.api)
7374
self.analytics = Analytics(self.api)
7475
self.alerttypes = AlertTypes(self.api)
76+
self.basics = Basics(self.api)
7577

7678
@staticmethod
7779
def set_timeout(timeout: int):

socketdev/basics/__init__.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import logging
2+
from typing import Optional, Union
3+
from dataclasses import dataclass, asdict
4+
5+
log = logging.getLogger("socketdev")
6+
7+
8+
@dataclass
9+
class SocketBasicsConfig:
10+
"""Data class representing Socket Basics configuration settings."""
11+
pythonSastEnabled: bool = False
12+
golangSastEnabled: bool = False
13+
javascriptSastEnabled: bool = False
14+
secretScanningEnabled: bool = False
15+
trivyImageEnabled: bool = False
16+
trivyDockerfileEnabled: bool = False
17+
socketScanningEnabled: bool = False
18+
socketScaEnabled: bool = False
19+
additionalParameters: str = ""
20+
21+
def __getitem__(self, key):
22+
return getattr(self, key)
23+
24+
def to_dict(self):
25+
return asdict(self)
26+
27+
@classmethod
28+
def from_dict(cls, data: dict) -> "SocketBasicsConfig":
29+
return cls(
30+
pythonSastEnabled=data.get("pythonSastEnabled", False),
31+
golangSastEnabled=data.get("golangSastEnabled", False),
32+
javascriptSastEnabled=data.get("javascriptSastEnabled", False),
33+
secretScanningEnabled=data.get("secretScanningEnabled", False),
34+
trivyImageEnabled=data.get("trivyImageEnabled", False),
35+
trivyDockerfileEnabled=data.get("trivyDockerfileEnabled", False),
36+
socketScanningEnabled=data.get("socketScanningEnabled", False),
37+
socketScaEnabled=data.get("socketScaEnabled", False),
38+
additionalParameters=data.get("additionalParameters", ""),
39+
)
40+
41+
42+
@dataclass
43+
class SocketBasicsResponse:
44+
"""Data class representing the response from Socket Basics API calls."""
45+
success: bool
46+
status: int
47+
config: Optional[SocketBasicsConfig] = None
48+
message: Optional[str] = None
49+
50+
def __getitem__(self, key):
51+
return getattr(self, key)
52+
53+
def to_dict(self):
54+
return asdict(self)
55+
56+
@classmethod
57+
def from_dict(cls, data: dict) -> "SocketBasicsResponse":
58+
return cls(
59+
config=SocketBasicsConfig.from_dict(data) if data else None,
60+
success=True,
61+
status=200,
62+
)
63+
64+
65+
class Basics:
66+
"""
67+
Socket Basics API client for managing CI/CD security scanning configurations.
68+
69+
Socket Basics is a security scanning suite that includes:
70+
- SAST (Static Application Security Testing) for Python, Go, and JavaScript
71+
- Secret scanning for hardcoded credentials
72+
- Container security for Docker images and Dockerfiles
73+
- Socket SCA dependency scanning
74+
"""
75+
76+
def __init__(self, api):
77+
self.api = api
78+
79+
def get_config(
80+
self, org_slug: str, use_types: bool = False
81+
) -> Union[dict, SocketBasicsResponse]:
82+
"""
83+
Get Socket Basics configuration for an organization.
84+
85+
Args:
86+
org_slug: Organization slug
87+
use_types: Whether to return typed response objects (default: False)
88+
89+
Returns:
90+
dict or SocketBasicsResponse: Configuration settings for Socket Basics
91+
92+
Example:
93+
>>> basics = socketdev_client.basics
94+
>>> config = basics.get_config("my-org")
95+
>>> print(config["pythonSastEnabled"])
96+
97+
>>> # Using typed response
98+
>>> response = basics.get_config("my-org", use_types=True)
99+
>>> print(response.config.pythonSastEnabled)
100+
"""
101+
path = f"orgs/{org_slug}/settings/socket-basics"
102+
response = self.api.do_request(path=path, method="GET")
103+
104+
if response.status_code == 200:
105+
config_data = response.json()
106+
if use_types:
107+
return SocketBasicsResponse.from_dict(config_data)
108+
return config_data
109+
110+
error_message = response.json().get("error", {}).get("message", "Unknown error")
111+
log.error(f"Failed to get Socket Basics configuration: {response.status_code}, message: {error_message}")
112+
113+
if use_types:
114+
return SocketBasicsResponse(
115+
success=False,
116+
status=response.status_code,
117+
config=None,
118+
message=error_message
119+
)
120+
return {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This directory is created for the basics module

socketdev/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.7"
1+
__version__ = "3.0.8"

0 commit comments

Comments
 (0)