Skip to content

Commit

Permalink
🎉 Source Square: migrate to Beta (YAML) (#19369)
Browse files Browse the repository at this point in the history
* 🐛 Source Square: migrate to Beta (YAML)

* Source Square: update CDK, reorder properties

* Source Square: update docs

* Source Square: add tests; change release stage to beta

* Source Square: fix tests

* Source Square: fix tests formatting

* Source Square: fix tests formatting

* Source Square: Add token_expiry_date_format to oauth authenticator

* Source Square: ref component

* Source Square: Refactor Slicer; inherit from datetime slicer

* Source Square: test fix

* Source Square: publish low-code rc1

* Source Square: update version

* auto-bump connector version

Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
  • Loading branch information
artem1205 and octavia-squidington-iii authored Dec 16, 2022
1 parent 2c5d799 commit 697b91a
Show file tree
Hide file tree
Showing 24 changed files with 2,448 additions and 951 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1560,11 +1560,11 @@
- name: Square
sourceDefinitionId: 77225a51-cd15-4a13-af02-65816bd0ecf4
dockerRepository: airbyte/source-square
dockerImageTag: 0.1.4
dockerImageTag: 0.2.0
documentationUrl: https://docs.airbyte.com/integrations/sources/square
icon: square.svg
sourceType: api
releaseStage: alpha
releaseStage: beta
- sourceDefinitionId: 7a4327c4-315a-11ec-8d3d-0242ac130003
name: Strava
dockerRepository: airbyte/source-strava
Expand Down
81 changes: 36 additions & 45 deletions airbyte-config/init/src/main/resources/seed/source_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13904,46 +13904,22 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-square:0.1.4"
- dockerImage: "airbyte/source-square:0.2.0"
spec:
documentationUrl: "https://docs.airbyte.com/integrations/sources/square"
connectionSpecification:
$schema: "http://json-schema.org/draft-07/schema#"
title: "Square Source CDK Specifications"
title: "Square Spec"
type: "object"
required:
- "is_sandbox"
additionalProperties: true
properties:
is_sandbox:
type: "boolean"
description: "Determines whether to use the sandbox or production environment."
title: "Sandbox"
examples:
- true
- false
default: false
start_date:
type: "string"
description: "UTC date in the format YYYY-MM-DD. Any data before this date\
\ will not be replicated. If not set, all data will be replicated."
title: "Start Date"
examples:
- "2021-01-01"
default: "2021-01-01"
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
include_deleted_objects:
type: "boolean"
description: "In some streams there is an option to include deleted objects\
\ (Items, Categories, Discounts, Taxes)"
title: "Include Deleted Objects"
examples:
- true
- false
default: false
credentials:
title: "Authentication"
description: "Choose how to authenticate to Square."
type: "object"
title: "Credential Type"
order: 0
oneOf:
- title: "Oauth authentication"
type: "object"
Expand All @@ -13953,21 +13929,18 @@
- "client_secret"
- "refresh_token"
properties:
auth_type:
credentials_title:
type: "string"
const: "Oauth"
enum:
- "Oauth"
default: "Oauth"
const: "OAuth Credentials"
order: 0
client_id:
title: "Client ID"
type: "string"
title: "Client ID"
description: "The Square-issued ID of your application"
airbyte_secret: true
client_secret:
title: "Client Secret"
type: "string"
title: "Client Secret"
description: "The Square-issued application secret for your application"
airbyte_secret: true
refresh_token:
Expand All @@ -13976,24 +13949,42 @@
description: "A refresh token generated using the above client ID\
\ and secret"
airbyte_secret: true
- type: "object"
title: "API Key"
- title: "API key"
type: "object"
required:
- "auth_type"
- "api_key"
properties:
auth_type:
credentials_title:
type: "string"
const: "Apikey"
enum:
- "Apikey"
default: "Apikey"
order: 1
const: "API Key"
order: 0
api_key:
title: "API key token"
type: "string"
title: "API key token"
description: "The API key for a Square application"
airbyte_secret: true
is_sandbox:
type: "boolean"
description: "Determines whether to use the sandbox or production environment."
title: "Sandbox"
default: false
order: 1
start_date:
type: "string"
description: "UTC date in the format YYYY-MM-DD. Any data before this date\
\ will not be replicated. If not set, all data will be replicated."
title: "Start Date"
default: "2021-01-01"
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
order: 2
include_deleted_objects:
type: "boolean"
description: "In some streams there is an option to include deleted objects\
\ (Items, Categories, Discounts, Taxes)"
title: "Include Deleted Objects"
default: false
order: 3
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
Expand Down
36 changes: 29 additions & 7 deletions airbyte-integrations/connectors/source-square/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_square ./source_square

# 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_square ./source_square

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

LABEL io.airbyte.version=0.1.4
LABEL io.airbyte.version=0.2.0
LABEL io.airbyte.name=airbyte/source-square
58 changes: 3 additions & 55 deletions airbyte-integrations/connectors/source-square/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
# Square Source

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

## Local development

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

#### Minimum Python version required `= 3.7.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 @@ -39,21 +15,13 @@ 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/square)
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_square/spec.json` file.
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_square/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 square 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,31 +46,11 @@ docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-square:dev discover --
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-square: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

### Using gradle to run tests
Expand Down
3 changes: 3 additions & 0 deletions airbyte-integrations/connectors/source-square/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
connector_image: airbyte/source-square:dev
tests:
spec:
- spec_path: "source_square/spec.json"
- spec_path: "source_square/spec.yaml"
connection:
- config_path: "secrets/config.json"
status: "succeed"
Expand All @@ -15,13 +15,18 @@ tests:
basic_read:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
empty_streams: ["payments"]
expect_records:
path: "integration_tests/expected_records.txt"
- config_path: "secrets/config_oauth.json"
configured_catalog_path: "integration_tests/configured_catalog_oauth.json"
empty_streams: ["shifts", "orders", "payments", "refunds"]
expect_records:
path: "integration_tests/expected_records_oauth.txt"
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"

configured_catalog_path: "integration_tests/configured_catalog.json"
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-square/acceptance-test-docker.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/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)
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"items": {
"updated_at": "2200-01-01T00:00:00+00:00"
"updated_at": "2200-01-01T00:00:00.0Z"
},
"categories": {
"updated_at": "2200-01-01T00:00:00+00:00"
"updated_at": "2200-01-01T00:00:00.0Z"
},
"discounts": {
"updated_at": "2200-01-01T00:00:00+00:00"
"updated_at": "2200-01-01T00:00:00.0Z"
},
"taxes": {
"updated_at": "2200-01-01T00:00:00+00:00"
"updated_at": "2200-01-01T00:00:00.0Z"
},
"modifier_list": {
"updated_at": "2200-01-01T00:00:00+00:00"
"updated_at": "2200-01-01T00:00:00.0Z"
},
"refunds": {
"created_at": "2200-01-01T00:00:00+00:00"
"created_at": "2200-01-01T00:00:00.0Z"
},
"payments": {
"created_at": "2200-01-01T00:00:00+00:00"
"created_at": "2200-01-01T00:00:00.0Z"
}
}
Loading

0 comments on commit 697b91a

Please sign in to comment.