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

Logging=False is not honored in _create_oauth_session #1777

Open
1 of 4 tasks
brooookemiller opened this issue Dec 13, 2023 · 1 comment
Open
1 of 4 tasks

Logging=False is not honored in _create_oauth_session #1777

brooookemiller opened this issue Dec 13, 2023 · 1 comment
Labels
good first issue New contributors welcome !

Comments

@brooookemiller
Copy link

Bug summary

As a user setting Logging=False as a param on initialization of the JIRA class, I'd like for logging to be turned off entirely, so that I can structure my logs flexibly within my service wrapped around this class. However, I recently noticed (presumably following this change) the following issues that lead to this Logging = False preference not to necessarily be honored as I'd expect it to be.

Areas for Improvement:

  1. Tracebacks being printed due to using logging.exception in _create_oauth_session. This is notably the only place in the file where an exception is logged (here).
  2. Each attempt to try a different signature_method for the creds generates an exception currently, although it's intentional to attempt to iterate through other options until we reach the last fallback option.
  3. The exception log statement mentions "Consider specifying the signature via oauth['signature_method']" even if the signature_method was provided as a param on the initialization. (Actually recognizing whether a signature_method was used before recommending that would be an improvement.)

References:

  • The logic to acknowledge the Logging param is set here

Rough Suggestions:

method_provided = oauth.get("signature_method")
....
except JIRAError as error:
    if not method_provided:
        _logging.debug(
            f"Failed to create OAuth session with signature_method={sha_type}."
            + "Attempting fallback method(s)."
            + "Consider specifying the signature via oauth['signature_method']."
        )
    else:
        _logging.debug(
            f"Failed to create OAuth session with signature_method={sha_type}."
            + "Attempting fallback method(s)."
        )
    if sha_type is FALLBACK_SHA:
        raise error  # We have exhausted our options, bubble up exception

Is there an existing issue for this?

  • I have searched the existing issues

Jira Instance type

Jira Cloud (Hosted by Atlassian)

Jira instance version

9.7.1

jira-python version

3.5.2

Python Interpreter version

3.10

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

# 1. Given a Jira client instance
jira: JIRA
# 2. When I initialize the Jira client instance and my OAuth credentials have expired and call the following function 
JIRA(options={"server": uri}, oauth=self.oauth, logging=False)

where self.oauth contains "signature_method": "RSA-SHA1",

Stack trace

2023-12-13 04:21:54.100228 [error    ] Failed to create OAuth session with signature_method=RSA-SHA1.
Attempting fallback method(s).Consider specifying the signature via oauth['signature_method']. 
Traceback (most recent call last):
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/client.py", line 3713, in _create_oauth_session
    self.myself()
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/client.py", line 3135, in myself
    return self._get_json("myself")
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/client.py", line 3853, in _get_json
    r = self._session.get(url, params=params)
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/resilientsession.py", line 246, in request
    elif raise_on_error(response, **processed_kwargs):
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/resilientsession.py", line 71, in raise_on_error
    raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 401 url: ...
        text: oauth_problem=token_rejected

        response headers = {'Date': 'Wed, 13 Dec 2023 04:21:54 GMT', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Content-Length': '28', 'Connection': 'keep-alive', 'WWW-Authenticate': ...., oauth_problem="token_rejected"', 'Content-Security-Policy': 'sandbox'}
        response text = oauth_problem=token_rejected
2023-12-13 04:21:54.157748 [error    ] Failed to create OAuth session with signature_method=HMAC-SHA1.
Attempting fallback method(s).Consider specifying the signature via oauth['signature_method']. 
Traceback (most recent call last):
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/client.py", line 3713, in _create_oauth_session
    self.myself()
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/client.py", line 3135, in myself
    return self._get_json("myself")
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/client.py", line 3853, in _get_json
    r = self._session.get(url, params=params)
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/resilientsession.py", line 246, in request
    elif raise_on_error(response, **processed_kwargs):
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/resilientsession.py", line 71, in raise_on_error
    raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 401 url: ...
        text: oauth_problem=token_rejected

        response headers = {'Date': 'Wed, 13 Dec 2023 04:21:54 GMT', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Content-Length': '28', 'Connection': 'keep-alive', 'WWW-Authenticate': ..., oauth_problem="token_rejected"', 'Content-Security-Policy': 'sandbox'}
        response text = oauth_problem=token_rejected
2023-12-13 04:21:54.197825 [error    ] Failed to create OAuth session with signature_method=RSA-SHA1.
Attempting fallback method(s).Consider specifying the signature via oauth['signature_method']. 
Traceback (most recent call last):
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/client.py", line 3713, in _create_oauth_session
    self.myself()
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/client.py", line 3135, in myself
    return self._get_json("myself")
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/client.py", line 3853, in _get_json
    r = self._session.get(url, params=params)
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/resilientsession.py", line 246, in request
    elif raise_on_error(response, **processed_kwargs):
  File "/Users/brookemiller/Library/Caches/pypoetry/virtualenvs/mothra-98Oa1KiW-py3.10/lib/python3.10/site-packages/jira/resilientsession.py", line 71, in raise_on_error
    raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 401 url: ...
        text: oauth_problem=token_rejected

        response headers = {'Date': 'Wed, 13 Dec 2023 04:21:54 GMT', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Content-Length': '28', 'Connection': 'keep-alive', 'WWW-Authenticate': ..., oauth_problem="token_rejected"', 'Content-Security-Policy': 'sandbox'}
        response text = oauth_problem=token_rejected

Expected behaviour

no logs or tracebacks

Additional Context

No response

@adehad
Copy link
Collaborator

adehad commented Jan 12, 2024

Thanks for the report, if anyone wants to take this on, the fix is to replace the calls to the global logging object _logging with the self.log object, which applies the log level accordingly.

@adehad adehad added the good first issue New contributors welcome ! label Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue New contributors welcome !
Projects
None yet
Development

No branches or pull requests

2 participants