Skip to content

Commit

Permalink
feat(source-hardcoded-records): add new source (#42434)
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Inzhyyants <artem.inzhyyants@gmail.com>
  • Loading branch information
artem1205 authored Jul 26, 2024
1 parent dd5ba24 commit 046c4b7
Show file tree
Hide file tree
Showing 22 changed files with 2,360 additions and 0 deletions.
104 changes: 104 additions & 0 deletions airbyte-integrations/connectors/source-hardcoded-records/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Hardcoded Records source connector

This is the repository for the Hardcoded Records source connector, written in Python.
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.com/integrations/sources/hardcoded-records).

## Local development

### Prerequisites

- Python (~=3.9)
- Poetry (~=1.7) - installation instructions [here](https://python-poetry.org/docs/#installation)

### Installing the connector

From this connector directory, run:

```bash
poetry install --with dev
```

### Create credentials

**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.com/integrations/sources/hardcoded-records)
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_hardcoded_records/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 `sample_files/sample_config.json` for a sample config file.

### Locally running the connector

```
poetry run source-hardcoded-records spec
poetry run source-hardcoded-records check --config secrets/config.json
poetry run source-hardcoded-records discover --config secrets/config.json
poetry run source-hardcoded-records read --config secrets/config.json --catalog sample_files/configured_catalog.json
```

### Running unit tests

To run unit tests locally, from the connector directory run:

```
poetry run pytest unit_tests
```

### Building the docker image

1. Install [`airbyte-ci`](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md)
2. Run the following command to build the docker image:

```bash
airbyte-ci connectors --name=source-hardcoded-records build
```

An image will be available on your host with the tag `airbyte/source-hardcoded-records:dev`.

### Running as a docker container

Then run any of the connector commands as follows:

```
docker run --rm airbyte/source-hardcoded-records:dev spec
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-hardcoded-records:dev check --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-hardcoded-records:dev discover --config /secrets/config.json
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-hardcoded-records:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
```

### Running our CI test suite

You can run our full test suite locally using [`airbyte-ci`](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md):

```bash
airbyte-ci connectors --name=source-hardcoded-records test
```

### Customizing acceptance Tests

Customize `acceptance-test-config.yml` file to configure acceptance 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.

### Dependency Management

All of your dependencies should be managed via Poetry.
To add a new dependency, run:

```bash
poetry add <package-name>
```

Please commit the changes to `pyproject.toml` and `poetry.lock` files.

