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 Feb 13, 2024
1 parent 2de41df commit 10ff425
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.3
rev: 0.27.4
hooks:
- id: check-dependabot
- id: check-github-workflows

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
rev: v0.1.15
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.3
rev: 0.27.4
hooks:
- id: check-dependabot
- id: check-github-workflows

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
rev: v0.1.15
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
Expand Down
16 changes: 15 additions & 1 deletion cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,29 @@ packages = [
[tool.poetry.dependencies]
python = ">=3.8"
importlib-resources = { version = "==6.1.*", python = "<3.9" }
singer-sdk = { version="~=0.35.0"{{ ', extras = ["faker"]' if cookiecutter.faker_extra }} }
fs-s3fs = { version = "~=1.1.1", optional = true }
{%- if cookiecutter.stream_type in ["REST", "GraphQL"] %}
requests = "~=2.31.0"
{%- endif %}

[tool.poetry.dependencies.singer-sdk]
version = "~=0.35.0"
extras = [
{%- if cookiecutter.auth_method == "JWT" %}
"crypto",
{%- endif %}
{%- if cookiecutter.faker_extra %}
"faker",
{%- endif %}
]

[tool.poetry.group.dev.dependencies]
pytest = ">=7.4.0"
{%- if cookiecutter.auth_method == "JWT" %}
singer-sdk = { version="~=0.35.0", extras = ["crypto", "testing"] }
{%- else %}
singer-sdk = { version="~=0.35.0", extras = ["testing"] }
{%- endif %}

[tool.poetry.extras]
s3 = ["fs-s3fs"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.3
rev: 0.27.4
hooks:
- id: check-dependabot
- id: check-github-workflows

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
rev: v0.1.15
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
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.
- `faker` - Enables the use of [Faker](https://faker.readthedocs.io/en/master/) in [stream maps](stream_maps.md).
- `s3` - Enables AWS S3 as a [BATCH storage](batch.md#the-batch-message).
- `parquet` - Enables as [BATCH encoding](batch.md#encoding).
Expand Down
8 changes: 4 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
def mypy(session: Session) -> None:
"""Check types with mypy."""
args = session.posargs or ["singer_sdk"]
session.install(".[faker,parquet,s3,testing]")
session.install(".[crypto,faker,parquet,s3,testing]")
session.install(
"exceptiongroup",
"mypy",
Expand All @@ -80,7 +80,7 @@ def mypy(session: Session) -> None:
@session(python=python_versions)
def tests(session: Session) -> None:
"""Execute pytest tests and compute coverage."""
session.install(".[faker,parquet,s3]")
session.install(".[crypto,faker,parquet,s3]")
session.install(*test_dependencies)

sqlalchemy_version = os.environ.get("SQLALCHEMY_VERSION")
Expand Down Expand Up @@ -113,7 +113,7 @@ def tests(session: Session) -> None:
@session(python=main_python_version)
def benches(session: Session) -> None:
"""Run benchmarks."""
session.install(".[s3]")
session.install(".[crypto,s3]")
session.install(*test_dependencies)
sqlalchemy_version = os.environ.get("SQLALCHEMY_VERSION")
if sqlalchemy_version:
Expand All @@ -135,7 +135,7 @@ def update_snapshots(session: Session) -> None:
"""Update pytest snapshots."""
args = session.posargs or ["-m", "snapshot"]

session.install(".[faker]")
session.install(".[crypto,faker]")
session.install(*test_dependencies)
session.run("pytest", "--snapshot-update", *args)

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.

5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ pytest-durations = {version = ">=1.2.0", optional = true}
faker = {version = ">=22.5,<24.0", optional = true}

[tool.poetry.extras]
crypto = [
"cryptography",
]
docs = [
"furo",
"myst-parser",
Expand Down Expand Up @@ -177,7 +180,7 @@ prerelease_offset = 1
tag_format = "v$major.$minor.$patch$prerelease"
version_files = [
"docs/conf.py:^release =",
"cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml:singer-sdk",
"cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml:version",
"cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml:singer-sdk",
"cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/pyproject.toml:singer-sdk",
".github/ISSUE_TEMPLATE/bug.yml:^ placeholder:",
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 10ff425

Please sign in to comment.