From e82178f794d419b0d2250490714d3494e8e38587 Mon Sep 17 00:00:00 2001 From: Maxime Carbonneau-Leclerc Date: Wed, 27 Sep 2023 11:34:40 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Source=20Stripe:=20handle=20Perm?= =?UTF-8?q?issionError=20as=20non=20breaking=20during=20check=5Fconnection?= =?UTF-8?q?=20(#30800)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../connectors/source-stripe/Dockerfile | 2 +- .../connectors/source-stripe/metadata.yaml | 2 +- .../source-stripe/source_stripe/source.py | 2 +- .../source-stripe/unit_tests/test_source.py | 33 +++++++++++++++---- docs/integrations/sources/stripe.md | 1 + 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/airbyte-integrations/connectors/source-stripe/Dockerfile b/airbyte-integrations/connectors/source-stripe/Dockerfile index 8b243ce2905f..d992f20b03e4 100644 --- a/airbyte-integrations/connectors/source-stripe/Dockerfile +++ b/airbyte-integrations/connectors/source-stripe/Dockerfile @@ -13,5 +13,5 @@ ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py" ENTRYPOINT ["python", "/airbyte/integration_code/main.py"] -LABEL io.airbyte.version=4.3.0 +LABEL io.airbyte.version=4.3.1 LABEL io.airbyte.name=airbyte/source-stripe diff --git a/airbyte-integrations/connectors/source-stripe/metadata.yaml b/airbyte-integrations/connectors/source-stripe/metadata.yaml index 501d0daa65b6..a8c21740f828 100644 --- a/airbyte-integrations/connectors/source-stripe/metadata.yaml +++ b/airbyte-integrations/connectors/source-stripe/metadata.yaml @@ -5,7 +5,7 @@ data: connectorSubtype: api connectorType: source definitionId: e094cb9a-26de-4645-8761-65c0c425d1de - dockerImageTag: 4.3.0 + dockerImageTag: 4.3.1 dockerRepository: airbyte/source-stripe githubIssueLabel: source-stripe icon: stripe.svg diff --git a/airbyte-integrations/connectors/source-stripe/source_stripe/source.py b/airbyte-integrations/connectors/source-stripe/source_stripe/source.py index 233e520e0001..1b0d78d278fb 100644 --- a/airbyte-integrations/connectors/source-stripe/source_stripe/source.py +++ b/airbyte-integrations/connectors/source-stripe/source_stripe/source.py @@ -76,7 +76,7 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> stripe.api_key = config["client_secret"] try: stripe.Account.retrieve(config["account_id"]) - except stripe.error.AuthenticationError as e: + except (stripe.error.AuthenticationError, stripe.error.PermissionError) as e: return False, str(e) return True, None diff --git a/airbyte-integrations/connectors/source-stripe/unit_tests/test_source.py b/airbyte-integrations/connectors/source-stripe/unit_tests/test_source.py index 03b445132e36..4abff84d2356 100644 --- a/airbyte-integrations/connectors/source-stripe/unit_tests/test_source.py +++ b/airbyte-integrations/connectors/source-stripe/unit_tests/test_source.py @@ -8,12 +8,17 @@ import pytest import source_stripe +import stripe from airbyte_cdk.utils import AirbyteTracedException from source_stripe import SourceStripe logger = logging.getLogger("airbyte") +def _a_valid_config(): + return {"account_id": 1, "client_secret": "secret"} + + @patch.object(source_stripe.source, "stripe") def test_source_check_connection_ok(mocked_client, config): assert SourceStripe().check_connection(logger, config=config) == (True, None) @@ -25,16 +30,30 @@ def test_streams_are_unique(config): @pytest.mark.parametrize( - "input_config, is_success, expected_error_msg", + "input_config, expected_error_msg", ( - ({"lookback_window_days": "month"}, False, "Invalid lookback window month. Please use only positive integer values or 0."), - ({"start_date": "January First, 2022"}, False, "Invalid start date January First, 2022. Please use YYYY-MM-DDTHH:MM:SSZ format."), - ({"slice_range": -10}, False, "Invalid slice range value -10. Please use positive integer values only."), - ({"account_id": 1, "client_secret": "secret"}, True, None) + ({"lookback_window_days": "month"}, "Invalid lookback window month. Please use only positive integer values or 0."), + ({"start_date": "January First, 2022"}, "Invalid start date January First, 2022. Please use YYYY-MM-DDTHH:MM:SSZ format."), + ({"slice_range": -10}, "Invalid slice range value -10. Please use positive integer values only."), + (_a_valid_config(), None) ) ) -@patch.object(source_stripe.source, "stripe") -def test_config_validation(mocked_client, input_config, is_success, expected_error_msg): +@patch.object(source_stripe.source.stripe, "Account") +def test_config_validation(mocked_client, input_config, expected_error_msg): context = pytest.raises(AirbyteTracedException, match=expected_error_msg) if expected_error_msg else does_not_raise() with context: SourceStripe().check_connection(logger, config=input_config) + + +@pytest.mark.parametrize( + "exception", + ( + stripe.error.AuthenticationError, + stripe.error.PermissionError, + ) +) +@patch.object(source_stripe.source.stripe, "Account") +def test_given_stripe_error_when_check_connection_then_connection_not_available(mocked_client, exception): + mocked_client.retrieve.side_effect = exception + is_available, _ = SourceStripe().check_connection(logger, config=_a_valid_config()) + assert not is_available diff --git a/docs/integrations/sources/stripe.md b/docs/integrations/sources/stripe.md index c14fdb09b673..7c4478034289 100644 --- a/docs/integrations/sources/stripe.md +++ b/docs/integrations/sources/stripe.md @@ -192,6 +192,7 @@ The Stripe connector should not run into Stripe API limitations under normal usa | Version | Date | Pull Request | Subject | |:--------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------| +| 4.3.1 | 2023-09-27 | [30800](https://github.com/airbytehq/airbyte/pull/30800) | Handle permission issues a non breaking | | 4.3.0 | 2023-09-26 | [30752](https://github.com/airbytehq/airbyte/pull/30752) | Do not sync upcoming invoices, extend stream schemas | | 4.2.0 | 2023-09-21 | [30660](https://github.com/airbytehq/airbyte/pull/30660) | Fix updated state for the incremental syncs | | 4.1.1 | 2023-09-15 | [30494](https://github.com/airbytehq/airbyte/pull/30494) | Fix datatype of invoices.lines property |