Skip to content

Commit de4ac75

Browse files
committed
[req-changes] Let's accept list of assets for hierarchical filters instead of dict
1 parent fd08933 commit de4ac75

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

pyatlan/model/packages/mongodb_crawler.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import List, Optional
3+
from typing import Dict, List, Optional
44

55
from pyatlan.model.enums import AtlanConnectorType, WorkflowPackage
66
from pyatlan.model.packages.base.crawler import AbstractCrawler
@@ -104,32 +104,34 @@ def basic_auth(
104104
self._credentials_body.update(local_creds)
105105
return self
106106

107-
def include(self, assets: dict) -> MongoDBCrawler:
107+
def include(self, assets: List[str]) -> MongoDBCrawler:
108108
"""
109109
Defines the filter for assets to include when crawling.
110110
111-
:param assets: dict where keys are database names, and values are lists of collections.
111+
:param assets: list of databases names to include when crawling
112112
:returns: crawler, set to include only those assets specified
113113
:raises InvalidRequestException: In the unlikely
114114
event the provided filter cannot be translated
115115
"""
116-
include_assets = assets or {}
116+
assets = assets or []
117+
include_assets: Dict[str, List[str]] = {asset: [] for asset in assets}
117118
to_include = self.build_hierarchical_filter(include_assets)
118119
self._parameters.append(
119120
dict(dict(name="include-filter", value=to_include or "{}"))
120121
)
121122
return self
122123

123-
def exclude(self, assets: dict) -> MongoDBCrawler:
124+
def exclude(self, assets: List[str]) -> MongoDBCrawler:
124125
"""
125126
Defines the filter for assets to exclude when crawling.
126127
127-
:param assets: dict where keys are database names, and values are lists of collections.
128+
:param assets: list of databases names to exclude when crawling
128129
:returns: crawler, set to exclude only those assets specified
129130
:raises InvalidRequestException: In the unlikely
130131
event the provided filter cannot be translated
131132
"""
132-
exclude_assets = assets or {}
133+
assets = assets or []
134+
exclude_assets: Dict[str, List[str]] = {asset: [] for asset in assets}
133135
to_exclude = self.build_hierarchical_filter(exclude_assets)
134136
self._parameters.append(dict(name="exclude-filter", value=to_exclude or "{}"))
135137
return self

tests/unit/data/package_requests/mongodb_basic.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@
5252
},
5353
{
5454
"name": "include-filter",
55-
"value": "{\"^test-include$\": [\"^test-asset-1$\", \"^test-asset-2$\"]}"
55+
"value": "{\"^test-asset-1$\": [], \"^test-asset-2$\": []}"
5656
},
5757
{
5858
"name": "exclude-filter",
59-
"value": "{\"^test-exlcude$\": [\"^test-asset-1$\", \"^test-asset-2$\"]}"
59+
"value": "{\"^test-asset-1$\": [], \"^test-asset-2$\": []}"
6060
},
6161
{
6262
"name": "temp-table-regex",

tests/unit/test_packages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ def test_mongodb_package(mock_package_env):
638638
auth_db="test-auth-db",
639639
is_ssl=False,
640640
)
641-
.include(assets={"test-include": ["test-asset-1", "test-asset-2"]})
642-
.exclude(assets={"test-exlcude": ["test-asset-1", "test-asset-2"]})
641+
.include(assets=["test-asset-1", "test-asset-2"])
642+
.exclude(assets=["test-asset-1", "test-asset-2"])
643643
.exclude_regex(regex="TEST*")
644644
.to_workflow()
645645
)

0 commit comments

Comments
 (0)