From: Patrick Donnelly Date: Thu, 30 Apr 2026 18:35:25 +0000 (-0700) Subject: script/ptl-tool: use Authorization header X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2eedf1dcbc261f53180c589db56b86ddae2741a7;p=ceph.git script/ptl-tool: use Authorization header Replaces basic authentication with the Authorization: Bearer header, obviating the need for the PTL_TOOL_GITHUB_USER environment variable and adhering to modern GitHub API authentication standards. Signed-off-by: Patrick Donnelly --- diff --git a/src/script/ptl-tool.py b/src/script/ptl-tool.py index 63c169f2629e..56303c98a738 100755 --- a/src/script/ptl-tool.py +++ b/src/script/ptl-tool.py @@ -29,7 +29,6 @@ # # Some important environment variables: # -# - PTL_TOOL_GITHUB_USER (your github username) # - PTL_TOOL_GITHUB_TOKEN (your github Personal access token, or what is stored in ~/.github_token) # - PTL_TOOL_REDMINE_USER (your redmine username) # - PTL_TOOL_REDMINE_API_KEY (your redmine api key, or what is stored in ~/redmine_key) @@ -189,7 +188,6 @@ BASE_REMOTE_URL = os.getenv("PTL_TOOL_BASE_REMOTE_URL", f"https://github.com/{BA CI_REPO = os.getenv("PTL_TOOL_CI_REPO", "ceph-ci") CI_REMOTE_URL = os.getenv("PTL_TOOL_CI_REMOTE_URL", f"git@github.com:{BASE_PROJECT}/{CI_REPO}.git") GITDIR = os.getenv("PTL_TOOL_GITDIR", ".") -GITHUB_USER = os.getenv("PTL_TOOL_GITHUB_USER", os.getenv("PTL_TOOL_USER", getuser())) GITHUB_TOKEN = None try: with open(expanduser("~/.github_token")) as f: @@ -239,7 +237,13 @@ BZ_MATCH = re.compile("(.*https?://bugzilla.redhat.com/.*)") TRACKER_MATCH = re.compile("(.*https?://tracker.ceph.com/.*)") def gitauth(): - return (GITHUB_USER, GITHUB_TOKEN) + class GitHubBearerAuth(requests.auth.AuthBase): + def __call__(self, r): + if GITHUB_TOKEN: + r.headers['Authorization'] = f'Bearer {GITHUB_TOKEN}' + r.headers['Accept'] = 'application/vnd.github.v3+json' + return r + return GitHubBearerAuth() def get(session, url, params=None, paging=True): if params is None: