Skip to content

Commit ae1b273

Browse files
feat: expose include, prefix and exclude filter for data connections
1 parent a4387c9 commit ae1b273

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

src/kili/adapters/kili_api_gateway/cloud_storage/mappers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ def data_connection_where_mapper(filters: DataConnectionFilters) -> Dict:
3333
def add_data_connection_data_mapper(data: AddDataConnectionKiliAPIGatewayInput) -> Dict:
3434
"""Build the GraphQL DataConnectionInput variable to be sent in an operation."""
3535
return {
36-
"projectId": data.project_id,
36+
"exclude": data.exclude,
37+
"include": data.include,
3738
"integrationId": data.integration_id,
3839
"isChecking": data.is_checking,
3940
"lastChecked": data.last_checked.isoformat(sep="T", timespec="milliseconds") + "Z",
41+
"prefix": data.prefix,
42+
"projectId": data.project_id,
4043
"selectedFolders": data.selected_folders,
4144
}
4245

src/kili/adapters/kili_api_gateway/cloud_storage/types.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
class AddDataConnectionKiliAPIGatewayInput:
1818
"""Add data connection input data for Kili API Gateway."""
1919

20-
is_checking: bool
20+
exclude: Optional[List[str]]
21+
include: Optional[List[str]]
2122
integration_id: DataIntegrationId
23+
is_checking: bool
2224
last_checked: datetime
25+
prefix: Optional[str]
2326
project_id: ProjectId
2427
selected_folders: Optional[List[str]]
2528

@@ -52,10 +55,10 @@ class DataIntegrationData:
5255
name: Optional[str]
5356
organization_id: Optional[OrganizationId]
5457
platform: Optional[DataIntegrationPlatform]
55-
status: Optional[DataIntegrationStatus]
5658
s3_access_key: Optional[str]
5759
s3_bucket_name: Optional[str]
5860
s3_endpoint: Optional[str]
5961
s3_region: Optional[str]
6062
s3_secret_key: Optional[str]
6163
s3_session_token: Optional[str]
64+
status: Optional[DataIntegrationStatus]

src/kili/presentation/client/cloud_storage.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,23 +296,39 @@ def add_cloud_storage_connection(
296296
project_id: str,
297297
cloud_storage_integration_id: str,
298298
selected_folders: Optional[List[str]] = None,
299+
prefix: Optional[str] = None,
300+
include: Optional[List[str]] = None,
301+
exclude: Optional[List[str]] = None,
299302
) -> Dict:
300-
"""Connect a cloud storage to a project.
303+
"""Connect a cloud storage to a project. More details about parameters
304+
can be found in the [documentation](https://docs.kili-technology.com/docs/filtering-assets-from-cloud-storage).
301305
302306
Args:
303307
project_id: Id of the project.
304308
cloud_storage_integration_id: Id of the cloud storage integration.
305309
selected_folders: List of folders of the data integration to connect to the project.
306310
If not provided, all folders of the data integration will be connected.
311+
This option is deprecated and will be removed in the future.
312+
prefix: Filter files to synchronize based on their base path.
313+
include: List of pattern used to include files based on their path.
314+
exclude: List of pattern used to exclude files based on their path.
307315
308316
Returns:
309317
A dict with the DataConnection Id.
310318
"""
319+
if selected_folders is not None:
320+
logger.warning(
321+
"The selected_folders argument is deprecated and will be removed in the future."
322+
)
323+
311324
data_connection_id = CloudStorageUseCases(self.kili_api_gateway).add_data_connection(
312325
project_id=ProjectId(project_id),
313326
data_integration_id=DataIntegrationId(cloud_storage_integration_id),
314327
selected_folders=selected_folders,
315328
fields=("id",),
329+
prefix=prefix,
330+
include=include,
331+
exclude=exclude,
316332
)["id"]
317333

318334
return {"id": data_connection_id}

src/kili/use_cases/cloud_storage/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ def add_data_connection(
7878
project_id: ProjectId,
7979
selected_folders: Optional[List[str]],
8080
fields: ListOrTuple[str],
81+
prefix: Optional[str] = None,
82+
include: Optional[List[str]] = None,
83+
exclude: Optional[List[str]] = None,
8184
) -> Dict:
8285
"""Add data connection to a project."""
8386
if (
@@ -90,9 +93,12 @@ def add_data_connection(
9093
return self._kili_api_gateway.add_data_connection(
9194
fields=fields,
9295
data=AddDataConnectionKiliAPIGatewayInput(
93-
is_checking=False,
96+
exclude=exclude,
97+
include=include,
9498
integration_id=data_integration_id,
99+
is_checking=False,
95100
last_checked=datetime.now(),
101+
prefix=prefix,
96102
project_id=project_id,
97103
selected_folders=selected_folders,
98104
),

0 commit comments

Comments
 (0)