Skip to content

Commit

Permalink
馃帀 New Source: Whisky Hunter API [low-code CDK] (airbytehq#17918)
Browse files Browse the repository at this point in the history
* initial commit for source-whisky-hunter

* better logs

* finish up connector

* fix catalog

* fix bug in connector_runner.py that doesn't allow falsey configs

* add bootstrap.md

* add docs

* fix typo

* fix source-accept test

* auto-bump connector version

Co-authored-by: marcosmarxm <marcosmarxm@gmail.com>
Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
  • Loading branch information
3 people authored and jhammarstedt committed Oct 31, 2022
1 parent 3ea57a4 commit c617d64
Show file tree
Hide file tree
Showing 32 changed files with 726 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,13 @@
icon: webflow.svg
sourceType: api
releaseStage: alpha
- name: Whisky Hunter
sourceDefinitionId: e65f84c0-7598-458a-bfac-f770c381ff5d
dockerRepository: airbyte/source-whisky-hunter
dockerImageTag: 0.1.0
documentationUrl: https://docs.airbyte.com/integrations/sources/whisky-hunter
sourceType: api
releaseStage: alpha
- name: WooCommerce
sourceDefinitionId: 2a2552ca-9f78-4c1c-9eb7-4d0dc66d72df
dockerRepository: airbyte/source-woocommerce
Expand Down
12 changes: 12 additions & 0 deletions airbyte-config/init/src/main/resources/seed/source_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11844,6 +11844,18 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-whisky-hunter:0.1.0"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/whisky-hunter"
connectionSpecification:
$schema: "http://json-schema.org/draft-07/schema#"
title: "Whisky Hunter Spec"
type: "object"
additionalProperties: true
properties: {}
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-woocommerce:0.1.2"
spec:
documentationUrl: "https://docs.airbyte.com/integrations/sources/woocommerce"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ def _validate_records_structure(records: List[AirbyteRecordMessage], configured_
continue
record_fields = set(get_object_structure(record.data))
common_fields = set.intersection(record_fields, schema_pathes)
assert common_fields, f" Record from {record.stream} stream should have some fields mentioned by json schema, {schema_pathes}"

assert (
common_fields
), f" Record {record} from {record.stream} stream with fields {record_fields} should have some fields mentioned by json schema: {schema_pathes}"

@staticmethod
def _validate_schema(records: List[AirbyteRecordMessage], configured_catalog: ConfiguredAirbyteCatalog):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def _prepare_volumes(self, config: Optional[Mapping], state: Optional[Mapping],
self.input_folder.mkdir(parents=True)
self.output_folder.mkdir(parents=True)

if config:
# using "is not None" to allow falsey config objects like {} to still write
if config is not None:
with open(str(self.input_folder / "tap_config.json"), "w") as outfile:
json.dump(dict(config), outfile)

Expand Down Expand Up @@ -149,7 +150,7 @@ def read(cls, container: Container, command: str = None, with_ext: bool = True)
raise
if exit_status["StatusCode"]:
error = exit_status["Error"] or exception or line
logging.error(f"Docker container was failed, " f'code {exit_status["StatusCode"]}, error:\n{error}')
logging.error(f"Docker container failed, " f'code {exit_status["StatusCode"]}, error:\n{error}')
if with_ext:
raise ContainerError(
container=container,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def test_read(schema, record, should_fail):
]
t = _TestBasicRead()
if should_fail:
with pytest.raises(AssertionError, match="stream should have some fields mentioned by json schema"):
with pytest.raises(AssertionError, match="should have some fields mentioned by json schema"):
t.test_read(None, catalog, input_config, [], docker_runner_mock, MagicMock())
else:
t.test_read(None, catalog, input_config, [], docker_runner_mock, MagicMock())
Expand Down
1 change: 1 addition & 0 deletions airbyte-integrations/builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
| Twilio | [![source-twilio](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-twilio%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-twilio) |
| Typeform | [![source-typeform](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-typeform%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-typeform) |
| US Census | [![source-us-census](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-us-census%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-us-census) |
| Whisky Hunter | [![source-whisky-hunter](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-whisky-hunter%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-whisky-hunter) |
| Wrike | [![source-wrike](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-wrike%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-wrike) |
| YouTube Analytics | [![source-youtube-analytics](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-youtube-analytics%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-youtube-analytics) |
| Zendesk Chat | [![source-zendesk-chat](https://img.shields.io/endpoint?url=https%3A%2F%2Fdnsgjos7lj2fu.cloudfront.net%2Ftests%2Fsummary%2Fsource-zendesk-chat%2Fbadge.json)](https://dnsgjos7lj2fu.cloudfront.net/tests/summary/source-zendesk-chat) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!Dockerfile
!main.py
!source_whisky_hunter
!setup.py
!secrets
38 changes: 38 additions & 0 deletions airbyte-integrations/connectors/source-whisky-hunter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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


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_whisky_hunter ./source_whisky_hunter

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

LABEL io.airbyte.version=0.1.0
LABEL io.airbyte.name=airbyte/source-whisky-hunter
79 changes: 79 additions & 0 deletions airbyte-integrations/connectors/source-whisky-hunter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Whisky Hunter Source

This is the repository for the Whisky Hunter configuration based source connector.
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/whisky-hunter).

## Local development

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

To build using Gradle, from the Airbyte repository root, run:
```
./gradlew :airbyte-integrations:connectors:source-whisky-hunter:build
```

#### Create credentials
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/whisky-hunter)
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_whisky_hunter/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 whisky-hunter test creds`
and place them into `secrets/config.json`.

### Locally running the connector docker image

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

You can also build the connector image via Gradle:
```
./gradlew :airbyte-integrations:connectors:source-whisky-hunter: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-whisky-hunter:dev spec
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-whisky-hunter:dev check --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-whisky-hunter:dev discover --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-whisky-hunter:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
```
## Testing

#### 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 docker

### Using gradle to run tests
All commands should be run from airbyte project root.
To run unit tests:
```
./gradlew :airbyte-integrations:connectors:source-whisky-hunter:unitTest
```
To run acceptance and custom integration tests:
```
./gradlew :airbyte-integrations:connectors:source-whisky-hunter:integrationTest
```

## Dependency Management
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,3 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See [Source Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/source-acceptance-tests-reference)
# for more information about how to configure these tests
connector_image: airbyte/source-whisky-hunter:dev
tests:
spec:
- spec_path: "source_whisky_hunter/spec.yaml"
connection:
- config_path: "secrets/config.json"
status: "succeed"
discovery:
- config_path: "secrets/config.json"
basic_read:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
empty_streams: []
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

20 changes: 20 additions & 0 deletions airbyte-integrations/connectors/source-whisky-hunter/bootstrap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Core streams

[Whisky Hunter](https://whiskyhunter.net/api/) is an API. Connector is implemented with the [Airbyte Low-Code CDK](https://docs.airbyte.com/connector-development/config-based/low-code-cdk-overview).

Connector supports the following three streams:
* `auctions_data`
* Provides stats about specific auctions.
* `auctions_info`
* Provides information and metadata about recurring and one-off auctions.
* `distilleries_info`
* Provides information about distilleries.

Rate Limiting:
* No published rate limit.

Authentication and Permissions:
* No authentication.


See [this](https://docs.airbyte.io/integrations/sources/whisky-hunter) link for the connector docs.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id 'airbyte-python'
id 'airbyte-docker'
id 'airbyte-source-acceptance-test'
}

airbytePython {
moduleDirectory 'source_whisky_hunter'
}
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
@@ -0,0 +1,14 @@
#
# Copyright (c) 2022 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
Loading

0 comments on commit c617d64

Please sign in to comment.