From cab34c6ad6f18355e57557398264f1ca45f17b69 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Fri, 15 Dec 2023 01:30:23 +0530 Subject: [PATCH] refactor: use a user specific token Signed-off-by: Akhil Narang --- dumpyarabot/config.py | 4 ++-- dumpyarabot/utils.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dumpyarabot/config.py b/dumpyarabot/config.py index 4b24cc7..2538002 100644 --- a/dumpyarabot/config.py +++ b/dumpyarabot/config.py @@ -5,9 +5,9 @@ class Settings(BaseSettings): TELEGRAM_BOT_TOKEN: str - JENKINS_TOKEN: str - JENKINS_URL: AnyHttpUrl + JENKINS_USER_NAME: str + JENKINS_USER_TOKEN: str SUDO_USERS: list[int] = [] diff --git a/dumpyarabot/utils.py b/dumpyarabot/utils.py index 28e0a4d..fbe2dc3 100644 --- a/dumpyarabot/utils.py +++ b/dumpyarabot/utils.py @@ -16,11 +16,11 @@ async def call_jenkins(args: schemas.DumpArguments) -> str: f"{settings.JENKINS_URL}/job/dumpyara/buildWithParameters", params=httpx.QueryParams( { - "token": settings.JENKINS_TOKEN, "URL": args.url.unicode_string(), "USE_ALT_DUMPER": args.use_alt_dumper, } ), + auth=(settings.JENKINS_USER_NAME, settings.JENKINS_USER_TOKEN), ) if response.status_code in (200, 201): return "Job started" @@ -37,7 +37,7 @@ async def cancel_jenkins_job(job_id: str) -> str: async with httpx.AsyncClient() as client: response = await client.post( f"{settings.JENKINS_URL}/job/dumpyara/{job_id}/stop", - params=httpx.QueryParams({"token": settings.JENKINS_TOKEN}), + auth=(settings.JENKINS_USER_NAME, settings.JENKINS_USER_TOKEN), ) if response.status_code == 200: return f"Job with ID {job_id} has been cancelled."