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

🎉 Source Zuora: Add OAuth support for Airbyte Cloud, Migrated to new CI Sandbox #6575

Merged
merged 10 commits into from
Oct 6, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"sourceDefinitionId": "3dc3037c-5ce8-4661-adc2-f7a9e3c5ece5",
"name": "Zuora",
"dockerRepository": "airbyte/source-zuora",
"dockerImageTag": "0.1.0",
"dockerImageTag": "0.1.1",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/zuora"
}
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@
- sourceDefinitionId: 3dc3037c-5ce8-4661-adc2-f7a9e3c5ece5
name: Zuora
dockerRepository: airbyte/source-zuora
dockerImageTag: 0.1.0
dockerImageTag: 0.1.1
documentationUrl: https://docs.airbyte.io/integrations/sources/zuora
sourceType: api
- sourceDefinitionId: 47f25999-dd5e-4636-8c39-e7cea2453331
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
ZuoraSubmitJob,
)
from source_zuora.zuora_auth import ZuoraAuthenticator


# Method to get url_base from config input
def get_url_base(is_sandbox: bool = False) -> str:
url_base = "https://rest.zuora.com"
if is_sandbox:
url_base = "https://rest.apisandbox.zuora.com"
return url_base
from source_zuora.zuora_endpoint import get_url_base


def get_config(config_path: str) -> Mapping[str, Any]:
Expand All @@ -37,7 +30,7 @@ def client(config: Dict):
"""
Create client by extending config dict with authenticator and url_base
"""
url_base = get_url_base(config["is_sandbox"])
url_base = get_url_base(config["tenant_endpoint"])
authenticator = ZuoraAuthenticator(
token_refresh_endpoint=f"{url_base}/oauth/token",
client_id=config["client_id"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@
from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.streams.http import HttpStream

from .zuora_endpoint import get_url_base
from .zuora_auth import ZuoraAuthenticator
from .zuora_errors import ZOQLQueryCannotProcessObject, ZOQLQueryFailed, ZOQLQueryFieldCannotResolve


def get_url_base(is_sandbox: bool = False) -> str:
url_base = "https://rest.zuora.com"
if is_sandbox:
url_base = "https://rest.apisandbox.zuora.com"
return url_base


class ZuoraStream(HttpStream, ABC):
"""
Parent class for all other classes, except of SourceZuora.
Expand Down Expand Up @@ -449,7 +443,7 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) ->
"""

# Define the endpoint from user's config
url_base = get_url_base(config["is_sandbox"])
url_base = get_url_base(config["tenant_endpoint"])
try:
ZuoraAuthenticator(
token_refresh_endpoint=f"{url_base}/oauth/token",
Expand All @@ -467,7 +461,7 @@ def streams(self, config: Mapping[str, Any]) -> List[ZuoraStream]:
Defining streams to run by building stream classes dynamically.
"""
# Define the endpoint from user's config
url_base = get_url_base(config["is_sandbox"])
url_base = get_url_base(config["tenant_endpoint"])

# Get Authotization Header with Access Token
authenticator = ZuoraAuthenticator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Zuora Connector Configuration",
"type": "object",
"required": ["start_date", "client_id", "client_secret"],
"required": ["start_date","client_id","client_secret","tenant_endpoint"],
"additionalProperties": false,
"properties": {
"start_date": {
Expand All @@ -15,7 +15,7 @@
"window_in_days": {
"type": "integer",
"description": "The amount of days for each data-chunk begining from start_date. Bigger the value - faster the fetch. (Min=1, as for a Day; Max=364, as for a Year).",
"examples": [30, 60, 90, 120, 200, 364],
"examples": [30,60,90,120,200,364],
"default": 90
},
"client_id": {
Expand All @@ -28,10 +28,49 @@
"description": "Client Secret",
"airbyte_secret": true
},
"is_sandbox": {
"type": "boolean",
"description": "Defines whether use the SANDBOX or PRODUCTION environment.",
"default": false
"tenant_endpoint": {
"title": "Tenant Endpoint Type",
"type": "object",
"description": "Please choose the right endpoint where your Tenant is located. More info by this <a href=\"https://www.zuora.com/developer/api-reference/#section/Introduction/Access-to-the-API\">Link</a>",
"oneOf": [
{
"title": "Production",
"description": "Choose between production endpoints",
"required": ["production"],
"properties": {
"production": {
"title": "Choose between production endpoints",
"type": "string",
"enum": ["US Production","US Cloud Production","EU Production"]
}
}
},
{
bazarnov marked this conversation as resolved.
Show resolved Hide resolved
"title": "Sandbox",
"description": "Choose between sandbox endpoints",
"required": ["sandbox"],
"properties": {
"sandbox": {
"title": "Choose between sandbox endpoints",
"type": "string",
"enum": ["US API Sandbox","US Cloud API Sandbox","US Central Sandbox","EU API Sandbox","EU Central Sandbox"]
}
bazarnov marked this conversation as resolved.
Show resolved Hide resolved
}
},
{
"title": "Custom",
"description": "Enter the URL link for your tenant.",
"required": ["custom"],
"properties": {
"custom": {
"title": "Enter your custom tenant URL",
"type": "string",
"description": "Specifies the URL for Zuora Tenant",
"examples": ["https://my.zuora.tenant.com/"]
}
}
}
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing import Any, Mapping

from airbyte_cdk.sources.streams.http.auth.oauth import Oauth2Authenticator
from airbyte_cdk.sources.streams.http.requests_native_auth import Oauth2Authenticator


class ZuoraAuthenticator(Oauth2Authenticator):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#


from typing import Dict

ZUORA_TENANT_ENDPOINT_MAP: Dict = {
"US Production": "https://rest.zuora.com",
"US API Sandbox": "https://rest.apisandbox.zuora.com",
"US Performance Test": "https://rest.pt1.zuora.com",
"US Cloud Production": "https://rest.na.zuora.com",
"US Cloud API Sandbox": "https://rest.sandbox.na.zuora.com",
"US Central Sandbox": "https://rest.test.zuora.com",
"EU Production": "https://rest.eu.zuora.com",
"EU API Sandbox": "https://rest.sandbox.eu.zuora.com",
"EU Central Sandbox": "https://rest.test.eu.zuora.com",
}

def get_url_base(tenant_endpoint: str) -> str:
""" Define the URL Base from user's input with respect to the ZUORA_TENANT_ENDPOINT_MAP """

# map the tenant_type & endpoint from user's input
tenant_type, endpoint = list(tenant_endpoint.items())[0]
bazarnov marked this conversation as resolved.
Show resolved Hide resolved
if tenant_type == "custom":
# case with custom tenant URL should return the entered URL as url_base
url_base = endpoint
else:
# all other cases should be handled by the tenant map
url_base = ZUORA_TENANT_ENDPOINT_MAP.get(endpoint)
return url_base
3 changes: 2 additions & 1 deletion docs/integrations/sources/zuora.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ For more information visit [Create an API User page](https://knowledgecenter.zuo
## Changelog

| Version | Date | Pull Request | Subject |
| :------ | :-------- | :-------- | :------ |
| :------ | :------
| 0.1.1 | 2021-10-01 | [6575](https://github.com/airbytehq/airbyte/pull/6575) | Added OAuth support for Airbyte Cloud |
| 0.1.0 | 2021-08-01 | [4661](https://github.com/airbytehq/airbyte/pull/4661) | Initial release of Native Zuora connector for Airbyte |