Skip to content

Commit

Permalink
refactor: Add a crypto package extra. The cryptography dependency…
Browse files Browse the repository at this point in the history
… is not yet removed from the default dependencies
  • Loading branch information
edgarrmondragon committed Jan 31, 2024
1 parent 70483e3 commit 4b9b219
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ packages = [
[tool.poetry.dependencies]
python = ">=3.8"
importlib-resources = { version = "==6.1.*", python = "<3.9" }
{%- if cookiecutter.auth_method == "JWT" %}
singer-sdk = { version="~=0.34.1", extras = ["crypto"] }
{%- else %}
singer-sdk = { version="~=0.34.1" }
{%- endif %}
fs-s3fs = { version = "~=1.1.1", optional = true }
{%- if cookiecutter.stream_type in ["REST", "GraphQL"] %}
requests = "~=2.31.0"
Expand Down
3 changes: 2 additions & 1 deletion docs/dev_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Create taps with the SDK requires overriding just two or three classes:
`http_headers` property in the stream class.
- `OAuthAuthenticator` - This class performs an OAuth 2.0 authentication flow.
- `OAuthJWTAuthenticator` - This class performs an JWT (JSON Web Token) authentication
flow.
flow. Requires installing the `singer-sdk[crypto]` extra.

## Target Development Overview

Expand Down Expand Up @@ -181,6 +181,7 @@ Some APIs instead return the records as values inside an object where each key i

The following [extra features](https://packaging.python.org/en/latest/specifications/dependency-specifiers/#extras) are available for the Singer SDK:

- `crypto` - Enables the `OAuthJWTAuthenticator` class for JWT (JSON Web Token) authentication.
- `s3` - Enables AWS S3 as a [BATCH storage](batch.md#the-batch-message).
- `parquet` - Enables as [BATCH encoding](batch.md#encoding).
- `testing` - Pytest dependencies required to use the [Tap & Target Testing Frameworks](testing.md).
Expand Down
3 changes: 2 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ pytest = {version=">=7.2.1", optional = true}
pytest-durations = {version = ">=1.2.0", optional = true}

[tool.poetry.extras]
crypto = [
"cryptography",
]
docs = [
"sphinx",
"furo",
Expand Down
5 changes: 3 additions & 2 deletions singer_sdk/authenticators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

import jwt
import requests
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization

from singer_sdk.helpers._util import utc_now

Expand Down Expand Up @@ -564,6 +562,9 @@ def oauth_request_payload(self) -> dict:
Raises:
ValueError: If the private key is not set.
"""
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization

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

0 comments on commit 4b9b219

Please sign in to comment.