Skip to content

Commit

Permalink
feat: custom user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
tengzl33t committed May 13, 2024
1 parent 0eaca26 commit 41eac4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ build-backend = "poetry.core.masonry.api"
version_toml = [
"pyproject.toml:tool.poetry.version"
]
version_variable = [
"threatx_api_client/__init__.py:__version__"
]
major_on_zero = false
branch = "main"
upload_to_vcs_release = true
Expand Down
13 changes: 10 additions & 3 deletions threatx_api_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import aiohttp

from threatx_api_client.exceptions import (
TXAPIError,
TXAPIIncorrectCommandError,
TXAPIIncorrectEnvironmentError,
TXAPIIncorrectTokenError,
TXAPIResponseError, TXAPIError,
TXAPIResponseError,
)

__version__ = "1.2.0"


class Client:
"""Main API Client class."""
Expand All @@ -27,6 +30,10 @@ def __init__(self, api_env, api_key):
self.api_env = api_env
self.api_key = api_key

self.headers = {
"User-Agent": f"ThreatX-API-Client/{__version__}"
}

self.parallel_requests = 10

self.base_url = self.__get_api_env_host()
Expand Down Expand Up @@ -81,7 +88,7 @@ async def __process_response(self, path: str, available_commands: list, payloads
if payload.get("command") not in available_commands:
raise TXAPIIncorrectCommandError(payload.get("command"))

async with aiohttp.ClientSession(base_url=self.base_url) as session:
async with aiohttp.ClientSession(base_url=self.base_url, headers=self.headers) as session:
responses = await asyncio.gather(*(
self.__post(
session,
Expand All @@ -100,7 +107,7 @@ async def __login(self):
if not self.api_key:
raise TXAPIIncorrectTokenError("Please provide TX API Key.")

async with aiohttp.ClientSession(base_url=self.base_url) as session:
async with aiohttp.ClientSession(base_url=self.base_url, headers=self.headers) as session:
response = await asyncio.gather(
self.__post(
session,
Expand Down

0 comments on commit 41eac4e

Please sign in to comment.