Skip to content

Commit 7776dbe

Browse files
authored
🎉 Source Zendesk Sunshine: support oauth (#7976)
* add oauth support * bump version * add java part * change date format * change spec * upd invalid_configs * bump version and format
1 parent ee26499 commit 7776dbe

File tree

13 files changed

+492
-36
lines changed

13 files changed

+492
-36
lines changed

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@
753753
- name: Zendesk Sunshine
754754
sourceDefinitionId: 325e0640-e7b3-4e24-b823-3361008f603f
755755
dockerRepository: airbyte/source-zendesk-sunshine
756-
dockerImageTag: 0.1.0
756+
dockerImageTag: 0.1.1
757757
documentationUrl: https://docs.airbyte.io/integrations/sources/zendesk-sunshine
758758
icon: zendesk.svg
759759
sourceType: api

airbyte-config/init/src/main/resources/seed/source_specs.yaml

Lines changed: 112 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7553,40 +7553,137 @@
75537553
path_in_connector_config:
75547554
- "credentials"
75557555
- "client_secret"
7556-
- dockerImage: "airbyte/source-zendesk-sunshine:0.1.0"
7556+
- dockerImage: "airbyte/source-zendesk-sunshine:0.1.1"
75577557
spec:
75587558
documentationUrl: "https://docs.airbyte.io/integrations/sources/zendesk_sunshine"
75597559
connectionSpecification:
75607560
$schema: "http://json-schema.org/draft-07/schema#"
75617561
title: "Zendesk Sunshine Spec"
75627562
type: "object"
75637563
required:
7564-
- "api_token"
7565-
- "email"
75667564
- "start_date"
75677565
- "subdomain"
7568-
additionalProperties: false
7566+
additionalProperties: true
75697567
properties:
7570-
api_token:
7571-
type: "string"
7572-
airbyte_secret: true
7573-
description: "API Token. See the <a href=\"https://docs.airbyte.io/integrations/sources/zendesk_sunshine\"\
7574-
>docs</a> for information on how to generate this key."
7575-
email:
7576-
type: "string"
7577-
description: "The user email for your Zendesk account"
75787568
subdomain:
7569+
title: "Subdomain"
75797570
type: "string"
7580-
description: "The subdomain for your Zendesk Account"
7571+
description: "The subdomain for your Zendesk Account."
75817572
start_date:
75827573
title: "Start Date"
75837574
type: "string"
7584-
description: "The date from which you'd like to replicate the data"
7575+
description: "The date from which you'd like to replicate data for Zendesk\
7576+
\ Sunshine API, in the format YYYY-MM-DDT00:00:00Z."
75857577
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
7586-
examples: "2021-01-01T00:00:00.000000Z"
7578+
examples:
7579+
- "2021-01-01T00:00:00Z"
7580+
credentials:
7581+
title: "Authorization Method"
7582+
type: "object"
7583+
oneOf:
7584+
- type: "object"
7585+
title: "OAuth2.0"
7586+
required:
7587+
- "auth_method"
7588+
- "client_id"
7589+
- "client_secret"
7590+
- "access_token"
7591+
properties:
7592+
auth_method:
7593+
type: "string"
7594+
const: "oauth2.0"
7595+
enum:
7596+
- "oauth2.0"
7597+
default: "oauth2.0"
7598+
order: 0
7599+
client_id:
7600+
type: "string"
7601+
title: "Client ID"
7602+
description: "The Client ID of your OAuth application."
7603+
airbyte_secret: true
7604+
client_secret:
7605+
type: "string"
7606+
title: "Client Secret"
7607+
description: "The Client Secret of your OAuth application."
7608+
airbyte_secret: true
7609+
access_token:
7610+
type: "string"
7611+
title: "Access Token"
7612+
description: "Long-term access Token for making authenticated requests."
7613+
airbyte_secret: true
7614+
- type: "object"
7615+
title: "API Token"
7616+
required:
7617+
- "auth_method"
7618+
- "api_token"
7619+
- "email"
7620+
properties:
7621+
auth_method:
7622+
type: "string"
7623+
const: "api_token"
7624+
enum:
7625+
- "api_token"
7626+
default: "api_token"
7627+
order: 1
7628+
api_token:
7629+
type: "string"
7630+
title: "API Token"
7631+
description: "API Token. See the <a href=\"https://docs.airbyte.io/integrations/sources/zendesk_sunshine\"\
7632+
>docs</a> for information on how to generate this key."
7633+
airbyte_secret: true
7634+
email:
7635+
type: "string"
7636+
title: "Email"
7637+
description: "The user email for your Zendesk account"
75877638
supportsNormalization: false
75887639
supportsDBT: false
75897640
supported_destination_sync_modes: []
7641+
advanced_auth:
7642+
auth_flow_type: "oauth2.0"
7643+
predicate_key:
7644+
- "credentials"
7645+
- "auth_method"
7646+
predicate_value: "oauth2.0"
7647+
oauth_config_specification:
7648+
oauth_user_input_from_connector_config_specification:
7649+
type: "object"
7650+
additionalProperties: false
7651+
properties:
7652+
subdomain:
7653+
type: "string"
7654+
path_in_connector_config:
7655+
- "subdomain"
7656+
complete_oauth_output_specification:
7657+
type: "object"
7658+
additionalProperties: false
7659+
properties:
7660+
access_token:
7661+
type: "string"
7662+
path_in_connector_config:
7663+
- "credentials"
7664+
- "access_token"
7665+
complete_oauth_server_input_specification:
7666+
type: "object"
7667+
additionalProperties: false
7668+
properties:
7669+
client_id:
7670+
type: "string"
7671+
client_secret:
7672+
type: "string"
7673+
complete_oauth_server_output_specification:
7674+
type: "object"
7675+
additionalProperties: false
7676+
properties:
7677+
client_id:
7678+
type: "string"
7679+
path_in_connector_config:
7680+
- "credentials"
7681+
- "client_id"
7682+
client_secret:
7683+
type: "string"
7684+
path_in_connector_config:
7685+
- "credentials"
7686+
- "client_secret"
75907687
- dockerImage: "airbyte/source-zendesk-support:0.1.11"
75917688
spec:
75927689
documentationUrl: "https://docs.airbyte.io/integrations/sources/zendesk-support"

airbyte-integrations/connectors/source-zendesk-sunshine/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ RUN pip install .
1212
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1313
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1414

15-
LABEL io.airbyte.version=0.1.0
15+
LABEL io.airbyte.version=0.1.1
1616
LABEL io.airbyte.name=airbyte/source-zendesk-sunshine

airbyte-integrations/connectors/source-zendesk-sunshine/acceptance-test-config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,25 @@ tests:
77
connection:
88
- config_path: "secrets/config.json"
99
status: "succeed"
10+
- config_path: "secrets/config_oauth.json"
11+
status: "succeed"
12+
- config_path: "secrets/config_api_token.json"
13+
status: "succeed"
1014
- config_path: "integration_tests/invalid_config.json"
1115
status: "failed"
16+
- config_path: "integration_tests/invalid_config_api_token.json"
17+
status: "failed"
18+
- config_path: "integration_tests/invalid_config_oauth.json"
19+
status: "failed"
1220
discovery:
1321
- config_path: "secrets/config.json"
1422
basic_read:
1523
- config_path: "secrets/config.json"
1624
configured_catalog_path: "integration_tests/configured_catalog.json"
25+
- config_path: "secrets/config_api_token.json"
26+
configured_catalog_path: "integration_tests/configured_catalog.json"
27+
- config_path: "secrets/config_oauth.json"
28+
configured_catalog_path: "integration_tests/configured_catalog.json"
1729
# incremental: # complex state ( {parent_id: {cur_field: value}} still not supported )
1830
# - config_path: "secrets/config.json"
1931
# configured_catalog_path: "integration_tests/configured_catalog.json"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"credentials": {
3+
"auth_method": "api_token",
4+
"email": "[email protected]",
5+
"api_token": "fgfgvf ghnbvg hnghbvnhbvnvbn"
6+
},
7+
"subdomain": "d3v-airbyte",
8+
"start_date": "2020-01-01T00:00:00Z"
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"credentials": {
3+
"auth_method": "oauth2.0",
4+
"client_id": "some_client_id",
5+
"client_secret": "some_client_secret",
6+
"access_token": "some_access_token"
7+
},
8+
"subdomain": "d3v-airbyte",
9+
"start_date": "2020-01-01T00:00:00Z"
10+
}

