Skip to content

Commit 21348af

Browse files
authored
ref(source-stripe): remove stripe py-package (#45348)
Signed-off-by: Artem Inzhyyants <artem.inzhyyants@gmail.com>
1 parent ba63c03 commit 21348af

File tree

6 files changed

+508
-284
lines changed

6 files changed

+508
-284
lines changed

airbyte-integrations/connectors/source-stripe/metadata.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ data:
1010
connectorSubtype: api
1111
connectorType: source
1212
definitionId: e094cb9a-26de-4645-8761-65c0c425d1de
13-
dockerImageTag: 5.5.3
13+
dockerImageTag: 5.5.4
1414
dockerRepository: airbyte/source-stripe
1515
documentationUrl: https://docs.airbyte.com/integrations/sources/stripe
1616
erdUrl: https://dbdocs.io/airbyteio/source-stripe?view=relationships

airbyte-integrations/connectors/source-stripe/poetry.lock

+449-206
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

airbyte-integrations/connectors/source-stripe/pyproject.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
33
build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
6-
version = "5.5.3"
6+
version = "5.5.4"
77
name = "source-stripe"
88
description = "Source implementation for Stripe."
99
authors = [ "Airbyte <contact@airbyte.io>",]
@@ -17,7 +17,6 @@ include = "source_stripe"
1717

1818
[tool.poetry.dependencies]
1919
python = "^3.10,<3.12"
20-
stripe = "==2.56.0"
2120
pendulum = "==2.1.2"
2221
airbyte-cdk = "^4"
2322

airbyte-integrations/connectors/source-stripe/source_stripe/source.py

+22-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from typing import Any, List, Mapping, MutableMapping, Optional, Tuple
99

1010
import pendulum
11-
import stripe
1211
from airbyte_cdk.entrypoint import logger as entrypoint_logger
1312
from airbyte_cdk.models import ConfiguredAirbyteCatalog, FailureType
1413
from airbyte_cdk.sources.concurrent_source.concurrent_source import ConcurrentSource
@@ -107,14 +106,29 @@ def validate_and_fill_with_defaults(config: MutableMapping[str, Any]) -> Mutable
107106
return config
108107

109108
def check_connection(self, logger: logging.Logger, config: MutableMapping[str, Any]) -> Tuple[bool, Any]:
110-
self.validate_and_fill_with_defaults(config)
111-
stripe.api_key = config["client_secret"]
109+
args = self._get_stream_base_args(config)
110+
account_stream = StripeStream(name="accounts", path="accounts", use_cache=USE_CACHE, **args)
112111
try:
113-
stripe.Account.retrieve(config["account_id"])
114-
except (stripe.error.AuthenticationError, stripe.error.PermissionError) as e:
115-
return False, str(e)
112+
next(account_stream.read_records(sync_mode=SyncMode.full_refresh))
113+
except AirbyteTracedException as error:
114+
if error.failure_type == FailureType.config_error:
115+
return False, error.message
116+
raise error
116117
return True, None
117118

119+
def _get_stream_base_args(self, config: MutableMapping[str, Any]) -> MutableMapping[str, Any]:
120+
config = self.validate_and_fill_with_defaults(config)
121+
authenticator = TokenAuthenticator(config["client_secret"])
122+
start_timestamp = self._start_date_to_timestamp(config)
123+
args = {
124+
"authenticator": authenticator,
125+
"account_id": config["account_id"],
126+
"start_date": start_timestamp,
127+
"slice_range": config["slice_range"],
128+
"api_budget": self.get_api_call_budget(config),
129+
}
130+
return args
131+
118132
@staticmethod
119133
def customers(**args):
120134
# The Customers stream is instantiated in a dedicated method to allow parametrization and avoid duplicated code.
@@ -174,17 +188,7 @@ def get_api_call_budget(self, config: Mapping[str, Any]) -> AbstractAPIBudget:
174188
return HttpAPIBudget(policies=policies)
175189

176190
def streams(self, config: MutableMapping[str, Any]) -> List[Stream]:
177-
config = self.validate_and_fill_with_defaults(config)
178-
authenticator = TokenAuthenticator(config["client_secret"])
179-
180-
start_timestamp = self._start_date_to_timestamp(config)
181-
args = {
182-
"authenticator": authenticator,
183-
"account_id": config["account_id"],
184-
"start_date": start_timestamp,
185-
"slice_range": config["slice_range"],
186-
"api_budget": self.get_api_call_budget(config),
187-
}
191+
args = self._get_stream_base_args(config)
188192
incremental_args = {**args, "lookback_window_days": config["lookback_window_days"]}
189193
subscriptions = IncrementalStripeStream(
190194
name="subscriptions",
@@ -532,7 +536,7 @@ def streams(self, config: MutableMapping[str, Any]) -> List[Stream]:
532536
),
533537
]
534538

