Skip to content

Commit

Permalink
refactor: Use requests.auth.HTTPBasicAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Nov 11, 2023
1 parent 53c2a15 commit 0215c3c
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
[%- set base_stream = tap_source_id + 'Stream' -%]
[%- set builtin_auth = {
"API Key": "APIKeyAuthenticator",
"Bearer Token": "BearerTokenAuthenticator",
"Basic Auth": "BasicAuthenticator",
} -%]
[%- set authenticator = tap_source_id + 'Authenticator' -%]

"""REST client handling, including [[ base_stream ]] base class."""
Expand All @@ -12,10 +7,16 @@ from __future__ import annotations

from typing import Any

[% if tap_auth_method == "Basic Auth" -%]
from requests.auth import HTTPBasicAuth
[% endif -%]

from singer_sdk import [[ tap_stream_type ]]Stream

[%- if tap_auth_method in builtin_auth %]
from singer_sdk.authenticators import [[ builtin_auth[tap_auth_method] ]]
[%- if tap_auth_method == "API Key" %]
from singer_sdk.authenticators import APIKeyAuthenticator
[%- elif tap_auth_method == "Bearer Token" %]
from singer_sdk.authenticators import BearerTokenAuthenticator
[%- endif %]

[%- if tap_auth_method in ("OAuth2", "JWT") %]
Expand Down Expand Up @@ -77,20 +78,13 @@ class [[ base_stream ]]([[ tap_stream_type ]]Stream):
[%- elif tap_auth_method == "Basic Auth" %]

@property
def authenticator(self) -> BasicAuthenticator:
def authenticator(self) -> HTTPBasicAuth:
"""Get an authenticator object.

Returns:
The authenticator instance for this REST stream.
"""
username = self.config["username"]
password = self.config["password"]

return BasicAuthenticator.create_for_stream(
self,
username=username,
password=password,
)
return HTTPBasicAuth(self.config["username"], self.config["password"])

[%- endif %]

Expand Down

0 comments on commit 0215c3c

Please sign in to comment.