From 0973b33dc6daa82e94b54d689cad8b707c8d306a Mon Sep 17 00:00:00 2001 From: Bruno Nirello <30416677+bruno-nirello@users.noreply.github.com> Date: Tue, 7 Dec 2021 23:13:02 -0300 Subject: [PATCH] Source Typeform: fix check connection authenticator loop (#8466) * removed full forms list loop * better exception return * Update airbyte-integrations/connectors/source-typeform/source_typeform/source.py Co-authored-by: Marcos Marx * added comments to show bug * better error handling with empty form list * rebase Co-authored-by: Marcos Marx Co-authored-by: Marcos Marx --- .../resources/seed/source_definitions.yaml | 2 +- .../src/main/resources/seed/source_specs.yaml | 2 +- .../connectors/source-typeform/Dockerfile | 2 +- .../source-typeform/source_typeform/source.py | 28 +++++++++++++++---- docs/integrations/sources/typeform.md | 1 + 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml index 9c54645bada51d..b0c2748be2302b 100644 --- a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml @@ -686,7 +686,7 @@ - name: Typeform sourceDefinitionId: e7eff203-90bf-43e5-a240-19ea3056c474 dockerRepository: airbyte/source-typeform - dockerImageTag: 0.1.2 + dockerImageTag: 0.1.3 documentationUrl: https://docs.airbyte.io/integrations/sources/typeform icon: typeform.svg sourceType: api diff --git a/airbyte-config/init/src/main/resources/seed/source_specs.yaml b/airbyte-config/init/src/main/resources/seed/source_specs.yaml index 1ac1bd8d843973..f884cd66b06937 100644 --- a/airbyte-config/init/src/main/resources/seed/source_specs.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_specs.yaml @@ -6354,7 +6354,7 @@ supportsDBT: false supported_destination_sync_modes: - "append" -- dockerImage: "airbyte/source-typeform:0.1.2" +- dockerImage: "airbyte/source-typeform:0.1.3" spec: documentationUrl: "https://docs.airbyte.io/integrations/sources/typeform" connectionSpecification: diff --git a/airbyte-integrations/connectors/source-typeform/Dockerfile b/airbyte-integrations/connectors/source-typeform/Dockerfile index 9a0f3f2e685736..842462b6665771 100644 --- a/airbyte-integrations/connectors/source-typeform/Dockerfile +++ b/airbyte-integrations/connectors/source-typeform/Dockerfile @@ -12,5 +12,5 @@ RUN pip install . ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py" ENTRYPOINT ["python", "/airbyte/integration_code/main.py"] -LABEL io.airbyte.version=0.1.2 +LABEL io.airbyte.version=0.1.3 LABEL io.airbyte.name=airbyte/source-typeform diff --git a/airbyte-integrations/connectors/source-typeform/source_typeform/source.py b/airbyte-integrations/connectors/source-typeform/source_typeform/source.py index 12708338e457e9..e20f9846248cf6 100644 --- a/airbyte-integrations/connectors/source-typeform/source_typeform/source.py +++ b/airbyte-integrations/connectors/source-typeform/source_typeform/source.py @@ -202,14 +202,30 @@ class SourceTypeform(AbstractSource): def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> Tuple[bool, any]: try: form_ids = config.get("form_ids", []).copy() - auth = TokenAuthenticator(token=config["token"]) # verify if form inputted by user is valid - for form in TrimForms(authenticator=auth, **config).read_records(sync_mode=SyncMode.full_refresh): - if form.get("id") in form_ids: - form_ids.remove(form.get("id")) + try: + url = f"{TypeformStream.url_base}/me" + auth_headers = {"Authorization": f"Bearer {config['token']}"} + session = requests.get(url, headers=auth_headers) + session.raise_for_status() + except requests.exceptions.BaseHTTPError as e: + return False, f"Cannot authenticate, please verify token. Error: {e}" if form_ids: - return False, f"Cannot find forms with IDs: {form_ids}. Please make sure they are valid form IDs and try again." - return True, None + for form in form_ids: + try: + url = f"{TypeformStream.url_base}/forms/{form}" + auth_headers = {"Authorization": f"Bearer {config['token']}"} + response = requests.get(url, headers=auth_headers) + response.raise_for_status() + except requests.exceptions.BaseHTTPError as e: + return ( + False, + f"Cannot find forms with ID: {form}. Please make sure they are valid form IDs and try again. Error: {e}", + ) + return True, None + else: + return True, None + except requests.exceptions.RequestException as e: return False, e diff --git a/docs/integrations/sources/typeform.md b/docs/integrations/sources/typeform.md index 83a69369e21e88..a7e13b5e4b0a4e 100644 --- a/docs/integrations/sources/typeform.md +++ b/docs/integrations/sources/typeform.md @@ -65,6 +65,7 @@ API rate limits \(2 requests per second\): [https://developer.typeform.com/get-s | Version | Date | Pull Request | Subject | | :--- | :--- | :--- | :--- | +| 0.1.3 | 2021-12-07 | [8466](https://github.com/airbytehq/airbyte/pull/8466) | Change Check Connection Function Logic | | 0.1.2 | 2021-10-11 | [6571](https://github.com/airbytehq/airbyte/pull/6571) | Support pulling data from a select set of forms | | 0.1.1 | 2021-09-06 | [5799](https://github.com/airbytehq/airbyte/pull/5799) | Add missed choices field to responses schema | | 0.1.0 | 2021-07-10 | [4541](https://github.com/airbytehq/airbyte/pull/4541) | Initial release for Typeform API supporting Forms and Responses streams |