From f53386b9231cf3b719672ce12e9ec29d245801d9 Mon Sep 17 00:00:00 2001 From: Oleksandr Bazarnov Date: Thu, 19 May 2022 16:34:47 +0300 Subject: [PATCH] added old config support --- .../acceptance-test-config.yml | 2 ++ .../source-bing-ads/source_bing_ads/client.py | 28 +++++++++++++++---- .../source-bing-ads/source_bing_ads/spec.json | 1 - 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/airbyte-integrations/connectors/source-bing-ads/acceptance-test-config.yml b/airbyte-integrations/connectors/source-bing-ads/acceptance-test-config.yml index 205bc72cbedd40..c73cbe55e46ca9 100644 --- a/airbyte-integrations/connectors/source-bing-ads/acceptance-test-config.yml +++ b/airbyte-integrations/connectors/source-bing-ads/acceptance-test-config.yml @@ -3,6 +3,8 @@ tests: spec: - spec_path: "source_bing_ads/spec.json" connection: + - config_path: "secrets/config_old.json" + status: "succeed" - config_path: "secrets/config.json" status: "succeed" - config_path: "integration_tests/invalid_config.json" diff --git a/airbyte-integrations/connectors/source-bing-ads/source_bing_ads/client.py b/airbyte-integrations/connectors/source-bing-ads/source_bing_ads/client.py index 01ccb57dc184a8..bbbf6ad7920534 100644 --- a/airbyte-integrations/connectors/source-bing-ads/source_bing_ads/client.py +++ b/airbyte-integrations/connectors/source-bing-ads/source_bing_ads/client.py @@ -36,28 +36,46 @@ class Client: def __init__( self, - credentials: dict, tenant_id: str, reports_start_date: str, hourly_reports: bool, daily_reports: bool, weekly_reports: bool, monthly_reports: bool, + credentials: dict = None, + client_id: str = None, # deprecated + client_secret: str = None, # deprecated + developer_token: str = None, # deprecated + refresh_token: str = None, # deprecated **kwargs: Mapping[str, Any], ) -> None: self.authorization_data: Mapping[str, AuthorizationData] = {} - self.authentication = self._get_auth_client(credentials, tenant_id) - self.refresh_token = credentials["refresh_token"] - self.developer_token = credentials["developer_token"] + self.refresh_token = credentials["refresh_token"] if credentials else refresh_token + self.developer_token = credentials["developer_token"] if credentials else developer_token self.hourly_reports = hourly_reports self.daily_reports = daily_reports self.weekly_reports = weekly_reports self.monthly_reports = monthly_reports - + + self.client_id = client_id # deprecated + self.client_secret = client_secret # deprecated + + self.authentication = self._get_auth_client(credentials, tenant_id) self.oauth: OAuthTokens = self._get_access_token() self.reports_start_date = pendulum.parse(reports_start_date).astimezone(tz=timezone.utc) def _get_auth_client(self, credentials: dict, tenant_id: str) -> OAuthWebAuthCodeGrant: + + # support the deprecated old input configuration + if self.client_id or self.client_secret: + auth_creds = { + "client_id": self.client_id, + "client_secret": self.client_secret, + "redirection_uri": "", # should be empty string + "tenant": tenant_id, + } + return OAuthWebAuthCodeGrant(**auth_creds) + # https://github.com/BingAds/BingAds-Python-SDK/blob/e7b5a618e87a43d0a5e2c79d9aa4626e208797bd/bingads/authorization.py#L390 auth_creds = { "client_id": credentials["client_id"], diff --git a/airbyte-integrations/connectors/source-bing-ads/source_bing_ads/spec.json b/airbyte-integrations/connectors/source-bing-ads/source_bing_ads/spec.json index 28d2dddac378c6..571157fcf4ac0e 100644 --- a/airbyte-integrations/connectors/source-bing-ads/source_bing_ads/spec.json +++ b/airbyte-integrations/connectors/source-bing-ads/source_bing_ads/spec.json @@ -5,7 +5,6 @@ "title": "Bing Ads Spec", "type": "object", "required": [ - "credentials", "reports_start_date", "hourly_reports", "daily_reports",