Skip to content

Custom User-Agent header, Migrated all bare requests.post() to self.session.post(), Version bump to 2.3.0#68

Merged
SeaBlooms merged 2 commits into
mainfrom
release/2.3.0
Jul 2, 2026
Merged

Custom User-Agent header, Migrated all bare requests.post() to self.session.post(), Version bump to 2.3.0#68
SeaBlooms merged 2 commits into
mainfrom
release/2.3.0

Conversation

@SeaBlooms

@SeaBlooms SeaBlooms commented Jul 2, 2026

Copy link
Copy Markdown

Summary

Adds a custom User-Agent header to all HTTP requests made by the SDK client, enabling server-side tracking of customer usage. Also consolidates all HTTP calls through a single requests.Session for consistent retry behavior, connection pooling, and header propagation.

Changes

Custom User-Agent Header

  • Added SDK_VERSION class constant (2.3.0) to JupiterOneClient
  • Added optional user_agent parameter to __init__ for caller-provided identifiers
  • Constructs structured header: jupiterone-client-python/2.3.0 (default) or jupiterone-client-python/2.3.0 <custom-suffix>
  • Sets User-Agent on both self.headers and self.session.headers to cover all request paths

Usage:

# Default
client = JupiterOneClient(account="...", token="...")
# User-Agent: jupiterone-client-python/2.3.0

# Custom suffix
client = JupiterOneClient(account="...", token="...", user_agent="acme-scanner/1.0")
# User-Agent: jupiterone-client-python/2.3.0 acme-scanner/1.0

Session Migration

Migrated 8 bare requests.post() calls to self.session.post() across 4 methods:

  • list_alert_rules
  • get_alert_rule_details
  • list_questions
  • list_account_parameters

These methods were previously bypassing the session's retry logic (Retry with backoff on 429/502/503/504), connection pooling, and now the User-Agent header. All calls now include timeout=60 for consistency.

Version Bump

  • setup.py: 2.2.02.3.0
  • JupiterOneClient.SDK_VERSION: 2.3.0

Test Updates

Updated mock targets in 3 test files from @patch('jupiterone.client.requests.post') to @patch('requests.Session.post') to match the migrated code:

  • tests/test_alert_rule_methods.py (3 tests)
  • tests/test_list_questions.py (15 tests)
  • tests/test_misc_methods.py (2 tests)

Test Plan

  • All 69 tests in affected files pass
  • No linter errors introduced
  • No bare requests.post/get calls remain in client.py
  • User-Agent set on both self.headers and self.session.headers

@SeaBlooms SeaBlooms requested review from a team as code owners July 2, 2026 18:49
@SeaBlooms SeaBlooms merged commit ebe1ef9 into main Jul 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants