Skip to content

Commit 911331c

Browse files
jdaltonlelia
andauthored
feat(user-agent): rename the client to socket-python-cli (#320)
* feat(user-agent): rename client to socket-python-cli Use one client name for CLI and SDK requests. Preserve the current release version and record the change under Unreleased. * fix(deps): use Python SDK 3.6.2 Pin the published SDK and refresh its locked artifacts. Include the upgrade in the 2.11.11 release notes. Assisted-by: Codex:GPT-6 --------- Co-authored-by: lelia <2418071+lelia@users.noreply.github.com>
1 parent da31a83 commit 911331c

6 files changed

Lines changed: 53 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## 2.11.11
44

5+
### Changed: use lowercase Python CLI User-Agent
6+
7+
- Use `socket-python-cli/` consistently for direct API and SDK requests.
8+
9+
### Changed: bump the Socket Python SDK to 3.6.2
10+
11+
- Bumped the pinned Socket Python SDK (`socketdev`) from `3.6.1` to `3.6.2`
12+
to reject retired API credentials before use.
13+
514
### Changed: bump pinned Coana CLI to 15.14.1
615

716
- Bumped the pinned reachability engine (the Coana CLI) from `15.14.0` to

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies = [
1616
"gitpython==3.2.1",
1717
"packaging==26.3",
1818
"python-dotenv==1.2.4",
19-
"socketdev==3.6.1",
19+
"socketdev==3.6.2",
2020
"beautifulsoup4==4.15.0",
2121
"markdown==3.11.2",
2222
"brotli==1.2.1; platform_python_implementation == 'CPython'",

‎socketsecurity/__init__.py‎

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

‎socketsecurity/socketcli.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from socketdev import socketdev
1313
from socketdev.fullscans import FullScanParams
1414

15+
from socketsecurity import USER_AGENT_NAME
1516
from socketsecurity.config import CliConfig, truncate_commit_message
1617
from socketsecurity.core import Core
1718
from socketsecurity.core.classes import Diff
@@ -240,7 +241,7 @@ def apply_git_context(config: CliConfig) -> Tuple[bool, Optional[Git]]:
240241

241242

242243
def build_socket_sdk(config: CliConfig) -> socketdev:
243-
cli_user_agent_string = f"SocketPythonCLI/{config.version}"
244+
cli_user_agent_string = f"{USER_AGENT_NAME}/{config.version}"
244245
return socketdev(
245246
token=config.api_token,
246247
timeout=get_api_request_timeout(config),

‎tests/unit/test_user_agent.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pytest
2+
import requests
3+
4+
from socketsecurity import __version__
5+
from socketsecurity.config import CliConfig
6+
from socketsecurity.core.cli_client import CliClient
7+
from socketsecurity.core.socket_config import SocketConfig
8+
from socketsecurity.socketcli import build_socket_sdk
9+
10+
11+
@pytest.mark.parametrize("transport", ["direct", "sdk"])
12+
def test_cli_api_requests_identify_the_same_product(monkeypatch, transport):
13+
captured = []
14+
15+
def send(session, request, **kwargs):
16+
captured.append(request)
17+
response = requests.Response()
18+
response.status_code = 200
19+
response._content = b"{}"
20+
return response
21+
22+
monkeypatch.setattr(requests.sessions.Session, "send", send)
23+
if transport == "direct":
24+
CliClient(SocketConfig(api_key="synthetic-test-token")).request(
25+
"organizations"
26+
)
27+
else:
28+
sdk = build_socket_sdk(
29+
CliConfig(api_token="synthetic-test-token", repo="test-repo")
30+
)
31+
sdk.api.do_request("organizations")
32+
33+
assert len(captured) == 1
34+
assert captured[0].headers["User-Agent"] == f"socket-python-cli/{__version__}"
35+
assert captured[0].headers["Authorization"].startswith("Basic ")

‎uv.lock‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)