535-
state_manager = ConnectorStateManager(stream_instance_map={s.name: s for s in streams}, state=self._state)
539+
state_manager = ConnectorStateManager(state=self._state)
536540
return [
537541
self._to_concurrent(
538542
stream,

airbyte-integrations/connectors/source-stripe/unit_tests/test_source.py

+2-25
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
import datetime
55
import logging
66
from contextlib import nullcontext as does_not_raise
7-
from unittest.mock import patch
87

98
import pytest
10-
import source_stripe
11-
import stripe
129
from airbyte_cdk.models import ConfiguredAirbyteCatalog, SyncMode
1310
from airbyte_cdk.sources.streams.call_rate import CachedLimiterSession, LimiterSession, Rate
1411
from airbyte_cdk.sources.streams.concurrent.adapters import StreamFacade
@@ -50,11 +47,6 @@ def _a_valid_config():
5047
return {"account_id": 1, "client_secret": "secret"}
5148

5249

53-
@patch.object(source_stripe.source, "stripe")
54-
def test_source_check_connection_ok(mocked_client, config):
55-
assert SourceStripe(_ANY_CATALOG, _ANY_CONFIG, _NO_STATE).check_connection(logger, config=config) == (True, None)
56-
57-
5850
def test_streams_are_unique(config):
5951
stream_names = [s.name for s in SourceStripe(_ANY_CATALOG, _ANY_CONFIG, _NO_STATE).streams(config=config)]
6052
assert len(stream_names) == len(set(stream_names)) == 46
@@ -69,25 +61,10 @@ def test_streams_are_unique(config):
6961
(_a_valid_config(), None),
7062
),
7163
)
72-
@patch.object(source_stripe.source.stripe, "Account")
73-
def test_config_validation(mocked_client, input_config, expected_error_msg):
64+
def test_config_validation(input_config, expected_error_msg):
7465
context = pytest.raises(AirbyteTracedException, match=expected_error_msg) if expected_error_msg else does_not_raise()
7566
with context:
76-
SourceStripe(_ANY_CATALOG, _ANY_CONFIG, _NO_STATE).check_connection(logger, config=input_config)
77-
78-
79-
@pytest.mark.parametrize(
80-
"exception",
81-
(
82-
stripe.error.AuthenticationError,
83-
stripe.error.PermissionError,
84-
),
85-
)
86-
@patch.object(source_stripe.source.stripe, "Account")
87-
def test_given_stripe_error_when_check_connection_then_connection_not_available(mocked_client, exception):
88-
mocked_client.retrieve.side_effect = exception
89-
is_available, _ = SourceStripe(_ANY_CATALOG, _ANY_CONFIG, _NO_STATE).check_connection(logger, config=_a_valid_config())
90-
assert not is_available
67+
SourceStripe(_ANY_CATALOG, _ANY_CONFIG, _NO_STATE).validate_and_fill_with_defaults(config=input_config)
9168

9269

9370
def test_when_streams_return_full_refresh_as_concurrent():

0 commit comments

Comments
 (0)