Skip to content

Commit

Permalink
🎉 Source Zendesk-Chat: add oauth flow support (#7313)
Browse files Browse the repository at this point in the history
  • Loading branch information
bazarnov authored Dec 23, 2021
1 parent be303bd commit 5ed94a8
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 57 deletions.
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 @@ -7209,7 +7209,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 @@ -7218,27 +7218,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:
- 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")
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

0 comments on commit 5ed94a8

Please sign in to comment.