Skip to content

Commit

Permalink
✨Source Shortio: Migrate Python CDK to Low-code CDK (#28950)
Browse files Browse the repository at this point in the history
* Migrate Shortio to Low-Code

* Update abnormal state

* Format

* Update Docs

* Fix metadata.yaml

* Add pagination

* Add incremental sync

* add incremental parameters

* update metadata

* rollback update version

* release date

---------

Co-authored-by: marcosmarxm <marcosmarxm@gmail.com>
  • Loading branch information
2 people authored and jbfbell committed Aug 5, 2023
1 parent 5b403dd commit 055d0f6
Show file tree
Hide file tree
Showing 24 changed files with 299 additions and 421 deletions.
36 changes: 29 additions & 7 deletions airbyte-integrations/connectors/source-shortio/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
FROM python:3.9-slim
FROM python:3.9.11-alpine3.15 as base

# build and load all requirements
FROM base as builder
WORKDIR /airbyte/integration_code

# upgrade pip to the latest version
RUN apk --no-cache upgrade \
&& pip install --upgrade pip \
&& apk --no-cache add tzdata build-base

# Bash is installed for more convenient debugging.
RUN apt-get update && apt-get install -y bash && rm -rf /var/lib/apt/lists/*

COPY setup.py ./
# install necessary packages to a temporary folder
RUN pip install --prefix=/install .

# build a clean environment
FROM base
WORKDIR /airbyte/integration_code
COPY source_shortio ./source_shortio

# copy all loaded and built libraries to a pure basic image
COPY --from=builder /install /usr/local
# add default timezone settings
COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN echo "Etc/UTC" > /etc/timezone

# bash is installed for more convenient debugging.
RUN apk --no-cache add bash

# copy payload code only
COPY main.py ./
COPY setup.py ./
RUN pip install .
COPY source_shortio ./source_shortio

ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.3
LABEL io.airbyte.version=0.2.0
LABEL io.airbyte.name=airbyte/source-shortio
69 changes: 8 additions & 61 deletions airbyte-integrations/connectors/source-shortio/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
# Shortio Source

This is the repository for the Shortio source connector, written in Python.
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/shortio).
This is the repository for the Shortio configuration based source connector.
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.com/integrations/sources/shortio).

## Local development

### Prerequisites
**To iterate on this connector, make sure to complete this prerequisites section.**

#### Minimum Python version required `= 3.9.0`

#### Build & Activate Virtual Environment and install dependencies
From this connector directory, create a virtual environment:
```
python -m venv .venv
```

This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your
development environment of choice. To activate it from the terminal, run:
```
source .venv/bin/activate
pip install -r requirements.txt
```
If you are in an IDE, follow your IDE's instructions to activate the virtualenv.

Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is
used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`.
If this is mumbo jumbo to you, don't worry about it, just put your deps in `setup.py` but install using `pip install -r requirements.txt` and everything
should work as you expect.

#### Building via Gradle
You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow.

Expand All @@ -38,22 +14,14 @@ To build using Gradle, from the Airbyte repository root, run:
```

#### Create credentials
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/shortio)
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_shortio/spec.json` file.
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.com/integrations/sources/shortio)
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_shortio/spec.yaml` file.
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
See `integration_tests/sample_config.json` for a sample config file.

**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source shortio test creds`
and place them into `secrets/config.json`.

### Locally running the connector
```
python main.py spec
python main.py check --config secrets/config.json
python main.py discover --config secrets/config.json
python main.py read --config secrets/config.json --catalog integration_tests/configured_catalog.json
```

### Locally running the connector docker image

#### Build
Expand All @@ -78,32 +46,15 @@ docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-shortio:dev discover -
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-shortio:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
```
## Testing
Make sure to familiarize yourself with [pytest test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery) to know how your test files and methods should be named.
First install test dependencies into your virtual environment:
```
pip install .[tests]
```
### Unit Tests
To run unit tests locally, from the connector directory run:
```
python -m pytest unit_tests
```

### Integration Tests
There are two types of integration tests: Acceptance Tests (Airbyte's test suite for all source connectors) and custom integration tests (which are specific to this connector).
#### Custom Integration tests
Place custom tests inside `integration_tests/` folder, then, from the connector root, run
```
python -m pytest integration_tests
```
#### Acceptance Tests
Customize `acceptance-test-config.yml` file to configure tests. See [Connector Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/connector-acceptance-tests-reference) for more information.
Customize `acceptance-test-config.yml` file to configure tests. See [Connector Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/connector-acceptance-tests-reference) for more information.
If your connector requires to create or destroy resources for use during acceptance tests create fixtures for it and place them inside integration_tests/acceptance.py.
To run your integration tests with acceptance tests, from the connector root, run

To run your integration tests with Docker, run:
```
python -m pytest integration_tests -p integration_tests.acceptance
./acceptance-test-docker.sh
```
To run your integration tests with docker

### Using gradle to run tests
All commands should be run from airbyte project root.
Expand All @@ -129,7 +80,3 @@ You've checked out the repo, implemented a million dollar feature, and you're re
1. Create a Pull Request.
1. Pat yourself on the back for being an awesome contributor.
1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.

## Notes specific to the connector

1. The links stream output doesn't match exactly what the documentation in the official website say (e.g. an owner object is returned as part of the response but that isn't listed there.)
3 changes: 3 additions & 0 deletions airbyte-integrations/connectors/source-shortio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
# See [Connector Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/connector-acceptance-tests-reference)
# for more information about how to configure these tests
connector_image: airbyte/source-shortio:dev
tests:
acceptance_tests:
spec:
- spec_path: "source_shortio/spec.json"
tests:
- spec_path: "source_shortio/spec.yaml"
connection:
- config_path: "secrets/config.json"
status: "succeed"
- config_path: "integration_tests/invalid_config.json"
status: "failed"
tests:
- config_path: "secrets/config.json"
status: "succeed"
- config_path: "integration_tests/invalid_config.json"
status: "failed"
discovery:
- config_path: "secrets/config.json"
tests:
- config_path: "secrets/config.json"
basic_read:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
empty_streams: ["clicks"]
# TODO: uncomment when any of incremental streams has records
# incremental:
# - config_path: "secrets/config.json"
# configured_catalog_path: "integration_tests/configured_catalog.json"
# future_state_path: "integration_tests/abnormal_state.json"
tests:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
empty_streams:
- name: clicks
bypass_reason: "Sandbox account cannot seed the stream"
expect_records:
path: "integration_tests/expected_records.jsonl"
extra_fields: no
exact_order: no
extra_records: yes
incremental:
# bypass_reason: "This connector does not implement incremental sync"
tests:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
future_state:
future_state_path: "integration_tests/abnormal_state.json"
full_refresh:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
tests:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
1 change: 1 addition & 0 deletions airbyte-integrations/connectors/source-shortio/acceptance-test-docker.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env sh

source "$(git rev-parse --show-toplevel)/airbyte-integrations/bases/connector-acceptance-test/acceptance-test-docker.sh"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{
"clicks": {
"dt": "2052-07-17 14:03:43.449925"
[
{
"type": "STREAM",
"stream": {
"stream_state": { "updatedAt": "2099-07-31T03:43:59.244Z" },
"stream_descriptor": { "name": "links" }
}
},
{
"type": "STREAM",
"stream": {
"stream_state": { "dt": "2099-09-10T12:44:55.000Z" },
"stream_descriptor": { "name": "clicks" }
}
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@

@pytest.fixture(scope="session", autouse=True)
def connector_setup():
"""This fixture is a placeholder for external resources that acceptance test might require."""
yield
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
{
"streams": [
{
"destination_sync_mode": "append",
"sync_mode": "incremental",
"stream": {
"name": "clicks",
"source_defined_cursor": true,
"default_cursor_field": ["dt"],
"supported_sync_modes": ["incremental"],
"json_schema": {}
}
},
"destination_sync_mode": "append",
"sync_mode": "incremental"
},
{
"destination_sync_mode": "append",
"sync_mode": "full_refresh",
"stream": {
"name": "links",
"source_defined_cursor": true,
"supported_sync_modes": ["full_refresh"],
"json_schema": {}
}
"json_schema": {},
"supported_sync_modes": ["full_refresh", "incremental"]
},
"sync_mode": "incremental",
"destination_sync_mode": "append"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"stream": "links", "data": {"lcpath": "gem9bt", "createdAt": "2021-08-09T13:51:46.000Z", "source": "spreadsheets", "DomainId": 235589, "archived": false, "updatedAt": "2021-08-09T13:51:46.000Z", "OwnerId": 231775, "originalURL": "https://jk-genesis.com.ua/promotions/kvartiry-rjadom-s-metro-shuljavskaja-ot-980-00-grn?utm_source=lun.ua&utm_medium=referral&utm_content=239563406.1628516963&utm_term=5105", "cloaking": false, "path": "geM9Bt", "idString": "lnk_ZhP_Tw4Ye", "shortURL": "https://1hsf.short.gy/geM9Bt", "secureShortURL": "https://1hsf.short.gy/geM9Bt", "id": "lnk_ZhP_Tw4Ye", "User": {"id": 231775, "name": "Jean Lafleur", "email": "integration-test@airbyte.io", "photoURL": null}}, "emitted_at": 1691072031178}
{"stream": "links", "data": {"lcpath": "4sfi0i", "createdAt": "2021-08-09T13:51:46.000Z", "source": "spreadsheets", "DomainId": 235589, "archived": false, "updatedAt": "2021-08-09T13:51:46.000Z", "OwnerId": 231775, "originalURL": "https://airbyte.io/connector-development-kit", "cloaking": false, "path": "4SfI0I", "idString": "lnk_ZhP_Tw4Y3", "shortURL": "https://1hsf.short.gy/4SfI0I", "secureShortURL": "https://1hsf.short.gy/4SfI0I", "id": "lnk_ZhP_Tw4Y3", "User": {"id": 231775, "name": "Jean Lafleur", "email": "integration-test@airbyte.io", "photoURL": null}}, "emitted_at": 1691072031183}
{"stream": "links", "data": {"lcpath": "saeipy", "createdAt": "2021-08-09T13:51:46.000Z", "source": "spreadsheets", "DomainId": 235589, "archived": false, "updatedAt": "2021-08-09T13:51:46.000Z", "OwnerId": 231775, "originalURL": "https://great.com.ua/ua/news/11/znizhki-do-10-u-zhitlovomu-kompleksi-great/?utm_source=lun.ua&utm_medium=referral&utm_content=239563406.1628516963&utm_term=6405", "cloaking": false, "path": "Saeipy", "idString": "lnk_ZhP_Tw4Y9", "shortURL": "https://1hsf.short.gy/Saeipy", "secureShortURL": "https://1hsf.short.gy/Saeipy", "id": "lnk_ZhP_Tw4Y9", "User": {"id": 231775, "name": "Jean Lafleur", "email": "integration-test@airbyte.io", "photoURL": null}}, "emitted_at": 1691072031187}
{"stream": "links", "data": {"lcpath": "48ne6k", "createdAt": "2021-08-09T13:51:46.000Z", "source": "spreadsheets", "DomainId": 235589, "archived": false, "updatedAt": "2021-08-09T13:51:46.000Z", "OwnerId": 231775, "originalURL": "http://www.redstar.ru/2005/03/10_03/1_02.html", "cloaking": false, "path": "48ne6k", "idString": "lnk_ZhP_Tw4Y4", "shortURL": "https://1hsf.short.gy/48ne6k", "secureShortURL": "https://1hsf.short.gy/48ne6k", "id": "lnk_ZhP_Tw4Y4", "User": {"id": 231775, "name": "Jean Lafleur", "email": "integration-test@airbyte.io", "photoURL": null}}, "emitted_at": 1691072031191}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"secret_key": "RANDOMKEY",
"domain_id": "123456",
"start_date": "2021-07-01"
"domain_id": "99999999",
"start_date": "2099-07-01"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"secret_key": "KEY",
"domain_id": "123456",
"start_date": "2023-07-30T03:43:59.244Z"
}
27 changes: 14 additions & 13 deletions airbyte-integrations/connectors/source-shortio/metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
data:
allowedHosts:
hosts:
- https://api.short.io
- https://api-v2.short.cm
registries:
oss:
enabled: true
cloud:
enabled: true
connectorSubtype: api
connectorType: source
definitionId: 2fed2292-5586-480c-af92-9944e39fe12d
dockerImageTag: 0.1.3
dockerImageTag: 0.2.0
dockerRepository: airbyte/source-shortio
githubIssueLabel: source-shortio
icon: short.svg
icon: shortio.svg
license: MIT
name: Short.io
registries:
cloud:
enabled: true
oss:
enabled: true
name: Shortio
releaseDate: 2023-08-02
releaseStage: alpha
documentationUrl: https://docs.airbyte.com/integrations/sources/shortio
tags:
- language:python
_ab_internal:
_sl: 100
_ql: 200
supportLevel: community
- language:lowcode
metadataSpecVersion: "1.0"
9 changes: 6 additions & 3 deletions airbyte-integrations/connectors/source-shortio/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

from setuptools import find_packages, setup

MAIN_REQUIREMENTS = ["airbyte-cdk~=0.1"]
MAIN_REQUIREMENTS = [
"airbyte-cdk~=0.1",
]

TEST_REQUIREMENTS = [
"pytest~=6.2.5",
"pytest~=6.2",
"pytest-mock~=3.6.1",
"connector-acceptance-test",
]

Expand All @@ -19,7 +22,7 @@
author_email="contact@airbyte.io",
packages=find_packages(),
install_requires=MAIN_REQUIREMENTS,
package_data={"": ["*.json", "schemas/*.json", "schemas/shared/*.json"]},
package_data={"": ["*.json", "*.yaml", "schemas/*.json", "schemas/shared/*.json"]},
extras_require={
"tests": TEST_REQUIREMENTS,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
#
# MIT License
#
# Copyright (c) 2020 Airbyte
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#


Expand Down
Loading

0 comments on commit 055d0f6

Please sign in to comment.