Skip to content

Commit f8e8a5a

Browse files
Vivek-kumar-QlikVivekKumarGLrdeshmukh15prijendev
authored
Sac 27555 fix libraries (#61)
* Updated requirements * Updated refresh_access_token function according to new asana version. * fixed imports acording to new version of asana. * for projects used new sdk methods. * Updated api call according to new sdk * Updated stories stream api call according to new sdk * Updated sections stream api call according to new sdk * Updated tasks stream api call according to new sdk * Updated tags stream api call according to new sdk * Updated tags stream api call according to new sdk * Updated teams stream api call according to new sdk * Updated users stream api call according to new sdk * Updated workspaces stream api call according to new sdk * Updated Schemas as per new SDK. * Updated subtasks stream api call according to new sdk * updated call_api method. * updated call_api method. * Fixed unit test. * fixed session bookmark. * Fixed retry_after_wait_gen function. * Exclude library function which is not available now. * Included request timeout in api call. * updated unit test according to new api call. * made changes according to pylint message. * made changes according to pylint message. * formatted according to pylint * formatted according to pylint * Fixed formatting. * Fixed formatting. and pylint error. * Added line at EOF. * removed unwanted line. * Fixed pylint error. * Excluded fields not available in new SDK. * Added status code 412, 401 as InvalidTokenError and NoAuthorizationError not avilable in new SDK. * removed unrequired field, updated default retry-after to 5 sec. * Removed unwanted line. * formating changes. * updated fields as per schema changes. * made changes according to pylint message. * Fixed unit test according to new functions. * Debuging Failure. * Debuging Failure. * Revert Changes. * revert changes to run integration test. * revert changes to run integration test. * fixed teams workspaces method call. * changed offset to True. * removed unwanted fields, corrected formatting. * removed keys as they are not available * Added custom error. * Added unit test for custom exceptions. * Added Test for Retry behaviour. * removed unrequired tests * updated tap-asana version. * adds requests in the install_requires * # Removing Portfolios as they are only available for users in an Enterprise or Business plan. * Remove approval_status from tasks expected keys --------- Co-authored-by: Vivek Kumar <vivek.kumar25@globallogic.com> Co-authored-by: “rdeshmukh15” <rutuja.deshmukh@qlik.com> Co-authored-by: Rutuja Deshmukh <107538720+rdeshmukh15@users.noreply.github.com> Co-authored-by: Prijen Khokhani <88327452+prijendev@users.noreply.github.com>
1 parent 088786c commit f8e8a5a

26 files changed

+1170
-481
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 2.4.0
4+
* Upgrade asana SDK version to 5.1.0. [#61](https://github.com/singer-io/tap-asana/pull/61)
5+
36
## 2.3.0
47
* New Stream Inclusion: Subtasks [#56](https://github.com/singer-io/tap-asana/pull/56)
58

setup.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33

44
setup(
55
name="tap-asana",
6-
version="2.3.0",
6+
version="2.4.0",
77
description="Singer.io tap for extracting Asana data",
88
author="Stitch",
99
url="http://github.com/singer-io/tap-asana",
1010
classifiers=["Programming Language :: Python :: 3 :: Only"],
1111
py_modules=["tap_asana"],
1212
install_requires=[
13-
"asana==3.1.0",
14-
'singer-python==5.13.0'
13+
"asana==5.1.0",
14+
"requests==2.32.4",
15+
"singer-python==6.1.1"
1516
],
1617
extras_require={
17-
'test': [
18-
'pylint',
19-
'requests==2.20.0',
20-
'nose'
18+
"test": [
19+
"pylint",
20+
"nose"
2121
],
22-
'dev': [
23-
'ipdb'
22+
"dev": [
23+
"ipdb"
2424
]
2525
},
2626
entry_points="""

tap_asana/asana.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import asana
22
import singer
3+
import requests
34

45
LOGGER = singer.get_logger()
56

67

78
""" Simple wrapper for Asana. """
89

910

11+
# pylint: disable=too-many-positional-arguments
1012
class Asana():
1113
"""Base class for tap-asana"""
1214

@@ -18,39 +20,47 @@ def __init__(
1820
self.redirect_uri = redirect_uri
1921
self.refresh_token = refresh_token
2022
self.access_token = access_token
21-
self._client = self._oauth_auth() or self._access_token_auth()
22-
self.refresh_access_token()
23-
24-
def _oauth_auth(self):
25-
"""Oauth authentication for tap"""
26-
if (
27-
self.client_id is None
28-
or self.client_secret is None
29-
or self.redirect_uri is None
30-
or self.refresh_token is None
31-
):
32-
LOGGER.debug("OAuth authentication unavailable.")
33-
return None
34-
return asana.Client.oauth(
35-
client_id=self.client_id,
36-
client_secret=self.client_secret,
37-
redirect_uri=self.redirect_uri,
38-
)
23+
self._client = self._access_token_auth()
3924

4025
def _access_token_auth(self):
4126
"""Check for access token"""
4227
if self.access_token is None:
43-
LOGGER.debug("OAuth authentication unavailable.")
44-
return None
45-
return asana.Client.access_token(self.access_token)
28+
self.access_token = self.refresh_access_token()
29+
30+
if self.access_token:
31+
try:
32+
configuration = asana.Configuration()
33+
configuration.access_token = self.access_token
34+
return asana.ApiClient(configuration)
35+
except asana.rest.ApiException as e:
36+
LOGGER.error("Error creating Asana client: %s", e)
37+
return None
4638

4739
def refresh_access_token(self):
48-
return self._client.session.refresh_token(
49-
self._client.session.token_url,
50-
client_id=self.client_id,
51-
client_secret=self.client_secret,
52-
refresh_token=self.refresh_token,
53-
)
40+
"""Get the access token using the refresh token"""
41+
url = "https://app.asana.com/-/oauth_token"
42+
payload = {
43+
"grant_type": "refresh_token",
44+
"client_id": self.client_id,
45+
"client_secret": self.client_secret,
46+
"redirect_uri": self.redirect_uri,
47+
"refresh_token": self.refresh_token,
48+
}
49+
50+
headers = {"Content-Type": "application/x-www-form-urlencoded"}
51+
52+
try:
53+
response = requests.post(url, data=payload, headers=headers, timeout=30)
54+
55+
if response.status_code == 200:
56+
LOGGER.debug("Access token refreshed successfully.")
57+
if "access_token" in response.json():
58+
self.access_token = response.json()["access_token"]
59+
return response.json()["access_token"]
60+
return None
61+
except requests.exceptions.RequestException as e:
62+
LOGGER.error("Failed to refresh access token: %s", e)
63+
return None
5464

5565
@property
5666
def client(self):

tap_asana/schemas/portfolios.json

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@
466466
]
467467
}
468468
}
469-
}
469+
}
470470
}
471471
}
472472
},
@@ -645,7 +645,7 @@
645645
"string"
646646
]
647647
}
648-
}
648+
}
649649
},
650650
"custom_fields": {
651651
"type": [
@@ -872,6 +872,57 @@
872872
"null",
873873
"boolean"
874874
]
875+
},
876+
"archived": {
877+
"type": [
878+
"null",
879+
"boolean"
880+
]
881+
},
882+
"default_access_level": {
883+
"type": [
884+
"null",
885+
"string"
886+
]
887+
},
888+
"privacy_setting": {
889+
"type": [
890+
"null",
891+
"string"
892+
]
893+
},
894+
"project_templates": {
895+
"type": [
896+
"null",
897+
"array"
898+
],
899+
"items": {
900+
"type": [
901+
"null",
902+
"object"
903+
],
904+
"additionalProperties": false,
905+
"properties": {
906+
"gid": {
907+
"type": [
908+
"null",
909+
"string"
910+
]
911+
},
912+
"resource_type": {
913+
"type": [
914+
"null",
915+
"string"
916+
]
917+
},
918+
"name": {
919+
"type": [
920+
"null",
921+
"string"
922+
]
923+
}
924+
}
925+
}
875926
}
876927
}
877928
}

tap_asana/schemas/projects.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@
940940
]
941941
}
942942
}
943-
}
943+
}
944944
}
945945
}
946946
},

tap_asana/schemas/stories.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,12 @@
12181218
"null",
12191219
"string"
12201220
]
1221+
},
1222+
"new_approval_status_updated": {
1223+
"type": [
1224+
"null",
1225+
"string"
1226+
]
12211227
}
12221228
}
12231229
}

tap_asana/schemas/teams.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@
106106
"null",
107107
"string"
108108
]
109+
},
110+
"edit_team_name_or_description_access_level": {
111+
"type": ["null", "string"]
112+
},
113+
"edit_team_visibility_or_trash_team_access_level": {
114+
"type": ["null", "string"]
115+
},
116+
"member_invite_management_access_level": {
117+
"type": ["null", "string"]
118+
},
119+
"guest_invite_management_access_level": {
120+
"type": ["null", "string"]
121+
},
122+
"join_request_management_access_level": {
123+
"type": ["null", "string"]
124+
},
125+
"team_member_removal_access_level": {
126+
"type": ["null", "string"]
127+
},
128+
"team_content_management_access_level": {
129+
"type": ["null", "string"]
130+
},
131+
"endorsed": {
132+
"type": ["null", "boolean"]
109133
}
110134
}
111135
}

0 commit comments

Comments
 (0)