Skip to content

Commit 13d4a1e

Browse files
authored
Merge pull request #45 from atlanhq/find_connections
Add find_connections_by_name method to AtlanClient
2 parents bd5e405 + 5faa8ea commit 13d4a1e

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

HISTORY.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.0.28 (May 9, 2023)
2+
3+
* Add find_connections_by_name to AtlanClient
4+
15
## 0.0.27 (May 8, 2023)
26

37
* Add a create method to Process

pyatlan/client/atlan.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@
6161
CustomMetadata,
6262
CustomMetadataReqest,
6363
)
64-
from pyatlan.model.enums import AtlanDeleteType, AtlanTypeCategory, CertificateStatus
64+
from pyatlan.model.enums import (
65+
AtlanConnectorType,
66+
AtlanDeleteType,
67+
AtlanTypeCategory,
68+
CertificateStatus,
69+
)
6570
from pyatlan.model.response import AssetMutationResponse
6671
from pyatlan.model.role import RoleResponse
67-
from pyatlan.model.search import IndexSearchRequest
72+
from pyatlan.model.search import DSL, IndexSearchRequest, Term
6873
from pyatlan.model.typedef import (
6974
ClassificationDef,
7075
CustomMetadataDef,
@@ -702,3 +707,24 @@ def remove_terms(
702707
if assets := response.assets_updated(asset_type=asset_type):
703708
return assets[0]
704709
return asset
710+
711+
@validate_arguments()
712+
def find_connections_by_name(
713+
self,
714+
name: str,
715+
connector_type: AtlanConnectorType,
716+
attributes: list[str] = None,
717+
) -> list[Connection]:
718+
query = (
719+
Term.with_state("ACTIVE")
720+
+ Term.with_type_name("CONNECTION")
721+
+ Term.with_name(name)
722+
+ Term(field="connectorName", value=connector_type.value)
723+
)
724+
dsl = DSL(query=query)
725+
search_request = IndexSearchRequest(
726+
dsl=dsl,
727+
attributes=attributes,
728+
)
729+
results = self.search(search_request)
730+
return [asset for asset in results if isinstance(asset, Connection)]

pyatlan/version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.27
1+
0.0.28

tests/integration/test_client.py

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pyatlan.client.atlan import AtlanClient
77
from pyatlan.model.assets import AtlasGlossary, AtlasGlossaryTerm, Connection, Database
8+
from pyatlan.model.enums import AtlanConnectorType
89

910
iter_count = count(1)
1011

@@ -219,3 +220,13 @@ def test_remove_term(
219220
assert deleted_terms[0].guid == original_term.guid
220221
active_terms = [t for t in database.terms if t.relationship_status != "DELETED"]
221222
assert active_terms[0].guid == another_term.guid
223+
224+
225+
def test_find_connections_by_name(client: AtlanClient):
226+
connections = client.find_connections_by_name(
227+
name="Test Connection",
228+
connector_type=AtlanConnectorType.SNOWFLAKE,
229+
attributes=["connectorName"],
230+
)
231+
assert len(connections) == 1
232+
assert connections[0].connector_name == AtlanConnectorType.SNOWFLAKE.value

0 commit comments

Comments
 (0)