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 Zendesk-Chat: add oauth flow support #7313

Merged
merged 29 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0eb073f
added oauth support
bazarnov Oct 20, 2021
5d3077d
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Oct 21, 2021
2182be8
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Oct 22, 2021
2e95066
added java part of oauth
bazarnov Oct 22, 2021
f292b68
changed spec.json to have credentials nested object
bazarnov Oct 23, 2021
dac667e
corrected oauthFlow.java
bazarnov Oct 23, 2021
a1118be
added title to start date in spec.json
bazarnov Oct 24, 2021
3f2eeba
small corrections to OAuthFlow.java
bazarnov Oct 24, 2021
d8bb699
added changelog
bazarnov Oct 24, 2021
2dd3c85
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Oct 28, 2021
afd16be
updated after review
bazarnov Oct 28, 2021
e6abf76
add new secret to workflows
bazarnov Oct 28, 2021
0ed2e1d
formated
bazarnov Oct 28, 2021
d955b0a
fixed conflicts
bazarnov Oct 29, 2021
2ecdcc4
updated after review
bazarnov Nov 1, 2021
4620788
updated after review
bazarnov Nov 1, 2021
ed61026
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Nov 1, 2021
8b025ab
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Nov 1, 2021
cf68d5e
fixed spec.json for SAT
bazarnov Nov 1, 2021
0e17ead
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Dec 15, 2021
1cc691a
made up java-part
bazarnov Dec 16, 2021
e34524f
added java test
bazarnov Dec 16, 2021
a80bd88
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Dec 22, 2021
c4a6e62
updated
bazarnov Dec 22, 2021
c24187c
merged with PR https://github.com/airbytehq/airbyte/pull/9040
bazarnov Dec 22, 2021
a3d07e8
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Dec 23, 2021
fcb19e0
added old config test in SAT
bazarnov Dec 23, 2021
b8a5abd
bumped version
bazarnov Dec 23, 2021
8d4a37c
new spec generated
bazarnov Dec 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"sourceDefinitionId": "40d24d0f-b8f9-4fe0-9e6c-b06c0f3f45e4",
"name": "Zendesk Chat",
"dockerRepository": "airbyte/source-zendesk-chat",
"dockerImageTag": "0.1.5",
"dockerImageTag": "0.1.6",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/zendesk-chat",
"icon": "zendesk.svg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@
- name: Zendesk Chat
sourceDefinitionId: 40d24d0f-b8f9-4fe0-9e6c-b06c0f3f45e4
dockerRepository: airbyte/source-zendesk-chat
dockerImageTag: 0.1.5
dockerImageTag: 0.1.6
documentationUrl: https://docs.airbyte.io/integrations/sources/zendesk-chat
icon: zendesk.svg
sourceType: api
Expand Down
126 changes: 115 additions & 11 deletions airbyte-config/init/src/main/resources/seed/source_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7204,7 +7204,7 @@
- - "client_secret"
oauthFlowOutputParameters:
- - "refresh_token"
- dockerImage: "airbyte/source-zendesk-chat:0.1.5"
- dockerImage: "airbyte/source-zendesk-chat:0.1.6"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/zendesk-chat"
connectionSpecification:
Expand All @@ -7213,27 +7213,131 @@
type: "object"
required:
- "start_date"
- "access_token"
additionalProperties: false
additionalProperties: true
properties:
start_date:
type: "string"
description: "UTC date and time in the format: YYYY-MM-DDT00:00:00Z. Any\
\ data before this date will not be replicated."
title: "Start Date"
description: "The date from which you'd like to replicate data for Zendesk\
\ Chat API, in the format YYYY-MM-DDT00:00:00Z."
examples:
- "2021-02-01T00:00:00Z"
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
access_token:
subdomain:
type: "string"
description: "The Access Token for making authenticated requests. See the\
\ <a href=\"https://docs.airbyte.io/integrations/sources/zendesk-chat\"\
>docs</a> for more information"
title: "Access Token"
airbyte_secret: true
title: "Subdomain (Optional)"
description: "Required if you access Zendesk Chat from a Zendesk Support\
\ subdomain."
default: ""
credentials:
title: "Authorization Method"
type: "object"
oneOf:
- type: "object"
title: "OAuth2.0"
required:
- "credentials"
properties:
credentials:
type: "string"
const: "oauth2.0"
enum:
- "oauth2.0"
default: "oauth2.0"
order: 0
client_id:
type: "string"
title: "Client ID"
description: "The Client ID of your OAuth application"
airbyte_secret: true
client_secret:
type: "string"
title: "Client Secret"
description: "The Client Secret of your OAuth application."
airbyte_secret: true
access_token:
type: "string"
title: "Access Token"
description: "Access Token for making authenticated requests."
airbyte_secret: true
refresh_token:
type: "string"
title: "Refresh Token"
description: "Refresh Token to obtain new Access Token, when it's\
\ expired."
airbyte_secret: true
- type: "object"
title: "Access Token"
required:
- "credentials"
- "access_token"
properties:
credentials:
type: "string"
const: "access_token"
enum:
- "access_token"
default: "access_token"
order: 0
access_token:
type: "string"
title: "Access Token"
description: "The Access Token to make authenticated requests."
airbyte_secret: true
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
advanced_auth:
auth_flow_type: "oauth2.0"
predicate_key:
- "credentials"
- "credentials"
predicate_value: "oauth2.0"
oauth_config_specification:
oauth_user_input_from_connector_config_specification:
type: "object"
additionalProperties: false
properties:
subdomain:
type: "string"
path_in_connector_config:
- "subdomain"
complete_oauth_output_specification:
type: "object"
additionalProperties: false
properties:
access_token:
type: "string"
path_in_connector_config:
- "credentials"
- "access_token"
refresh_token:
type: "string"
path_in_connector_config:
- "credentials"
- "refresh_token"
complete_oauth_server_input_specification:
type: "object"
additionalProperties: false
properties:
client_id:
type: "string"
client_secret:
type: "string"
complete_oauth_server_output_specification:
type: "object"
additionalProperties: false
properties:
client_id:
type: "string"
path_in_connector_config:
- "credentials"
- "client_id"
client_secret:
type: "string"
path_in_connector_config:
- "credentials"
- "client_secret"
- dockerImage: "airbyte/source-zendesk-sunshine:0.1.0"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/zendesk_sunshine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ RUN pip install .

