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

Run ci checks for ✨ Source Asana: Add SectionsCompact stream #31173

Closed
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-asana/BOOTSTRAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Connector is implemented with [Airbyte CDK](https://docs.airbyte.io/connector-de

Some streams depend on:
- workspaces (Teams, Users, CustomFields, Projects, Tags, Users streams);
- projects (Sections, Tasks streams);
- projects (SectionsCompact, Sections, Tasks streams);
- tasks (Stories stream);
- teams (TeamMemberships stream).

Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-asana/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.7
LABEL io.airbyte.version=0.1.8
LABEL io.airbyte.name=airbyte/source-asana
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"sync_mode": "full_refresh",
"destination_sync_mode": "overwrite"
},
{
"stream": {
"name": "sections_compact",
"json_schema": {},
"supported_sync_modes": ["full_refresh"]
},
"sync_mode": "full_refresh",
"destination_sync_mode": "overwrite"
},
{
"stream": {
"name": "sections",
Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-asana/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: d0243522-dccf-4978-8ba0-37ed47a0bdbf
dockerImageTag: 0.1.7
dockerImageTag: 0.1.8
dockerRepository: airbyte/source-asana
documentationUrl: https://docs.airbyte.com/integrations/sources/asana
githubIssueLabel: source-asana
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Tuple

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


class AsanaOauth2Authenticator(Oauth2Authenticator):
Expand All @@ -24,13 +24,13 @@ def refresh_access_token(self) -> Tuple[str, int]:
Tuple of access token and expiration time in seconds
"""
data = {
"client_id": (None, self.client_id),
"client_secret": (None, self.client_secret),
"client_id": (None, self._client_id),
"client_secret": (None, self._client_secret),
"grant_type": (None, "refresh_token"),
"refresh_token": (None, self.refresh_token),
"refresh_token": (None, self._refresh_token),
}

response = requests.post(self.token_refresh_endpoint, files=data)
response = requests.post(self._token_refresh_endpoint, files=data)
response.raise_for_status()
response_body = response.json()
return response_body["access_token"], response_body["expires_in"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": ["null", "object"],
"properties": {
"gid": {
"type": ["null", "string"]
},
"resource_type": {
"type": ["null", "string"]
},
"name": {
"type": ["null", "string"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
from airbyte_cdk.models import SyncMode
from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.streams import Stream
from airbyte_cdk.sources.streams.http.auth import TokenAuthenticator
from airbyte_cdk.sources.streams.http.requests_native_auth import TokenAuthenticator
from source_asana.oauth import AsanaOauth2Authenticator

from .streams import CustomFields, Projects, Sections, Stories, Tags, Tasks, TeamMemberships, Teams, Users, Workspaces
from .streams import CustomFields, Projects, Sections, SectionsCompact, Stories, Tags, Tasks, TeamMemberships, Teams, Users, Workspaces


class SourceAsana(AbstractSource):
def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> Tuple[bool, Any]:
try:
workspaces_stream = Workspaces(authenticator=self._get_authenticator(config))
logger("THIS IS THE WORKSPACES STREAM", workspaces_stream)
next(workspaces_stream.read_records(sync_mode=SyncMode.full_refresh))
return True, None
except Exception as e:
Expand Down Expand Up @@ -46,6 +47,7 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
return [
CustomFields(**args),
Projects(**args),
SectionsCompact(**args),
Sections(**args),
Stories(**args),
Tags(**args),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def _handle_array_type(self, prop: str, value: MutableMapping[str, Any]) -> str:

def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapping]:
response_json = response.json()
yield from response_json.get("data", []) # Asana puts records in a container array "data"
# Asana puts records in a container array "data"
yield from response_json.get("data", [])

def read_slices_from_records(self, stream_class: AsanaStreamType, slice_field: str) -> Iterable[Optional[Mapping[str, Any]]]:
"""
Expand Down Expand Up @@ -132,7 +133,7 @@ def request_params(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> Mu

class ProjectRelatedStream(AsanaStream, ABC):
"""
Few streams (Sections and Tasks) depends on `project gid`: Sections as a part of url and Tasks as `projects`
Few streams (SectionsCompact and Tasks) depends on `project gid`: SectionsCompact as a part of url and Tasks as `projects`
argument in request.
"""

Expand All @@ -153,12 +154,21 @@ def path(self, **kwargs) -> str:
return "projects"


class Sections(ProjectRelatedStream):
class SectionsCompact(ProjectRelatedStream):
def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
project_gid = stream_slice["project_gid"]
return f"projects/{project_gid}/sections"


class Sections(AsanaStream):
def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
section_gid = stream_slice["section_gid"]
return f"sections/{section_gid}"

def stream_slices(self, **kwargs) -> Iterable[Optional[Mapping[str, Any]]]:
yield from self.read_slices_from_records(stream_class=SectionsCompact, slice_field="section_gid")


class Stories(AsanaStream):
def path(self, stream_slice: Mapping[str, Any] = None, **kwargs) -> str:
task_gid = stream_slice["task_gid"]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import pytest
import requests_mock as req_mock
from airbyte_cdk.models import SyncMode
from source_asana.streams import AsanaStream, Sections, Stories, Tags, Tasks, TeamMemberships, Users
from source_asana.streams import AsanaStream, Sections, SectionsCompact, Stories, Tags, Tasks, TeamMemberships, Users


@pytest.mark.parametrize(
"stream",
[Tasks, Sections, Users, TeamMemberships, Tags, Stories],
[Tasks, SectionsCompact, Sections, Users, TeamMemberships, Tags, Stories],
)
def test_task_stream(requests_mock, stream, mock_response):
requests_mock.get(req_mock.ANY, json=mock_response)
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/asana.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The connector is restricted by normal Asana [requests limitation](https://develo

| Version | Date | Pull Request | Subject |
| :------ | :--------- | :------------------------------------------------------- | :--------------------------------------------------------- |
| 0.1.8 | 2023-10-16 | [31009](https://github.com/airbytehq/airbyte/pull/31009) | Add SectionsCompact stream |
| 0.1.7 | 2023-05-29 | [26716](https://github.com/airbytehq/airbyte/pull/26716) | Remove authSpecification from spec.json, use advancedAuth instead |
| 0.1.6 | 2023-05-26 | [26653](https://github.com/airbytehq/airbyte/pull/26653) | Fix order of authentication methods |
| 0.1.5 | 2022-11-16 | [19561](https://github.com/airbytehq/airbyte/pull/19561) | Added errors handling, updated SAT with new format |
Expand Down
Loading