Skip to content

Commit

Permalink
Catch exception when jwt deps are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jul 10, 2024
1 parent 18c392c commit c396b6e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ cryptography = { version = ">=3.4.6", optional = true }
PyJWT = { version = "~=2.4", optional = true }

[tool.poetry.extras]
# TODO: Add 'cryptography' and 'PyJWT' to the 'jwt' when we want to remove them
# from the main dependencies
jwt = [
"cryptography",
"PyJWT",
Expand Down Expand Up @@ -278,9 +276,9 @@ warn_unused_ignores = true
ignore_missing_imports = true
module = [
"backports.datetime_fromisoformat.*",
"joblib.*", # TODO: Remove when https://github.com/joblib/joblib/issues/1516 is shipped
"jsonpath_ng.*",
"pyarrow.*", # TODO: Remove when https://github.com/apache/arrow/issues/32609 if implemented and released
"joblib.*", # TODO: Remove when https://github.com/joblib/joblib/issues/1516 is shipped
"jsonpath_ng.*", # TODO: Remove when https://github.com/h2non/jsonpath-ng/issues/152 is implemented and released
"pyarrow.*", # TODO: Remove when https://github.com/apache/arrow/issues/32609 if implemented and released
]

[tool.poetry-dynamic-versioning]
Expand Down
11 changes: 8 additions & 3 deletions singer_sdk/authenticators.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,16 @@ def oauth_request_payload(self) -> dict:
Payload object for OAuth.
Raises:
RuntimeError: If the JWT dependencies are not installed.
ValueError: If the private key is not set.
"""
import jwt # noqa: PLC0415
from cryptography.hazmat.backends import default_backend # noqa: PLC0415
from cryptography.hazmat.primitives import serialization # noqa: PLC0415
try:
import jwt # noqa: PLC0415
from cryptography.hazmat.backends import default_backend # noqa: PLC0415
from cryptography.hazmat.primitives import serialization # noqa: PLC0415
except ModuleNotFoundError as ex:
msg = "Install singer-sdk[jwt] to use OAuthJWTAuthenticator."
raise RuntimeError(msg) from ex

Check warning on line 580 in singer_sdk/authenticators.py

View check run for this annotation

Codecov / codecov/patch

singer_sdk/authenticators.py#L578-L580

Added lines #L578 - L580 were not covered by tests

if not self.private_key:
msg = "Missing 'private_key' property for OAuth payload."
Expand Down

0 comments on commit c396b6e

Please sign in to comment.