## 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 our test suite: `airbyte-ci connectors --name=source-hardcoded-records test`
2. Bump the connector version (please follow [semantic versioning for connectors](https://docs.airbyte.com/contributing-to-airbyte/resources/pull-requests-handbook/#semantic-versioning-for-connectors)):
- bump the `dockerImageTag` value in in `metadata.yaml`
- bump the `version` value in `pyproject.toml`
3. Make sure the `metadata.yaml` content is up to date.
4. Make sure the connector documentation and its changelog is up to date (`docs/integrations/sources/hardcoded-records.md`).
5. Create a Pull Request: use [our PR naming conventions](https://docs.airbyte.com/contributing-to-airbyte/resources/pull-requests-handbook/#pull-request-title-convention).
6. Pat yourself on the back for being an awesome contributor.
7. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.
8. Once your PR is merged, the new version of the connector will be automatically published to Docker Hub and our connector registry.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
connector_image: airbyte/source-hardcoded-records:dev
test_strictness_level: high
acceptance_tests:
spec:
tests:
- spec_path: source_hardcoded_records/spec.json
connection:
tests:
- config_path: secrets/config.json
status: succeed
- config_path: integration_tests/invalid_config.json
status: failed
discovery:
tests:
- config_path: secrets/config.json
basic_read:
tests:
- config_path: secrets/config.json
expect_records:
path: integration_tests/expected_records.jsonl
full_refresh:
tests:
- config_path: secrets/config.json
configured_catalog_path: integration_tests/configured_catalog.json
incremental:
bypass_reason: "Incremental is not supported"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#


import pytest

pytest_plugins = ("connector_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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"streams": [
{
"stream": {
"name": "customers",
"json_schema": {},
"supported_sync_modes": ["incremental", "full_refresh"],
"source_defined_cursor": true,
"default_cursor_field": ["updated_at"]
},
"sync_mode": "full_refresh",
"destination_sync_mode": "overwrite"
},
{
"stream": {
"name": "products",
"json_schema": {},
"supported_sync_modes": ["incremental", "full_refresh"],
"source_defined_cursor": true,
"default_cursor_field": ["updated_at"]
},
"sync_mode": "full_refresh",
"destination_sync_mode": "overwrite"
},
{
"stream": {
"name": "dummy_fields",
"json_schema": {},
"supported_sync_modes": ["incremental", "full_refresh"],
"source_defined_cursor": true,
"default_cursor_field": ["updated_at"]
},
"sync_mode": "full_refresh",
"destination_sync_mode": "overwrite"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"stream":"customers","data":{"id":6569096478909,"email":"test@test.com","created_at":"2023-04-13T02:30:04-07:00","updated_at":"2023-04-24T06:53:48-07:00","first_name":"New Test","last_name":"Customer","orders_count":0,"state":"disabled","total_spent":0.0,"last_order_id":null,"note":"updated_mon_24.04.2023","verified_email":true,"multipass_identifier":null,"tax_exempt":false,"tags":"","last_order_name":null,"currency":"USD","phone":"+380639379992","addresses":[{"id":8092523135165,"customer_id":6569096478909,"first_name":"New Test","last_name":"Customer","company":"Test Company","address1":"My Best Accent","address2":"","city":"Fair Lawn","province":"New Jersey","country":"United States","zip":"07410","phone":"","name":"New Test Customer","province_code":"NJ","country_code":"US","country_name":"United States","default":true}],"accepts_marketing":true,"accepts_marketing_updated_at":"2023-04-13T02:30:04-07:00","marketing_opt_in_level":"single_opt_in","tax_exemptions":"[]","email_marketing_consent":{"state":"subscribed","opt_in_level":"single_opt_in","consent_updated_at":"2023-04-13T02:30:04-07:00"},"sms_marketing_consent":{"state":"not_subscribed","opt_in_level":"single_opt_in","consent_updated_at":null,"consent_collected_from":"SHOPIFY"},"admin_graphql_api_id":"gid://shopify/Customer/6569096478909","default_address":{"id":8092523135165,"customer_id":6569096478909,"first_name":"New Test","last_name":"Customer","company":"Test Company","address1":"My Best Accent","address2":"","city":"Fair Lawn","province":"New Jersey","country":"United States","zip":"07410","phone":"","name":"New Test Customer","province_code":"NJ","country_code":"US","country_name":"United States","default":true},"shop_url":"airbyte-integration-test"},"emitted_at":1721727132543}
{"stream":"products","data":{"id":1,"make":"Mazda","model":"MX-5","year":2008,"price":2869,"created_at":"2022-02-01T17:02:19+00:00","updated_at":"2022-11-01T17:02:19+00:00"},"emitted_at":1721727132544}
{"stream":"dummy_fields","data":{"field1":"valuevaluevaluevaluevalue1","field2":"valuevaluevaluevaluevalue1","field3":"valuevaluevaluevaluevalue1","field4":"valuevaluevaluevaluevalue1","field5":"valuevaluevaluevaluevalue1"},"emitted_at":1721895471355}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"count": -1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"count": 100
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#


from source_hardcoded_records.run import run

if __name__ == "__main__":
run()
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
data:
ab_internal:
ql: 300
sl: 100
allowedHosts:
hosts: []
connectorBuildOptions:
baseImage: docker.io/airbyte/python-connector-base:2.0.0@sha256:c44839ba84406116e8ba68722a0f30e8f6e7056c726f447681bb9e9ece8bd916
connectorSubtype: api
connectorType: source
definitionId: 084124ab-22db-4019-b36d-630418541bf7
dockerImageTag: 0.0.1
dockerRepository: airbyte/source-hardcoded-records
documentationUrl: https://docs.airbyte.com/integrations/sources/hardcoded-records
githubIssueLabel: source-hardcoded-records
icon: faker.svg
license: MIT
name: Hardcoded Records
registries:
cloud:
enabled: true
oss:
enabled: true
releaseStage: beta
remoteRegistries:
pypi:
enabled: true
packageName: airbyte-source-hardcoded-records
suggestedStreams:
streams:
- countries
- orders
supportLevel: community
tags:
- language:python
- cdk:python
connectorTestSuitesOptions:
- suite: acceptanceTests
testSecrets:
- name: SECRET_SOURCE-HARDCODED-RECORDS_CREDS
fileName: config.json
secretStore:
type: GSM
alias: airbyte-connector-testing-secret-store
metadataSpecVersion: "1.0"
Loading

0 comments on commit 046c4b7

Please sign in to comment.