Skip to content

Commit

Permalink
feat(googlesheets2): first pass at passing token
Browse files Browse the repository at this point in the history
put in conditional to prevent bug
  • Loading branch information
testinnplayin committed Aug 28, 2020
1 parent 8ba1c5d commit 2bfb1b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class GoogleSheets2Connector(ToucanConnector):
data_source_model: GoogleSheets2DataSource

auth_flow = 'oauth2'
access_token: str

def _retrieve_data(self, data_source: GoogleSheets2DataSource) -> pd.DataFrame:
def _retrieve_data(
self, data_source: GoogleSheets2DataSource, secrets: Optional[dict]
) -> pd.DataFrame:
print('secrets ', secrets)
pass
18 changes: 14 additions & 4 deletions toucan_connectors/toucan_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,27 @@ def retry_decorator(self):
return RetryPolicy(**kwargs)

@abstractmethod
def _retrieve_data(self, data_source: ToucanDataSource):
def _retrieve_data(self, data_source: ToucanDataSource, secrets: Optional[dict]):
"""Main method to retrieve a pandas dataframe"""

@decorate_func_with_retry
def get_df(
self, data_source: ToucanDataSource, permissions: Optional[dict] = None
self,
data_source: ToucanDataSource,
permissions: Optional[dict] = None,
secrets: Optional[dict] = None,
) -> pd.DataFrame:
"""
Method to retrieve the data as a pandas dataframe
filtered by permissions
"""
res = self._retrieve_data(data_source)
# This is to avoid having to modify every single connectors'
# _retrieve_data function
if secrets:
res = self._retrieve_data(data_source, secrets)
else:
res = self._retrieve_data(data_source)

if permissions is not None:
permissions_query = PandasConditionTranslator.translate(permissions)
permissions_query = apply_query_parameters(permissions_query, data_source.parameters)
Expand All @@ -249,6 +258,7 @@ def get_slice(
permissions: Optional[dict] = None,
offset: int = 0,
limit: Optional[int] = None,
secrets: Optional[dict] = None,
) -> DataSlice:
"""
Method to retrieve a part of the data as a pandas dataframe
Expand All @@ -258,7 +268,7 @@ def get_slice(
- limit is the number of rows to retrieve
Exemple: if offset = 5 and limit = 10 then 10 results are expected from 6th row
"""
df = self.get_df(data_source, permissions)
df = self.get_df(data_source, permissions, secrets)
if limit is not None:
return DataSlice(df[offset : offset + limit], len(df))
else:
Expand Down

0 comments on commit 2bfb1b6

Please sign in to comment.