Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the .verify property correctly #1202

Merged
merged 4 commits into from
Oct 30, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def __init__(
* rest_api_version -- the version of the REST resources under rest_path to use. Defaults to ``2``.
* agile_rest_path - the REST path to use for Jira Agile requests. Defaults to ``greenhopper`` (old, private
API). Check :py:class:`jira.resources.GreenHopperResource` for other supported values.
* verify -- Verify SSL certs. Defaults to ``True``.
* verify (Union[bool, str]) -- Verify SSL certs. Defaults to ``True``.
* client_cert -- a tuple of (cert,key) for the requests library for client side SSL
* check_update -- Check whether using the newest python-jira library version.
* headers -- a dict to update the default headers the session uses for all API requests.
Expand Down Expand Up @@ -480,7 +480,6 @@ def __init__(
self._create_oauth_session(oauth, timeout)
elif basic_auth:
self._create_http_basic_session(*basic_auth, timeout=timeout)
self._session.headers.update(self._options["headers"])
elif jwt:
self._create_jwt_session(jwt, timeout)
elif token_auth:
Expand All @@ -492,12 +491,12 @@ def __init__(
# always log in for cookie based auth, as we need a first request to be logged in
validate = True
else:
verify = bool(self._options["verify"])
self._session = ResilientSession(timeout=timeout)
self._session.verify = verify

# Add the client authentication certificate to the request if configured
self._add_client_cert_to_session()
# Add the SSL Cert to the request if configured
self._add_ssl_cert_to_session()

self._session.headers.update(self._options["headers"])

Expand Down Expand Up @@ -560,7 +559,6 @@ def _create_cookie_auth(
):
self._session = ResilientSession(timeout=timeout)
self._session.auth = JiraCookieAuth(self._session, self.session, auth)
self._session.verify = bool(self._options["verify"])

def _check_update_(self):
"""Check if the current version of the library is outdated."""
Expand Down Expand Up @@ -3345,15 +3343,12 @@ def _create_http_basic_session(
Returns:
ResilientSession
"""
verify = bool(self._options["verify"])
self._session = ResilientSession(timeout=timeout)
self._session.verify = verify
self._session.auth = (username, password)

def _create_oauth_session(
self, oauth, timeout: Optional[Union[Union[float, int], Tuple[float, float]]]
):
verify = bool(self._options["verify"])

from oauthlib.oauth1 import SIGNATURE_RSA
from requests_oauthlib import OAuth1
Expand All @@ -3366,15 +3361,13 @@ def _create_oauth_session(
resource_owner_secret=oauth["access_token_secret"],
)
self._session = ResilientSession(timeout)
self._session.verify = verify
self._session.auth = oauth_instance

def _create_kerberos_session(
self,
timeout: Optional[Union[Union[float, int], Tuple[float, float]]],
kerberos_options=None,
):
verify = bool(self._options["verify"])
if kerberos_options is None:
kerberos_options = {}

Expand All @@ -3391,7 +3384,6 @@ def _create_kerberos_session(
)

self._session = ResilientSession(timeout=timeout)
self._session.verify = verify
self._session.auth = HTTPKerberosAuth(
mutual_authentication=mutual_authentication
)
Expand All @@ -3403,6 +3395,13 @@ def _add_client_cert_to_session(self):
client_cert: Tuple[str, str] = self._options["client_cert"] # to help mypy
self._session.cert = client_cert

def _add_ssl_cert_to_session(self):
"""
Adds the client certificate to the request if configured through the constructor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this adding the client certificate, or the certificate authority?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this was a copy paste job I failed to update. I've now updated both the name of the function and improved the docstring for clarity.

"""
ssl_cert: Union[bool, str] = self._options["verify"] # to help mypy
self._session.verify = ssl_cert

@staticmethod
def _timestamp(dt: datetime.timedelta = None):
t = datetime.datetime.utcnow()
Expand All @@ -3428,7 +3427,6 @@ def _create_jwt_session(
for f in jwt["payload"].items():
jwt_auth.add_field(f[0], f[1])
self._session = ResilientSession(timeout=timeout)
self._session.verify = bool(self._options["verify"])
self._session.auth = jwt_auth

def _create_token_session(
Expand All @@ -3440,9 +3438,7 @@ def _create_token_session(
Creates token-based session.
Header structure: "authorization": "Bearer <token_auth>"
"""
verify = self._options["verify"]
self._session = ResilientSession(timeout=timeout)
self._session.verify = verify
self._session.auth = TokenAuth(token_auth)

def _set_avatar(self, params, url, avatar):
Expand Down