Skip to content

Commit

Permalink
Source Plaid: port to Python CDK (#7977)
Browse files Browse the repository at this point in the history
  • Loading branch information
firmbase-tal committed Jan 10, 2022
1 parent 0c57100 commit e68c564
Show file tree
Hide file tree
Showing 32 changed files with 677 additions and 428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"sourceDefinitionId": "ed799e2b-2158-4c66-8da4-b40fe63bc72a",
"name": "Plaid",
"dockerRepository": "airbyte/source-plaid",
"dockerImageTag": "0.2.1",
"dockerImageTag": "0.3.0",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/plaid",
"icon": "plaid.svg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@
- name: Plaid
sourceDefinitionId: ed799e2b-2158-4c66-8da4-b40fe63bc72a
dockerRepository: airbyte/source-plaid
dockerImageTag: 0.2.1
dockerImageTag: 0.3.0
documentationUrl: https://docs.airbyte.io/integrations/sources/plaid
icon: plaid.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5412,7 +5412,7 @@
- - "client_secret"
oauthFlowOutputParameters:
- - "refresh_token"
- dockerImage: "airbyte/source-plaid:0.2.1"
- dockerImage: "airbyte/source-plaid:0.3.0"
spec:
documentationUrl: "https://plaid.com/docs/api/"
connectionSpecification:
Expand All @@ -5422,6 +5422,7 @@
- "access_token"
- "api_key"
- "client_id"
- "plaid_env"
additionalProperties: false
properties:
access_token:
Expand Down
7 changes: 3 additions & 4 deletions airbyte-integrations/connectors/source-plaid/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
*
!Dockerfile
!Dockerfile.test
!package.json
!spec.json
!source.js
!main.py
!source_plaid
!setup.py
!secrets
!fullrefresh_configured_catalog.json
1 change: 0 additions & 1 deletion airbyte-integrations/connectors/source-plaid/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions airbyte-integrations/connectors/source-plaid/.prettierrc

This file was deleted.

44 changes: 33 additions & 11 deletions airbyte-integrations/connectors/source-plaid/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
# node 14
FROM node:alpine3.12
FROM python:3.7.11-alpine3.14 as base

# build and load all requirements
FROM base as builder
WORKDIR /airbyte/integration_code
# Copy source files
COPY package.json .
COPY source.js .
COPY spec.json .
# Install any needed dependencies
RUN npm install

ENV AIRBYTE_ENTRYPOINT "node /airbyte/integration_code/source.js"
ENTRYPOINT ["node", "/airbyte/integration_code/source.js"]
# upgrade pip to the latest version
RUN apk --no-cache upgrade \
&& pip install --upgrade pip \
&& apk --no-cache add tzdata build-base

LABEL io.airbyte.version=0.2.1

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 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 source_plaid ./source_plaid

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

LABEL io.airbyte.version=0.3.0
LABEL io.airbyte.name=airbyte/source-plaid
128 changes: 91 additions & 37 deletions airbyte-integrations/connectors/source-plaid/README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,129 @@
# Plaid Source

This is the repository for the JavaScript Template source connector, written in JavaScript.
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/javascript-template).
This is the repository for the Plaid source connector, written in Python.
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/plaid-new).

## Local development

### Prerequisites

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

#### Build & Activate Virtual Environment

First, build the module by running the following from the `airbyte` project root directory:
#### Minimum Python version required `= 3.7.0`

#### Build & Activate Virtual Environment and install dependencies
From this connector directory, create a virtual environment:
```
./gradlew :airbyte-integrations:connectors:source-plaid:build
python -m venv .venv
```

This will generate a virtualenv for this module in `source-plaid/.venv`. Make sure this venv is active in your
development environment of choice. To activate the venv from the terminal, run:

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:
```
cd airbyte-integrations/connectors/source-plaid # cd into the connector directory
source .venv/bin/activate
pip install -r requirements.txt
```

If you are in an IDE, follow your IDE's instructions to activate the virtualenv.

#### Create credentials
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
From the Airbyte repository root, run:
```
./gradlew :airbyte-integrations:connectors:source-plaid-new:build
```

**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/javascript-template)
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_javascript_template/spec.json` file.
See `sample_files/sample_config.json` for a sample config file.
#### Create credentials
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/plaid)
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_plaid/spec.json` file.
Note that the `secrets` directory is gitignored by default, 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 RPass under the secret name `source-plaid-integration-test-config`
**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source plaid-new test creds`
and place them into `secrets/config.json`.

### Locally running the connector

```
npm install
node source.js spec
node source.js check --config secrets/config.json
node source.js discover --config secrets/config.json
node source.js read --config secrets/config.json --catalog sample_files/configured_catalog.json
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
```

### Unit Tests (wip)

To run unit tests locally, from the connector directory run:
### Locally running the connector docker image

#### Build
First, make sure you build the latest Docker image:
```
npm test
docker build . -t airbyte/source-plaid:dev
```

### Locally running the connector docker image

You can also build the connector image via Gradle:
```
# in airbyte root directory
./gradlew :airbyte-integrations:connectors:source-plaid:airbyteDocker
```
When building via Gradle, the docker image name and tag, respectively, are the values of the `io.airbyte.name` and `io.airbyte.version` `LABEL`s in
the Dockerfile.

#### Run
Then run any of the connector commands as follows:
```
docker run --rm airbyte/source-plaid:dev spec
docker run --rm -v $(pwd)/airbyte-integrations/connectors/source-plaid/secrets:/secrets airbyte/source-plaid:dev check --config /secrets/config.json
docker run --rm -v $(pwd)/airbyte-integrations/connectors/source-plaid/secrets:/secrets airbyte/source-plaid:dev discover --config /secrets/config.json
docker run --rm -v $(pwd)/airbyte-integrations/connectors/source-plaid/secrets:/secrets -v $(pwd)/airbyte-integrations/connectors/source-plaid/sample_files:/sample_files airbyte/source-plaid:dev read --config /secrets/config.json --catalog /sample_files/fullrefresh_configured_catalog.json
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-plaid:dev check --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-plaid:dev discover --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-plaid: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 [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-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
```
python -m pytest integration_tests -p integration_tests.acceptance
```
To run your integration tests with docker

1. From the airbyte project root, run `./gradlew :airbyte-integrations:connectors:source-plaid:integrationTest` to run the standard integration test suite.
1. To run additional integration tests, place your integration tests in a new directory `integration_tests` and run them with `node test (wip)`.
### Using gradle to run tests
All commands should be run from airbyte project root.
To run unit tests:
```
./gradlew :airbyte-integrations:connectors:source-plaid-new:unitTest
```
To run acceptance and custom integration tests:
```
./gradlew :airbyte-integrations:connectors:source-plaid-new:integrationTest
```

## Dependency Management

All of your dependencies should go in `package.json`.
All of your dependencies should go in `setup.py`, NOT `requirements.txt`. The requirements file is only used to connect internal Airbyte dependencies in the monorepo for local development.
We split dependencies between two groups, dependencies that are:
* required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
* required for the testing need to go to `TEST_REQUIREMENTS` list

### Publishing a new version of the connector
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
1. Make sure your changes are passing unit and integration tests.
1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)).
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference)
# for more information about how to configure these tests
connector_image: airbyte/source-plaid:dev
tests:
spec:
- spec_path: "source_plaid/spec.json"
connection:
- config_path: "secrets/config.json"
status: "succeed"
- config_path: "integration_tests/invalid_config.json"
status: "failed"
discovery:
- config_path: "secrets/config.json"
basic_read:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
empty_streams: []
incremental:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
future_state_path: "integration_tests/abnormal_state.json"
full_refresh:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

# Build latest connector image
docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2)

# Pull latest acctest image
docker pull airbyte/source-acceptance-test:latest

# Run
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp:/tmp \
-v $(pwd):/test_input \
airbyte/source-acceptance-test \
--acceptance-test-config /test_input

40 changes: 6 additions & 34 deletions airbyte-integrations/connectors/source-plaid/build.gradle
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
plugins {
id 'airbyte-python'
id 'airbyte-docker'
id 'airbyte-standard-source-test-file'
id 'base' // ?
id 'com.github.node-gradle.node' version '2.2.4'
id 'airbyte-source-acceptance-test'
}

node {
download = true
version = "14.11.0"
}

npm_run_build {
inputs.files fileTree('public')
inputs.files fileTree('src')
inputs.file 'package.json'
inputs.file 'package-lock.json'

outputs.dir project.buildDir
}
assemble.dependsOn npm_run_build

//task test(type: NpmTask) {
// dependsOn assemble
//
// args = ['run', 'test', '--', '--watchAll=false']
// inputs.files fileTree('src')
// inputs.file 'package.json'
// inputs.file 'package-lock.json'
//}

airbyteStandardSourceTestFile {
// All these input paths must live inside this connector's directory (or subdirectories)
configPath = "secrets/config.json"
configuredCatalogPath = "sample_files/fullrefresh_configured_catalog.json"
specPath = "spec.json"
airbytePython {
moduleDirectory 'source_plaid_singer'
}

dependencies {
implementation files(project(':airbyte-integrations:bases:base-standard-source-test-file').airbyteDocker.outputs)
implementation files(project(':airbyte-integrations:bases:base').airbyteDocker.outputs)
implementation files(project(':airbyte-integrations:bases:source-acceptance-test').airbyteDocker.outputs)
implementation files(project(':airbyte-integrations:bases:base-python').airbyteDocker.outputs)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"transaction": {
"date": "2120-01-01"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#


import pytest

pytest_plugins = ("source_acceptance_test.plugin",)


@pytest.fixture(scope="session", autouse=True)
def connector_setup():
"""This fixture is a placeholder for external resources that acceptance test might require."""
yield

0 comments on commit e68c564

Please sign in to comment.