airbyte-integrations/connectors/source-zendesk-sunshine/source_zendesk_sunshine/source.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
import base64
7-
from typing import Any, List, Mapping, Tuple
7+
from typing import Any, List, Mapping, Tuple, Union
88

99
import pendulum
1010
from airbyte_cdk.logger import AirbyteLogger
@@ -23,11 +23,24 @@ def __init__(self, auth: Tuple[str, str], auth_method: str = "Basic", **kwargs):
2323
super().__init__(token=b64_encoded, auth_method=auth_method, **kwargs)
2424

2525

26+
class ZendeskSunshineAuthenticator:
27+
"""Provides the authentication capabilities for both old and new methods."""
28+
29+
@staticmethod
30+
def get_auth(config: Mapping[str, Any]) -> Union[Base64HttpAuthenticator, TokenAuthenticator]:
31+
credentials = config.get("credentials", {})
32+
token = config.get("api_token") or credentials.get("api_token")
33+
email = config.get("email") or credentials.get("email")
34+
if email and token:
35+
return Base64HttpAuthenticator(auth=(f"{email}/token", token))
36+
return TokenAuthenticator(token=credentials["access_token"])
37+
38+
2639
class SourceZendeskSunshine(AbstractSource):
2740
def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> Tuple[bool, Any]:
2841
try:
2942
pendulum.parse(config["start_date"], strict=True)
30-
authenticator = Base64HttpAuthenticator(auth=(f'{config["email"]}/token', config["api_token"]))
43+
authenticator = ZendeskSunshineAuthenticator.get_auth(config)
3144
stream = Limits(authenticator=authenticator, subdomain=config["subdomain"], start_date=pendulum.parse(config["start_date"]))
3245
records = stream.read_records(sync_mode=SyncMode.full_refresh)
3346
next(records)
@@ -47,7 +60,7 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
4760
After this time is passed we have no data. It will require permanent population, to pass
4861
the test criteria `stream should contain at least 1 record)
4962
"""
50-
authenticator = Base64HttpAuthenticator(auth=(f'{config["email"]}/token', config["api_token"]))
63+
authenticator = ZendeskSunshineAuthenticator.get_auth(config)
5164
args = {"authenticator": authenticator, "subdomain": config["subdomain"], "start_date": config["start_date"]}
5265
return [
5366
ObjectTypes(**args),

0 commit comments

Comments
 (0)