Skip to content

Commit 705dd3e

Browse files
alkalimarcosmarxmoctavia-squidington-iii
authored
🎉 New Source - Xero [python cdk] (#18666)
* xero connector 0.1.0 * docs and stuff * CR fixes: added sample_config.json and removed ununsed catalog.json * CR fixes: added unit test for parse_date * CR: typo fixed * add xero to source def * correct tests * update accpt test * correct abnormal state file * auto-bump connector version Co-authored-by: marcosmarxm <marcosmarxm@gmail.com> Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com> Co-authored-by: Marcos Marx <marcosmarxm@users.noreply.github.com>
1 parent 1e551d0 commit 705dd3e

File tree

85 files changed

+37809
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+37809
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,13 @@
15471547
documentationUrl: https://docs.airbyte.com/integrations/sources/visma-economic
15481548
sourceType: api
15491549
releaseStage: alpha
1550+
- name: Xero
1551+
sourceDefinitionId: 6fd1e833-dd6e-45ec-a727-ab917c5be892
1552+
dockerRepository: airbyte/source-xero
1553+
dockerImageTag: 0.1.0
1554+
documentationUrl: https://docs.airbyte.com/integrations/sources/xero
1555+
sourceType: api
1556+
releaseStage: alpha
15501557
- name: xkcd
15511558
sourceDefinitionId: 80fddd16-17bd-4c0c-bf4a-80df7863fc9d
15521559
dockerRepository: airbyte/source-xkcd

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14320,6 +14320,76 @@
1432014320
supportsNormalization: false
1432114321
supportsDBT: false
1432214322
supported_destination_sync_modes: []
14323+
- dockerImage: "airbyte/source-xero:0.1.0"
14324+
spec:
14325+
documentationUrl: "https://docs.airbyte.io/integrations/sources/xero"
14326+
connectionSpecification:
14327+
$schema: "http://json-schema.org/draft-07/schema#"
14328+
title: "Xero Spec"
14329+
type: "object"
14330+
required:
14331+
- "authentication"
14332+
- "start_date"
14333+
- "scopes"
14334+
- "tenant_id"
14335+
- "client_id"
14336+
- "client_secret"
14337+
additionalProperties: true
14338+
properties:
14339+
client_id:
14340+
title: "Client ID"
14341+
type: "string"
14342+
description: "Enter your Xero application's Client ID"
14343+
client_secret:
14344+
title: "Client Secret"
14345+
type: "string"
14346+
description: "Enter your Xero application's Client Secret"
14347+
airbyte_secret: true
14348+
tenant_id:
14349+
title: "Tenant ID"
14350+
type: "string"
14351+
description: "Enter your Xero organization's Tenant ID"
14352+
scopes:
14353+
title: "Scopes"
14354+
type: "string"
14355+
description: "Enter your required list of scopes (delimited by comma)"
14356+
authentication:
14357+
type: "object"
14358+
title: "Authentication"
14359+
description: "Type and additional credentials of the Xero API connection"
14360+
oneOf:
14361+
- title: "Authenticate via Xero (OAuth) (unsupported yet)"
14362+
type: "object"
14363+
required:
14364+
- "auth_type"
14365+
- "refresh_token"
14366+
properties:
14367+
auth_type:
14368+
type: "string"
14369+
const: "oauth"
14370+
refresh_token:
14371+
title: "Refresh Token"
14372+
type: "string"
14373+
description: "Enter your Xero application's refresh token"
14374+
airbyte_secret: true
14375+
- title: "Custom Connections Authentication"
14376+
type: "object"
14377+
required:
14378+
- "auth_type"
14379+
properties:
14380+
auth_type:
14381+
type: "string"
14382+
const: "custom_connection"
14383+
start_date:
14384+
type: "string"
14385+
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
14386+
description: "UTC date and time in the format YYYY-MM-DDTHH:mm:ssZ. Any\
14387+
\ data with created_at before this data will not be synced."
14388+
examples:
14389+
- "2022-03-01T00:00:00Z"
14390+
supportsNormalization: false
14391+
supportsDBT: false
14392+
supported_destination_sync_modes: []
1432314393
- dockerImage: "airbyte/source-xkcd:0.1.1"
1432414394
spec:
1432514395
documentationUrl: "https://docs.airbyte.io/integrations/sources/xkcd"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
!Dockerfile
3+
!main.py
4+
!source_xero
5+
!setup.py
6+
!secrets
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM python:3.9.13-alpine3.15 as base
2+
3+
# build and load all requirements
4+
FROM base as builder
5+
WORKDIR /airbyte/integration_code
6+
7+
# upgrade pip to the latest version
8+
RUN apk --no-cache upgrade \
9+
&& pip install --upgrade pip \
10+
&& apk --no-cache add tzdata build-base
11+
12+
13+
COPY setup.py ./
14+
# install necessary packages to a temporary folder
15+
RUN pip install --prefix=/install .
16+
17+
# build a clean environment
18+
FROM base
19+
WORKDIR /airbyte/integration_code
20+
21+
# copy all loaded and built libraries to a pure basic image
22+
COPY --from=builder /install /usr/local
23+
# add default timezone settings
24+
COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
25+
RUN echo "Etc/UTC" > /etc/timezone
26+
27+
# bash is installed for more convenient debugging.
28+
RUN apk --no-cache add bash
29+
30+
# copy payload code only
31+
COPY main.py ./
32+
COPY source_xero ./source_xero
33+
34+
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
35+
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
36+
37+
LABEL io.airbyte.version=0.1.0
38+
LABEL io.airbyte.name=airbyte/source-xero
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Xero Source
2+
3+
This is the repository for the Xero source connector, written in Python.
4+
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/xero).
5+
6+
## Local development
7+
8+
### Prerequisites
9+
**To iterate on this connector, make sure to complete this prerequisites section.**
10+
11+
#### Minimum Python version required `= 3.9.0`
12+
13+
#### Build & Activate Virtual Environment and install dependencies
14+
From this connector directory, create a virtual environment:
15+
```
16+
python -m venv .venv
17+
```
18+
19+
This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your
20+
development environment of choice. To activate it from the terminal, run:
21+
```
22+
source .venv/bin/activate
23+
pip install -r requirements.txt
24+
pip install '.[tests]'
25+
```
26+
If you are in an IDE, follow your IDE's instructions to activate the virtualenv.
27+
28+
Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is
29+
used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`.
30+
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
31+
should work as you expect.
32+
33+
#### Building via Gradle
34+
You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow.
35+
36+
To build using Gradle, from the Airbyte repository root, run:
37+
```
38+
./gradlew :airbyte-integrations:connectors:source-xero:build
39+
```
40+
41+
#### Create credentials
42+
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/xero)
43+
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_xero/spec.yaml` file.
44+
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
45+
See `integration_tests/sample_config.json` for a sample config file.
46+
47+
**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source xero test creds`
48+
and place them into `secrets/config.json`.
49+
50+
### Locally running the connector
51+
```
52+
python main.py spec
53+
python main.py check --config secrets/config.json
54+
python main.py discover --config secrets/config.json
55+
python main.py read --config secrets/config.json --catalog integration_tests/configured_catalog.json
56+
```
57+
58+
### Locally running the connector docker image
59+
60+
#### Build
61+
First, make sure you build the latest Docker image:
62+
```
63+
docker build . -t airbyte/source-xero:dev
64+
```
65+
66+
You can also build the connector image via Gradle:
67+
```
68+
./gradlew :airbyte-integrations:connectors:source-xero:airbyteDocker
69+
```
70+
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
71+
the Dockerfile.
72+
73+
#### Run
74+
Then run any of the connector commands as follows:
75+
```
76+
docker run --rm airbyte/source-xero:dev spec
77+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-xero:dev check --config /secrets/config.json
78+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-xero:dev discover --config /secrets/config.json
79+
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-xero:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
80+
```
81+
## Testing
82+
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.
83+
First install test dependencies into your virtual environment:
84+
```
85+
pip install .[tests]
86+
```
87+
### Unit Tests
88+
To run unit tests locally, from the connector directory run:
89+
```
90+
python -m pytest unit_tests
91+
```
92+
93+
### Integration Tests
94+
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).
95+
#### Custom Integration tests
96+
Place custom tests inside `integration_tests/` folder, then, from the connector root, run
97+
```
98+
python -m pytest integration_tests
99+
```
100+
#### Acceptance Tests
101+
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.
102+
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.
103+
To run your integration tests with acceptance tests, from the connector root, run
104+
```
105+
python -m pytest integration_tests -p integration_tests.acceptance
106+
```
107+
To run your integration tests with docker
108+
109+
### Using gradle to run tests
110+
All commands should be run from airbyte project root.
111+
To run unit tests:
112+
```
113+
./gradlew :airbyte-integrations:connectors:source-xero:unitTest
114+
```
115+
To run acceptance and custom integration tests:
116+
```
117+
./gradlew :airbyte-integrations:connectors:source-xero:integrationTest
118+
```
119+
120+
## Dependency Management
121+
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.
122+
We split dependencies between two groups, dependencies that are:
123+
* required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
124+
* required for the testing need to go to `TEST_REQUIREMENTS` list
125+
126+
### Publishing a new version of the connector
127+
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
128+
1. Make sure your changes are passing unit and integration tests.
129+
1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)).
130+
1. Create a Pull Request.
131+
1. Pat yourself on the back for being an awesome contributor.
132+
1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# See [Source Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/source-acceptance-tests-reference)
2+
# for more information about how to configure these tests
3+
connector_image: airbyte/source-xero:dev
4+
tests:
5+
spec:
6+
- spec_path: "source_xero/spec.yaml"
7+
connection:
8+
- config_path: "integration_tests/sample_config.json"
9+
status: "succeed"
10+
- config_path: "integration_tests/invalid_config.json"
11+
status: "failed"
12+
discovery:
13+
- config_path: "integration_tests/sample_config.json"
14+
basic_read:
15+
- config_path: "integration_tests/sample_config.json"
16+
configured_catalog_path: "integration_tests/configured_catalog.json"
17+
empty_streams: ["manual_journals", "credit_notes", "overpayments", "bank_transfers", "purchase_orders", "prepayments"]
18+
incremental:
19+
- config_path: "integration_tests/sample_config.json"
20+
configured_catalog_path: "integration_tests/configured_catalog.json"
21+
future_state_path: "integration_tests/abnormal_state.json"
22+
full_refresh:
23+
- config_path: "integration_tests/sample_config.json"
24+
configured_catalog_path: "integration_tests/configured_catalog.json"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env sh
2+
3+
# Build latest connector image
4+
docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2-)
5+
6+
# Pull latest acctest image
7+
docker pull airbyte/source-acceptance-test:latest
8+
9+
# Run
10+
docker run --rm -it \
11+
-v /var/run/docker.sock:/var/run/docker.sock \
12+
-v /tmp:/tmp \
13+
-v $(pwd):/test_input \
14+
airbyte/source-acceptance-test \
15+
--acceptance-test-config /test_input
16+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
plugins {
2+
id 'airbyte-python'
3+
id 'airbyte-docker'
4+
id 'airbyte-source-acceptance-test'
5+
}
6+
7+
airbytePython {
8+
moduleDirectory 'source_xero'
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
#
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"bank_transactions": {
3+
"date": "2033-10-28T11:08:03+00:00"
4+
},
5+
"contacts": {
6+
"date": "2033-10-30T10:47:59+00:00"
7+
},
8+
"credit_notes": {
9+
"date": "2033-10-28T11:06:20+00:00"
10+
},
11+
"invoices": {
12+
"date": "2033-10-28T16:36:42+00:00"
13+
},
14+
"manual_journals": {
15+
"date": "2033-10-28T12:08:59+00:00"
16+
},
17+
"overpayments": {
18+
"date": "2033-10-28T12:30:01+00:00"
19+
},
20+
"prepayments": {
21+
"date": "2033-10-18T11:51:45+00:00"
22+
},
23+
"purchase_orders": {
24+
"date": "2033-10-18T11:51:45+00:00"
25+
},
26+
"accounts": {
27+
"date": "2033-10-18T11:51:45+00:00"
28+
},
29+
"bank_transfers": {
30+
"date": "2033-10-28T07:28:42+00:00"
31+
},
32+
"employees": {
33+
"date": "2033-10-18T11:51:45+00:00"
34+
},
35+
"items": {
36+
"date": "2033-10-18T11:51:45+00:00"
37+
},
38+
"payments": {
39+
"date": "2033-10-28T16:36:42+00:00"
40+
},
41+
"users": {
42+
"date": "2033-08-30T09:53:59+00:00"
43+
}
44+
}

0 commit comments

Comments
 (0)