mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 09:52:38 +02:00
✨ — Allow to customize agent User-Agent header (fix #78)
This commit is contained in:
parent
1b484da27a
commit
db54dd2cdd
3 changed files with 18 additions and 5 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
- ✨ — Allow to customize agent User-Agent header (#78)
|
||||
|
||||
## 0.7.4
|
||||
|
||||
Date: 2025-02-12
|
||||
|
|
|
@ -37,11 +37,17 @@ def log_failure(retry_state):
|
|||
class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes
|
||||
"""The Argos agent is responsible for running the checks and reporting the results."""
|
||||
|
||||
def __init__(self, server: str, auth: str, max_tasks: int, wait_time: int):
|
||||
def __init__( # pylint: disable-msg=too-many-positional-arguments
|
||||
self, server: str, auth: str, max_tasks: int, wait_time: int, user_agent: str
|
||||
):
|
||||
self.server = server
|
||||
self.max_tasks = max_tasks
|
||||
self.wait_time = wait_time
|
||||
self.auth = auth
|
||||
if user_agent == "":
|
||||
self.ua = user_agent
|
||||
else:
|
||||
self.ua = f" - {user_agent}"
|
||||
self._http_client: httpx.AsyncClient | None = None
|
||||
self._http_client_v4: httpx.AsyncClient | None = None
|
||||
self._http_client_v6: httpx.AsyncClient | None = None
|
||||
|
@ -53,13 +59,13 @@ class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes
|
|||
async def run(self):
|
||||
auth_header = {
|
||||
"Authorization": f"Bearer {self.auth}",
|
||||
"User-Agent": f"Argos Panoptes agent {VERSION}",
|
||||
"User-Agent": f"Argos Panoptes agent {VERSION}{self.ua}",
|
||||
}
|
||||
self._http_client = httpx.AsyncClient(headers=auth_header)
|
||||
|
||||
ua_header = {
|
||||
"User-Agent": f"Argos Panoptes {VERSION} "
|
||||
"(about: https://argos-monitoring.framasoft.org/)",
|
||||
f"(about: https://argos-monitoring.framasoft.org/){self.ua}",
|
||||
}
|
||||
self._http_client_v4 = httpx.AsyncClient(
|
||||
headers=ua_header,
|
||||
|
|
|
@ -92,7 +92,12 @@ def version():
|
|||
default="INFO",
|
||||
type=click.Choice(logging.LOG_LEVELS, case_sensitive=False),
|
||||
)
|
||||
def agent(server_url, auth, max_tasks, wait_time, log_level):
|
||||
@click.option(
|
||||
"--user-agent",
|
||||
default="",
|
||||
help="A custom string to append to the User-Agent header",
|
||||
)
|
||||
def agent(server_url, auth, max_tasks, wait_time, log_level, user_agent): # pylint: disable-msg=too-many-positional-arguments
|
||||
"""Get and run tasks for the provided server. Will wait for new tasks.
|
||||
|
||||
Usage: argos agent https://argos.example.org "auth-token-here"
|
||||
|
@ -108,7 +113,7 @@ def agent(server_url, auth, max_tasks, wait_time, log_level):
|
|||
from argos.logging import logger
|
||||
|
||||
logger.setLevel(log_level)
|
||||
agent_ = ArgosAgent(server_url, auth, max_tasks, wait_time)
|
||||
agent_ = ArgosAgent(server_url, auth, max_tasks, wait_time, user_agent)
|
||||
asyncio.run(agent_.run())
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue