Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Add Braintree source connector #5362

Merged
merged 6 commits into from
Aug 19, 2021
Merged

Conversation

avida
Copy link
Contributor

@avida avida commented Aug 12, 2021

What

Resolves #5236 issues

How

Describe the solution

Recommended reading order

  1. x.java
  2. y.python

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions
  • Connector added to connector index like described here

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here

Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions
  • Connector version bumped like described here

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here

Connector Generator

  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed.

@github-actions github-actions bot added the area/connectors Connector related issues label Aug 12, 2021
@avida
Copy link
Contributor Author

avida commented Aug 12, 2021

/test connector=source-braintree

🕑 source-braintree https://github.com/airbytehq/airbyte/actions/runs/1123026558
❌ source-braintree https://github.com/airbytehq/airbyte/actions/runs/1123026558

@jrhizor jrhizor temporarily deployed to more-secrets August 12, 2021 07:36 Inactive
@avida avida force-pushed the drezchykov/5236-braintree-source branch from 2a43333 to fe956f1 Compare August 12, 2021 08:21
@avida
Copy link
Contributor Author

avida commented Aug 12, 2021

/test connector=source-braintree

🕑 source-braintree https://github.com/airbytehq/airbyte/actions/runs/1123158004
✅ source-braintree https://github.com/airbytehq/airbyte/actions/runs/1123158004

@jrhizor jrhizor temporarily deployed to more-secrets August 12, 2021 08:24 Inactive
@avida avida force-pushed the drezchykov/5236-braintree-source branch from fe956f1 to 11508d7 Compare August 13, 2021 05:57
@github-actions github-actions bot added the area/documentation Improvements or additions to documentation label Aug 13, 2021
@avida avida force-pushed the drezchykov/5236-braintree-source branch 5 times, most recently from ed6132d to f277359 Compare August 16, 2021 13:17
@avida
Copy link
Contributor Author

avida commented Aug 16, 2021

/test connector=source-braintree

🕑 source-braintree https://github.com/airbytehq/airbyte/actions/runs/1135600523
✅ source-braintree https://github.com/airbytehq/airbyte/actions/runs/1135600523

@jrhizor jrhizor temporarily deployed to more-secrets August 16, 2021 13:20 Inactive
Copy link
Contributor

@Zirochkaa Zirochkaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few comments

@avida avida requested a review from Zirochkaa August 17, 2021 11:22
@avida
Copy link
Contributor Author

avida commented Aug 17, 2021

/test connector=source-braintree

🕑 source-braintree https://github.com/airbytehq/airbyte/actions/runs/1139056884
✅ source-braintree https://github.com/airbytehq/airbyte/actions/runs/1139056884

@jrhizor jrhizor temporarily deployed to more-secrets August 17, 2021 11:26 Inactive
@avida avida force-pushed the drezchykov/5236-braintree-source branch from b9dd023 to 3e8f0b7 Compare August 17, 2021 12:01
@avida avida requested a review from sherifnada August 17, 2021 12:03
@@ -0,0 +1,7 @@
{
"sourceDefinitionId": "63cea06f-1c75-458d-88fe-ad48c7cb27fd",
"name": "Braintree",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add "Deprecated" to the old one (for json and yml files)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"stream": {
"name": "customer_stream",
"json_schema": {},
"supported_sync_modes": ["full_refresh"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I look at the code and don't understand why your customer_stream stream can be Incremental, but in the catalog you indicate it simply as full_refresh?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it ignored by acceptance test anyway? What point of those changes to integration_tests/configured_catalog.json ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

"json_schema": {},
"supported_sync_modes": ["full_refresh"],
"source_defined_cursor": false,
"default_cursor_field": ["column_name"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I don't see the source_defined_primary_key field

Comment on lines 19 to 20
"source_defined_cursor": false,
"default_cursor_field": ["column_name"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is unnecessary

item = self.get_json_from_resource(item)
item = self.model(**item)
yield item.dict(exclude_unset=True)
yield from []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this line - the code should complete without it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment on lines 104 to 136
@backoff.on_exception(
backoff.expo,
(
braintree.exceptions.GatewayTimeoutError,
braintree.exceptions.RequestTimeoutError,
braintree.exceptions.ServerError,
braintree.exceptions.ServiceUnavailableError,
braintree.exceptions.TooManyRequestsError,
),
max_tries=5,
)
def read_records(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is correct.
I think that we should not wrap the whole generator in backoff, but a separate function that requests data once.
In this case, we exclude the likelihood that if an error pops up at the 10th iteration, then we will not run the read_records function with the initial values, thereby getting duplicate records.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, fixed

docs/SUMMARY.md Outdated
Comment on lines 36 to 39
* [Braintree](integrations/sources/braintree.md)
* [Bing Ads](integrations/sources/bing-ads.md)
* [BigQuery](integrations/sources/bigquery.md)
* [Braintree (standalone)](integrations/sources/braintree-standalone.md)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* [Braintree](integrations/sources/braintree.md)
* [Bing Ads](integrations/sources/bing-ads.md)
* [BigQuery](integrations/sources/bigquery.md)
* [Braintree (standalone)](integrations/sources/braintree-standalone.md)
* [Braintree (Deprecated)](integrations/sources/braintree.md)
* [Bing Ads](integrations/sources/bing-ads.md)
* [BigQuery](integrations/sources/bigquery.md)
* [Braintree](integrations/sources/braintree-standalone.md)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

@yevhenii-ldv yevhenii-ldv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments

@avida avida requested a review from yevhenii-ldv August 18, 2021 07:46
@avida
Copy link
Contributor Author

avida commented Aug 18, 2021

/test connector=source-braintree

🕑 source-braintree https://github.com/airbytehq/airbyte/actions/runs/1142273098
✅ source-braintree https://github.com/airbytehq/airbyte/actions/runs/1142273098

@jrhizor jrhizor temporarily deployed to more-secrets August 18, 2021 07:49 Inactive
Copy link
Contributor

@yevhenii-ldv yevhenii-ldv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@sherifnada sherifnada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done with using pydantic for the models. It's super easy to read. Was it easier to use than JSON/would you prefer that we do things this way going forward?

We should remove the previous singer connector from the YAMLs, jsons, etc... (not just rename it). We should make things as simple as possible for the user, who probably doesn't care if something is based on singer or airbyte, they just want data from braintree

@@ -168,7 +168,7 @@
documentationUrl: https://docs.airbyte.io/integrations/sources/freshdesk
icon: freshdesk.svg
- sourceDefinitionId: 396e4ca3-8a97-4b85-aa4e-c9d8c2d5f992
name: Braintree
name: Braintree (Deprecated)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should delete the singer one

configured_catalog_path: "integration_tests/configured_catalog.json"
empty_streams: ["subscription_stream"]
expect_records:
path: "integration_tests/expected_records.txt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job adding expected records!



class AllOptional(pydantic.main.ModelMetaclass):
def __new__(self, name, bases, namespaces, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a docstring to explain why we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

VenmoAccount,
VisaCheckoutCard,
)
from .common import CatalogModel as BaseModel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think renaming it as basemodel is a little misleading because we're not using basemodel, we're using a subclass of it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

name="Merchant ID",
description='<a href="https://docs.airbyte.io/integrations/sources/braintree">Merchant ID</a> is the unique identifier for entire gateway account.',
)
public_key: str = Field(name="Public key", description="This is your user-specific public identifier for Braintree.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add the title field to each of these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would automatically be added by pydantic model generator:

{
  "type": "SPEC",
  "spec": {
    "documentationUrl": "https://docs.airbyte.io/integrations/sources/braintree",
    "connectionSpecification": {
      "title": "Braintree Spec",
      "type": "object",
      "properties": {
        "merchant_id": {
          "title": "Merchant Id",
          "description": "<a href=\"https://docs.airbyte.io/integrations/sources/braintree\">Merchant ID</a> is the unique identifier for entire gateway account.",
          "name": "Merchant ID",
          "type": "string"
        },
        "public_key": {
          "title": "Public Key",
          "description": "This is your user-specific public identifier for Braintree.",
          "name": "Public key",
          "type": "string"
        },
        "private_key": {
          "title": "Private Key",
          "description": "This is your user-specific private identifier.",
          "name": "Private Key",
          "airbyte_secret": true,
          "type": "string"
        },
        "start_date": {
          "title": "Start Date",
          "description": "The date from which you'd like to replicate data for Braintree API for UTC timezone, All data generated after this date will be replicated.",
          "name": "Start date",
          "examples": [
            "2020",
            "2020-12-30",
            "2020-11-22 20:20:05"
          ],
          "type": "string",
          "format": "date-time"
        },
        "environment": {
          "$ref": "#/definitions/Environment"
        }
      },
      "required": [
        "merchant_id",
        "public_key",
        "private_key",
        "environment"
      ],
      "definitions": {
        "Environment": {
          "title": "Environment",
          "description": "An enumeration.",
          "enum": [
            "Development",
            "Sandbox",
            "Qa",
            "Production"
          ],
          "type": "string"
        }
      }
    }
  }
}



@responses.activate
def test_customers_stream(test_config):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome use of this library. Nicely done!

from source_braintree.spec import BraintreeConfig


class BraintreeStream(Stream):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should declare as ABC since it declares abstract methods

Suggested change
class BraintreeStream(Stream):
class BraintreeStream(Stream, ABC):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@avida
Copy link
Contributor Author

avida commented Aug 19, 2021

/test connector=source-braintree

🕑 source-braintree https://github.com/airbytehq/airbyte/actions/runs/1146114860
✅ source-braintree https://github.com/airbytehq/airbyte/actions/runs/1146114860

@jrhizor jrhizor temporarily deployed to more-secrets August 19, 2021 07:51 Inactive
@avida
Copy link
Contributor Author

avida commented Aug 19, 2021

Nicely done with using pydantic for the models. It's super easy to read. Was it easier to use than JSON/would you prefer that we do things this way going forward?

Yes, it was a lot more easy than JSON, I used pydantic models for Amazon Ads and Braintree and was happy about it, would like to use it instead of jsonschema models.

@avida
Copy link
Contributor Author

avida commented Aug 19, 2021

/publish connector=source-braintree

❌ source-braintree https://github.com/airbytehq/airbyte/actions/runs/1146133843

@avida avida force-pushed the drezchykov/5236-braintree-source branch from c55ce76 to 2fc1619 Compare August 19, 2021 07:58
@avida avida force-pushed the drezchykov/5236-braintree-source branch from 2fc1619 to 5e4f747 Compare August 19, 2021 08:00
@avida
Copy link
Contributor Author

avida commented Aug 19, 2021

/publish connector=source-braintree

❌ source-braintree https://github.com/airbytehq/airbyte/actions/runs/1146149498

@jrhizor jrhizor temporarily deployed to more-secrets August 19, 2021 08:04 Inactive
@avida
Copy link
Contributor Author

avida commented Aug 19, 2021

/publish connector=connectors/source-braintree

🕑 connectors/source-braintree https://github.com/airbytehq/airbyte/actions/runs/1146258683
✅ connectors/source-braintree https://github.com/airbytehq/airbyte/actions/runs/1146258683

@jrhizor jrhizor temporarily deployed to more-secrets August 19, 2021 08:40 Inactive
@avida avida merged commit 5560df7 into master Aug 19, 2021
@avida avida deleted the drezchykov/5236-braintree-source branch August 19, 2021 08:49
@avida avida changed the title Add Braintree source connector 🎉 Add Braintree source connector Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues area/documentation Improvements or additions to documentation connectors/source/braintree connectors/sources-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New source: airbyte-native braintree
6 participants