ENTRYPOINT ["python", "/airbyte/integration_code/main_dev.py"]

LABEL io.airbyte.version=0.1.5
LABEL io.airbyte.version=0.1.6
LABEL io.airbyte.name=airbyte/source-zendesk-chat
10 changes: 10 additions & 0 deletions airbyte-integrations/connectors/source-zendesk-chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ python main_dev.py discover --config secrets/config.json
python main_dev.py read --config secrets/config.json --catalog sample_files/configured_catalog.json
```

#### 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 acceptance tests, from the connector root, run
```
docker build . --no-cache -t airbyte/source-zendesk-chat:dev \
&& python -m pytest -p source_acceptance_test.plugin
```
To run your integration tests with docker

### Unit Tests
To run unit tests locally, from the connector directory run:
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ tests:
spec:
- spec_path: "source_zendesk_chat/spec.json"
connection:
- config_path: "secrets/config_old.json"
status: "succeed"
- config_path: "secrets/config.json"
status: "succeed"
- config_path: "secrets/config_oauth.json"
status: "succeed"
- config_path: "integration_tests/invalid_config.json"
status: "failed"
discovery:
- config_path: "secrets/config_old.json"
- config_path: "secrets/config.json"
- config_path: "secrets/config_oauth.json"
basic_read:
bazarnov marked this conversation as resolved.
Show resolved Hide resolved
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
- config_path: "secrets/config_oauth.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
incremental:
- config_path: "secrets/config.json"
configured_catalog_path: "integration_tests/configured_catalog.json"
# Unable to use 'future_state_path' because Zendesk Chat API returns an error when specifying a date in the future.
# future_state_path: "integration_tests/abnormal_state.json"
# Unable to use 'future_state_path' because Zendesk Chat API returns an error when specifying a date in the future.
# future_state_path: "integration_tests/abnormal_state.json"
cursor_paths:
agents: [ "id" ]
bans: [ "id" ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"access_token": "wrongkey-access-token",
"start_date": "2020-12-12T00:00:00Z"
"start_date": "2020-10-01T00:00:00Z",
"subdomain": "",
"credentials": {
"credentials": "access_token",
"access_token": "wrong_access_token"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"access_token": "<your_access_token>",
"start_date": "2020-11-01T00:00:00Z"
"start_date": "2020-11-01T00:00:00Z",
"subdomain": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#


from typing import Any, List, Mapping, Tuple
from typing import Any, Dict, List, Mapping, Tuple

from airbyte_cdk.models import SyncMode
from airbyte_cdk.sources import AbstractSource
Expand All @@ -13,18 +13,36 @@
from .streams import Accounts, Agents, AgentTimelines, Bans, Chats, Departments, Goals, Roles, RoutingSettings, Shortcuts, Skills, Triggers


class ZendeskAuthentication:
""" Provides the authentication capabilities for both old and new methods. """

def __init__(self, config: Dict):
self.config = config

def get_auth(self) -> TokenAuthenticator:
""" Return the TokenAuthenticator object with access_token. """

# the old config supports for backward capability
access_token = self.config.get("access_token")
bazarnov marked this conversation as resolved.
Show resolved Hide resolved
if not access_token:
# the new config supports `OAuth2.0`
access_token = self.config["credentials"]["access_token"]

return TokenAuthenticator(token=access_token)


class SourceZendeskChat(AbstractSource):
def check_connection(self, logger, config) -> Tuple[bool, any]:
authenticator = ZendeskAuthentication(config).get_auth()
try:
authenticator = TokenAuthenticator(config["access_token"])
records = RoutingSettings(authenticator=authenticator).read_records(sync_mode=SyncMode.full_refresh)
next(records)
return True, None
except Exception as error:
return False, f"Unable to connect to Zendesk Chat API with the provided credentials - {error}"

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
authenticator = TokenAuthenticator(config["access_token"])
authenticator = ZendeskAuthentication(config).get_auth()
return [
Accounts(authenticator=authenticator),
AgentTimelines(authenticator=authenticator, start_date=config["start_date"]),
Expand Down
Loading