From b0a79b3fe4eb674d72688db419e3142f77ba7523 Mon Sep 17 00:00:00 2001 From: "Hans Raphael (BD/TOA-SWE6)" Date: Wed, 7 May 2025 16:47:22 +0200 Subject: [PATCH] Pass header to request session (#1533) + (#1526) --- atlassian/bitbucket/__init__.py | 2 +- atlassian/rest_client.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/atlassian/bitbucket/__init__.py b/atlassian/bitbucket/__init__.py index 1f24688e7..b200f7c76 100644 --- a/atlassian/bitbucket/__init__.py +++ b/atlassian/bitbucket/__init__.py @@ -162,7 +162,7 @@ def get_users_info(self, user_filter=None, start=0, limit=25): params["filter"] = user_filter return self._get_paged(url, params=params) - @property + def get_current_license(self): """ Retrieves details about the current license, as well as the current status of the system with diff --git a/atlassian/rest_client.py b/atlassian/rest_client.py index 335fb1633..34a9cb115 100644 --- a/atlassian/rest_client.py +++ b/atlassian/rest_client.py @@ -94,7 +94,8 @@ def __init__( max_backoff_retries: int = 1000, backoff_factor=1.0, backoff_jitter=1.0, - retry_with_header=True, + retry_with_header=True, + header=None ): """ init function for the AtlassianRestAPI object. @@ -197,6 +198,8 @@ def __init__( self._create_kerberos_session(kerberos) elif cookies is not None: self._session.cookies.update(cookies) + elif header is not None: + self._create_header_session(header) def __enter__(self) -> Self: return self @@ -210,7 +213,10 @@ def _create_basic_session(self, username: str, password: str) -> None: def _create_token_session(self, token: str) -> None: self._update_header("Authorization", f"Bearer {token.strip()}") - def _create_kerberos_session(self, _: object) -> None: + def _create_header_session(self, header: dict) -> None: + self._session.headers.update(header) + + def _create_kerberos_session(self, _): from requests_kerberos import OPTIONAL, HTTPKerberosAuth self._session.auth = HTTPKerberosAuth(mutual_authentication=OPTIONAL)