Skip to content

Commit ceb0dd8

Browse files
adehadametzger
andcommitted
address lint
also added contributions from another pull request Co-Authored-By: Alex Metzger <[email protected]>
1 parent c70daea commit ceb0dd8

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

jira/client.py

+24-18
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,19 @@ def start_session(self):
264264
self._get_session(self.__auth)
265265

266266

267+
class TokenAuth(AuthBase):
268+
"""Bearer Token Authentication"""
269+
270+
def __init__(self, token: str):
271+
# setup any auth-related data here
272+
self._token = token
273+
274+
def __call__(self, r: requests.PreparedRequest):
275+
# modify and return the request
276+
r.headers["authorization"] = f"Bearer {self._token}"
277+
return r
278+
279+
267280
class JIRA:
268281
"""User interface to Jira.
269282
@@ -325,10 +338,10 @@ def __init__(
325338
self,
326339
server: str = None,
327340
options: Dict[str, Union[str, bool, Any]] = None,
328-
basic_auth: Union[None, Tuple[str, str]] = None,
341+
basic_auth: Optional[Tuple[str, str]] = None,
342+
token_auth: Optional[str] = None,
329343
oauth: Dict[str, Any] = None,
330344
jwt: Dict[str, Any] = None,
331-
token_auth: str =None,
332345
kerberos=False,
333346
kerberos_options: Dict[str, Any] = None,
334347
validate=False,
@@ -348,8 +361,8 @@ def __init__(
348361
or ``atlas-run-standalone`` commands. By default, this instance runs at
349362
``http://localhost:2990/jira``. The ``options`` argument can be used to set the Jira instance to use.
350363
351-
Authentication is handled with the ``basic_auth`` argument. If authentication is supplied (and is
352-
accepted by Jira), the client will remember it for subsequent requests.
364+
Authentication is handled with the ``basic_auth`` or ``token_auth`` argument.
365+
If authentication is supplied (and is accepted by Jira), the client will remember it for subsequent requests.
353366
354367
For quick command line access to a server, see the ``jirashell`` script included with this distribution.
355368
@@ -397,7 +410,7 @@ def __init__(
397410
398411
Example jwt structure: ``{'secret': SHARED_SECRET, 'payload': {'iss': PLUGIN_KEY}}``
399412
400-
token_auth (str): A string containg the token necessary for (PAT) token authorization.
413+
token_auth (str): A string containing the token necessary for (PAT) bearer token authorization.
401414
402415
validate (bool): If true it will validate your credentials first. Remember that if you are accessing Jira
403416
as anonymous it will fail to instantiate.
@@ -3417,16 +3430,19 @@ def _create_jwt_session(
34173430
self._session.verify = bool(self._options["verify"])
34183431
self._session.auth = jwt_auth
34193432

3420-
def _create_token_session(self, token_auth: str, timeout):
3433+
def _create_token_session(
3434+
self,
3435+
token_auth: str,
3436+
timeout: Optional[Union[Union[float, int], Tuple[float, float]]],
3437+
):
34213438
"""
34223439
Creates token-based session.
34233440
Header structure: "authorization": "Bearer <token_auth>"
34243441
"""
34253442
verify = self._options["verify"]
34263443
self._session = ResilientSession(timeout=timeout)
34273444
self._session.verify = verify
3428-
token_auth = TokenAuth(token_auth)
3429-
self._session.auth = token_auth
3445+
self._session.auth = TokenAuth(token_auth)
34303446

34313447
def _set_avatar(self, params, url, avatar):
34323448
data = {"id": avatar}
@@ -4826,13 +4842,3 @@ def __init__(self, options=None, basic_auth=None, oauth=None, async_=None):
48264842
self, options=options, basic_auth=basic_auth, oauth=oauth, async_=async_
48274843
)
48284844

4829-
class TokenAuth(AuthBase):
4830-
"""Token Authentication"""
4831-
def __init__(self, token: str):
4832-
# setup any auth-related data here
4833-
self._token = token
4834-
4835-
def __call__(self, r):
4836-
# modify and return the request
4837-
r.headers['authorization'] = "Bearer " + self._token
4838-
return r

0 commit comments

Comments
 (0)