Skip to content

Commit

Permalink
address lint
Browse files Browse the repository at this point in the history
also added contributions from another pull request

Co-Authored-By: Alex Metzger <asm@asm.io>
  • Loading branch information
adehad and ametzger committed Oct 24, 2021
1 parent c70daea commit ceb0dd8
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,19 @@ def start_session(self):
self._get_session(self.__auth)


class TokenAuth(AuthBase):
"""Bearer Token Authentication"""

def __init__(self, token: str):
# setup any auth-related data here
self._token = token

def __call__(self, r: requests.PreparedRequest):
# modify and return the request
r.headers["authorization"] = f"Bearer {self._token}"
return r


class JIRA:
"""User interface to Jira.
Expand Down Expand Up @@ -325,10 +338,10 @@ def __init__(
self,
server: str = None,
options: Dict[str, Union[str, bool, Any]] = None,
basic_auth: Union[None, Tuple[str, str]] = None,
basic_auth: Optional[Tuple[str, str]] = None,
token_auth: Optional[str] = None,
oauth: Dict[str, Any] = None,
jwt: Dict[str, Any] = None,
token_auth: str =None,
kerberos=False,
kerberos_options: Dict[str, Any] = None,
validate=False,
Expand All @@ -348,8 +361,8 @@ def __init__(
or ``atlas-run-standalone`` commands. By default, this instance runs at
``http://localhost:2990/jira``. The ``options`` argument can be used to set the Jira instance to use.
Authentication is handled with the ``basic_auth`` argument. If authentication is supplied (and is
accepted by Jira), the client will remember it for subsequent requests.
Authentication is handled with the ``basic_auth`` or ``token_auth`` argument.
If authentication is supplied (and is accepted by Jira), the client will remember it for subsequent requests.
For quick command line access to a server, see the ``jirashell`` script included with this distribution.
Expand Down Expand Up @@ -397,7 +410,7 @@ def __init__(
Example jwt structure: ``{'secret': SHARED_SECRET, 'payload': {'iss': PLUGIN_KEY}}``
token_auth (str): A string containg the token necessary for (PAT) token authorization.
token_auth (str): A string containing the token necessary for (PAT) bearer token authorization.
validate (bool): If true it will validate your credentials first. Remember that if you are accessing Jira
as anonymous it will fail to instantiate.
Expand Down Expand Up @@ -3417,16 +3430,19 @@ def _create_jwt_session(
self._session.verify = bool(self._options["verify"])
self._session.auth = jwt_auth

def _create_token_session(self, token_auth: str, timeout):
def _create_token_session(
self,
token_auth: str,
timeout: Optional[Union[Union[float, int], Tuple[float, float]]],
):
"""
Creates token-based session.
Header structure: "authorization": "Bearer <token_auth>"
"""
verify = self._options["verify"]
self._session = ResilientSession(timeout=timeout)
self._session.verify = verify
token_auth = TokenAuth(token_auth)
self._session.auth = token_auth
self._session.auth = TokenAuth(token_auth)

def _set_avatar(self, params, url, avatar):
data = {"id": avatar}
Expand Down Expand Up @@ -4826,13 +4842,3 @@ def __init__(self, options=None, basic_auth=None, oauth=None, async_=None):
self, options=options, basic_auth=basic_auth, oauth=oauth, async_=async_
)

class TokenAuth(AuthBase):
"""Token Authentication"""
def __init__(self, token: str):
# setup any auth-related data here
self._token = token

def __call__(self, r):
# modify and return the request
r.headers['authorization'] = "Bearer " + self._token
return r

0 comments on commit ceb0dd8

Please sign in to comment.