Skip to content

Commit fce9184

Browse files
authored
Source File: using AirbyteConnectionStatus for "check" command instead of Exception (#19222)
1 parent b1c9041 commit fce9184

File tree

8 files changed

+29
-14
lines changed

8 files changed

+29
-14
lines changed

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@
410410
- name: File
411411
sourceDefinitionId: 778daa7c-feaf-4db6-96f3-70fd645acc77
412412
dockerRepository: airbyte/source-file
413-
dockerImageTag: 0.2.28
413+
dockerImageTag: 0.2.30
414414
documentationUrl: https://docs.airbyte.com/integrations/sources/file
415415
icon: file.svg
416416
sourceType: file

airbyte-config/init/src/main/resources/seed/source_specs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3636,7 +3636,7 @@
36363636
supportsNormalization: false
36373637
supportsDBT: false
36383638
supported_destination_sync_modes: []
3639-
- dockerImage: "airbyte/source-file:0.2.28"
3639+
- dockerImage: "airbyte/source-file:0.2.30"
36403640
spec:
36413641
documentationUrl: "https://docs.airbyte.com/integrations/sources/file"
36423642
connectionSpecification:

airbyte-integrations/connectors/source-file-secure/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ RUN pip install .
99
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1010
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1111

12-
LABEL io.airbyte.version=0.2.28
12+
LABEL io.airbyte.version=0.2.30
1313
LABEL io.airbyte.name=airbyte/source-file-secure

airbyte-integrations/connectors/source-file-secure/acceptance-test-config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tests:
1515
status: "succeed"
1616
# for local should be failed
1717
- config_path: "integration_tests/local_config.json"
18-
status: "exception"
18+
status: "failed"
1919

2020
discovery:
2121
# for https

airbyte-integrations/connectors/source-file/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ COPY source_file ./source_file
1717
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1818
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1919

20-
LABEL io.airbyte.version=0.2.28
20+
LABEL io.airbyte.version=0.2.30
2121
LABEL io.airbyte.name=airbyte/source-file

airbyte-integrations/connectors/source-file/source_file/source.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import traceback
99
from datetime import datetime
1010
from typing import Any, Iterable, Iterator, Mapping, MutableMapping
11+
from urllib.parse import urlparse
1112

1213
from airbyte_cdk import AirbyteLogger
1314
from airbyte_cdk.models import (
@@ -83,25 +84,29 @@ def _validate_and_transform(self, config: Mapping[str, Any]):
8384
try:
8485
config["reader_options"] = json.loads(config["reader_options"])
8586
except ValueError:
86-
raise Exception("reader_options is not valid JSON")
87+
raise ConfigurationError("reader_options is not valid JSON")
8788
else:
8889
config["reader_options"] = {}
8990
config["url"] = dropbox_force_download(config["url"])
91+
92+
parse_result = urlparse(config["url"])
93+
if parse_result.netloc == "docs.google.com" and parse_result.path.lower().startswith("/spreadsheets/"):
94+
raise ConfigurationError(f'Failed to load {config["url"]}: please use the Official Google Sheets Source connector')
9095
return config
9196

9297
def check(self, logger, config: Mapping) -> AirbyteConnectionStatus:
9398
"""
9499
Check involves verifying that the specified file is reachable with
95100
our credentials.
96101
"""
97-
config = self._validate_and_transform(config)
102+
try:
103+
config = self._validate_and_transform(config)
104+
except ConfigurationError as e:
105+
logger.error(str(e))
106+
return AirbyteConnectionStatus(status=Status.FAILED, message=str(e))
107+
98108
client = self._get_client(config)
99109
source_url = client.reader.full_url
100-
logger.info(f"Checking access to {source_url}...")
101-
if "docs.google.com/spreadsheets" in source_url:
102-
reason = f"Failed to load {source_url}: please use the Official Google Sheets Source connector"
103-
logger.error(reason)
104-
return AirbyteConnectionStatus(status=Status.FAILED, message=reason)
105110
try:
106111
with client.reader.open():
107112
list(client.streams)

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,14 @@ def test_discover(source, config, client):
149149

150150
def test_check_wrong_reader_options(source, config):
151151
config["reader_options"] = '{encoding":"utf_16"}'
152-
with pytest.raises(Exception):
153-
source.check(logger=logger, config=config)
152+
assert source.check(logger=logger, config=config) == AirbyteConnectionStatus(
153+
status=Status.FAILED, message="reader_options is not valid JSON"
154+
)
155+
156+
157+
def test_check_google_spreadsheets_url(source, config):
158+
config["url"] = "https://docs.google.com/spreadsheets/d/"
159+
assert source.check(logger=logger, config=config) == AirbyteConnectionStatus(
160+
status=Status.FAILED,
161+
message="Failed to load https://docs.google.com/spreadsheets/d/: please use the Official Google Sheets Source connector",
162+
)

docs/integrations/sources/file.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ In order to read large files from a remote location, this connector uses the [sm
129129

130130
| Version | Date | Pull Request | Subject |
131131
| ------- | ---------- | -------------------------------------------------------- | -------------------------------------------------------- |
132+
| 0.2.30 | 2022-11-10 | [19222](https://github.com/airbytehq/airbyte/pull/19222) | Use AirbyteConnectionStatus for "check" command |
132133
| 0.2.28 | 2022-10-27 | [18428](https://github.com/airbytehq/airbyte/pull/18428) | Added retry logic for `Connection reset error - 104` |
133134
| 0.2.27 | 2022-10-26 | [18481](https://github.com/airbytehq/airbyte/pull/18481) | Fix check for wrong format |
134135
| 0.2.26 | 2022-10-18 | [18116](https://github.com/airbytehq/airbyte/pull/18116) | Transform Dropbox shared link |

0 commit comments

Comments
 (0)