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

feat: Support requests.auth authenticators #1109

Merged
merged 9 commits into from
Feb 3, 2023
2 changes: 1 addition & 1 deletion docs/_templates/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: {{ name }}
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.BatchSink.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: BatchSink
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.GraphQLStream.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: GraphQLStream
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.InlineMapper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
:members:
:show-inheritance:
:inherited-members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.RESTStream.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: RESTStream
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.RecordSink.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: RecordSink
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.SQLConnector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: SQLConnector
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.SQLSink.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: SQLSink
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.SQLStream.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: SQLStream
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.SQLTap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
:members:
:show-inheritance:
:inherited-members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.SQLTarget.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
:members:
:show-inheritance:
:inherited-members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.Sink.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: Sink
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.Stream.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: Stream
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.Tap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
:members:
:show-inheritance:
:inherited-members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.Target.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
:members:
:show-inheritance:
:inherited-members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: APIAuthenticatorBase
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: APIKeyAuthenticator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: BasicAuthenticator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: BearerTokenAuthenticator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: OAuthAuthenticator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: OAuthJWTAuthenticator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: SimpleAuthenticator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: ConfigValidationError
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.exceptions.FatalAPIError.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: FatalAPIError
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: InvalidStreamSortException
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: MapExpressionError
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: MaxRecordsLimitException
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: RecordsWithoutSchemaException
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.exceptions.RetriableAPIError.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: RetriableAPIError
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: StreamMapConfigError
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: TapStreamConnectionFailure
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: TooManyRecordsException
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.pagination.BaseAPIPaginator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: BaseAPIPaginator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: BaseHATEOASPaginator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: BaseOffsetPaginator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: BasePageNumberPaginator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: HeaderLinkPaginator
:members:
:special-members: __init__
:special-members: __init__, __call__
2 changes: 1 addition & 1 deletion docs/classes/singer_sdk.pagination.JSONPathPaginator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: JSONPathPaginator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: LegacyPaginatedStreamProtocol
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: LegacyStreamPaginator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: SimpleHeaderPaginator
:members:
:special-members: __init__
:special-members: __init__, __call__
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

.. autoclass:: SinglePagePaginator
:members:
:special-members: __init__
:special-members: __init__, __call__
28 changes: 28 additions & 0 deletions docs/code_samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,34 @@ class CachedAuthStream(RESTStream):
return APIAuthenticatorBase(stream=self)
```

### Use one of `requests`'s built-in authenticators

```python
from requests.auth import HTTPDigestAuth
from singer_sdk.streams import RESTStream

class DigestAuthStream(RESTStream):
"""A stream with digest authentication."""

@property
def authenticator(self) -> HTTPDigestAuth:
"""Stream authenticator."""
return HTTPDigestAuth(
username=self.config["username"],
password=self.config["password"],
)
```

[`HTTPBasicAuth`](https://requests.readthedocs.io/en/latest/api/#requests.auth.HTTPBasicAuth) and
[`HTTPProxyAuth`](https://requests.readthedocs.io/en/latest/api/#requests.auth.HTTPProxyAuth)
are also available in `requests.auth`. In addition to `requests.auth` classes, the community
has published a few packages with custom authenticator classes, which are compatible with the SDK.
For example:

- [`requests-aws4auth`](https://github.com/tedder/requests-aws4auth): AWS v4 authentication
- [`requests_auth`](https://github.com/Colin-b/requests_auth): A collection of authenticators
for various services and protocols including Azure, Okta and NTLM.

### Custom response validation

Some APIs deviate from HTTP status codes to report failures. For those cases,
Expand Down
Loading