Skip to content

Commit

Permalink
refac:
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas1312 committed Oct 5, 2023
1 parent 5dd24f2 commit f73896a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
3 changes: 1 addition & 2 deletions src/kili/domain/cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class DataIntegrationFilters:

@dataclass
class DataConnectionFilters:
"""Data Connection filters."""
"""DataConnectionsWhere filters."""

data_connection_id: Optional[DataConnectionId]
project_id: Optional[ProjectId]
integration_id: Optional[DataIntegrationId]
39 changes: 23 additions & 16 deletions src/kili/presentation/client/cloud_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,30 @@ def cloud_storage_connections(

disable_tqdm = disable_tqdm_if_as_generator(as_generator, disable_tqdm)

data_connections_gen = CloudStorageUseCases(self.kili_api_gateway).list_data_connections(
data_connection_filters=DataConnectionFilters(
data_connection_id=(
DataConnectionId(cloud_storage_connection_id)
if cloud_storage_connection_id is not None
else None
),
project_id=ProjectId(project_id) if project_id is not None else None,
integration_id=(
DataIntegrationId(cloud_storage_integration_id)
if cloud_storage_integration_id is not None
else None
cloud_storage_use_cases = CloudStorageUseCases(self.kili_api_gateway)

if cloud_storage_connection_id is None:
data_connections_gen = cloud_storage_use_cases.list_data_connections(
data_connection_filters=DataConnectionFilters(
project_id=ProjectId(project_id) if project_id is not None else None,
integration_id=(
DataIntegrationId(cloud_storage_integration_id)
if cloud_storage_integration_id is not None
else None
),
),
),
fields=fields,
options=QueryOptions(disable_tqdm, first, skip),
)
fields=fields,
options=QueryOptions(disable_tqdm, first, skip),
)
else:
data_connections_gen = (
i
for i in [
cloud_storage_use_cases.get_data_connection(
DataConnectionId(cloud_storage_connection_id), fields=fields
)
]
)

if as_generator:
return data_connections_gen
Expand Down
17 changes: 4 additions & 13 deletions src/kili/use_cases/cloud_storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Cloud storage use cases."""
import time
from datetime import datetime
from typing import Dict, Generator, Iterable, List, Optional
from typing import Dict, Generator, List, Optional

from tenacity import Retrying
from tenacity.retry import retry_if_exception_type
Expand Down Expand Up @@ -34,19 +34,10 @@ def list_data_connections(
data_connection_filters: DataConnectionFilters,
fields: ListOrTuple[str],
options: QueryOptions,
) -> Iterable[Dict]:
) -> Generator[Dict, None, None]:
"""List data connections."""
if data_connection_filters.data_connection_id is None:
return self._kili_api_gateway.list_data_connections(
data_connection_filters=data_connection_filters, fields=fields, options=options
)

return iter(
[
self._kili_api_gateway.get_data_connection(
data_connection_id=data_connection_filters.data_connection_id, fields=fields
)
]
return self._kili_api_gateway.list_data_connections(
data_connection_filters=data_connection_filters, fields=fields, options=options
)

def get_data_connection(
Expand Down

0 comments on commit f73896a

Please sign in to comment.