port-ocean 0.28.14__py3-none-any.whl → 0.28.16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of port-ocean might be problematic. Click here for more details.

@@ -1,24 +1,24 @@
1
1
  import asyncio
2
+ import json
2
3
  from typing import Any, Literal
3
4
  from urllib.parse import quote_plus
4
- import json
5
5
 
6
6
  import httpx
7
7
  from loguru import logger
8
- from port_ocean.context.ocean import ocean
8
+ from starlette import status
9
+
9
10
  from port_ocean.clients.port.authentication import PortAuthentication
10
11
  from port_ocean.clients.port.types import RequestOptions, UserAgentType
11
12
  from port_ocean.clients.port.utils import (
12
- handle_port_status_code,
13
13
  PORT_HTTP_MAX_CONNECTIONS_LIMIT,
14
+ handle_port_status_code,
14
15
  )
16
+ from port_ocean.context.ocean import ocean
15
17
  from port_ocean.core.models import (
16
18
  BulkUpsertResponse,
17
19
  Entity,
18
20
  PortAPIErrorMessage,
19
21
  )
20
- from starlette import status
21
-
22
22
  from port_ocean.helpers.metric.metric import MetricPhase, MetricType
23
23
 
24
24
  ENTITIES_BULK_SAMPLES_SIZE = 10
@@ -484,54 +484,89 @@ class EntityClientMixin:
484
484
  parameters_to_include: list[str] | None = None,
485
485
  ) -> list[Entity]:
486
486
  if query is None:
487
- datasource_prefix = f"port-ocean/{self.auth.integration_type}/"
488
- datasource_suffix = (
489
- f"/{self.auth.integration_identifier}/{user_agent_type.value}"
490
- )
491
- logger.info(
492
- f"Searching entities with datasource prefix: {datasource_prefix} and suffix: {datasource_suffix}"
493
- )
487
+ return await self._search_entities_by_datasource_paginated(user_agent_type)
488
+
489
+ return await self._search_entities_by_query(
490
+ user_agent_type=user_agent_type,
491
+ query=query,
492
+ parameters_to_include=parameters_to_include,
493
+ )
494
+
495
+ async def _search_entities_by_datasource_paginated(
496
+ self, user_agent_type: UserAgentType
497
+ ) -> list[Entity]:
498
+ datasource_prefix = f"port-ocean/{self.auth.integration_type}/"
499
+ datasource_suffix = (
500
+ f"/{self.auth.integration_identifier}/{user_agent_type.value}"
501
+ )
502
+ logger.info(
503
+ f"Searching entities with datasource prefix: {datasource_prefix} and suffix: {datasource_suffix}"
504
+ )
505
+
506
+ next_from: str | None = None
507
+ aggregated_entities: list[Entity] = []
508
+ while True:
509
+ request_body: dict[str, Any] = {
510
+ "datasource_prefix": datasource_prefix,
511
+ "datasource_suffix": datasource_suffix,
512
+ }
513
+
514
+ if next_from:
515
+ request_body["from"] = next_from
494
516
 
495
517
  response = await self.client.post(
496
518
  f"{self.auth.api_url}/blueprints/entities/datasource-entities",
497
- json={
498
- "datasource_prefix": datasource_prefix,
499
- "datasource_suffix": datasource_suffix,
500
- },
519
+ json=request_body,
501
520
  headers=await self.auth.headers(user_agent_type),
502
521
  extensions={"retryable": True},
503
522
  )
504
- else:
505
- default_query = {
506
- "combinator": "and",
507
- "rules": [
508
- {
509
- "property": "$datasource",
510
- "operator": "contains",
511
- "value": f"port-ocean/{self.auth.integration_type}/",
512
- },
513
- {
514
- "property": "$datasource",
515
- "operator": "contains",
516
- "value": f"/{self.auth.integration_identifier}/{user_agent_type.value}",
517
- },
518
- ],
519
- }
523
+ handle_port_status_code(response)
524
+ response_json = response.json()
525
+ aggregated_entities.extend(
526
+ Entity.parse_obj(result) for result in response_json.get("entities", [])
527
+ )
528
+ next_from = response_json.get("next")
529
+ if not next_from:
530
+ break
520
531
 
521
- if query.get("rules"):
522
- query["rules"].extend(default_query["rules"])
532
+ return aggregated_entities
523
533
 
524
- logger.info(f"Searching entities with custom query: {query}")
525
- response = await self.client.post(
526
- f"{self.auth.api_url}/entities/search",
527
- json=query,
528
- headers=await self.auth.headers(user_agent_type),
529
- params={
530
- "exclude_calculated_properties": "true",
531
- "include": parameters_to_include or ["blueprint", "identifier"],
534
+ async def _search_entities_by_query(
535
+ self,
536
+ user_agent_type: UserAgentType,
537
+ query: dict[Any, Any],
538
+ parameters_to_include: list[str] | None,
539
+ ) -> list[Entity]:
540
+ default_query = {
541
+ "combinator": "and",
542
+ "rules": [
543
+ {
544
+ "property": "$datasource",
545
+ "operator": "contains",
546
+ "value": f"port-ocean/{self.auth.integration_type}/",
532
547
  },
533
- extensions={"retryable": True},
534
- )
548
+ {
549
+ "property": "$datasource",
550
+ "operator": "contains",
551
+ "value": f"/{self.auth.integration_identifier}/{user_agent_type.value}",
552
+ },
553
+ ],
554
+ }
555
+
556
+ if query.get("rules"):
557
+ query["rules"].extend(default_query["rules"])
558
+
559
+ logger.info(f"Searching entities with custom query: {query}")
560
+ response = await self.client.post(
561
+ f"{self.auth.api_url}/entities/search",
562
+ json=query,
563
+ headers=await self.auth.headers(user_agent_type),
564
+ params={
565
+ "exclude_calculated_properties": "true",
566
+ "include": parameters_to_include or ["blueprint", "identifier"],
567
+ },
568
+ extensions={"retryable": True},
569
+ )
535
570
 
536
571
  handle_port_status_code(response)
537
572
  return [Entity.parse_obj(result) for result in response.json()["entities"]]
@@ -808,5 +808,12 @@ class JQEntityProcessor(BaseEntityProcessor):
808
808
  ) -> dict[str, Any]:
809
809
  if isinstance(data, tuple):
810
810
  raw_data = json.loads(data[1])
811
- return {items_to_parse_name: data[0], **raw_data}
811
+ return {
812
+ **(
813
+ data[0]
814
+ if items_to_parse_name in data[0]
815
+ else {items_to_parse_name: data[0]}
816
+ ),
817
+ **raw_data,
818
+ }
812
819
  return data
@@ -123,7 +123,7 @@ class SyncRawMixin(HandlerMixin, EventsMixin):
123
123
  f"Found sync function for {resource_config.kind} name: {task.__qualname__}"
124
124
  )
125
125
  task = typing.cast(Callable[[str], Awaitable[RAW_RESULT]], task)
126
- tasks.append(resync_function_wrapper(task, resource_config.kind))
126
+ tasks.append(resync_function_wrapper(task, resource_config.kind, resource_config.port.items_to_parse))
127
127
 
128
128
  logger.info(
129
129
  f"Found {len(tasks) + len(results)} resync tasks for {resource_config.kind}"
@@ -56,7 +56,7 @@ def _process_path_type_items(
56
56
  content = json.loads(f.read())
57
57
  # Create a copy of the item with the content field
58
58
  processed_item = item.copy()
59
- processed_item["content"] = content
59
+ processed_item["file"]["content"] = content
60
60
  processed_result.append(processed_item)
61
61
  else:
62
62
  # If file doesn't exist, keep the original item
@@ -97,12 +97,12 @@ def resync_error_handling() -> Generator[None, None, None]:
97
97
 
98
98
 
99
99
  async def resync_function_wrapper(
100
- fn: Callable[[str], Awaitable[RAW_RESULT]], kind: str
100
+ fn: Callable[[str], Awaitable[RAW_RESULT]], kind: str, items_to_parse: str | None = None
101
101
  ) -> RAW_RESULT:
102
102
  with resync_error_handling():
103
103
  results = await fn(kind)
104
104
  validated_results = validate_result(results)
105
- return _process_path_type_items(validated_results)
105
+ return _process_path_type_items(validated_results, items_to_parse)
106
106
 
107
107
 
108
108
  async def resync_generator_wrapper(
@@ -117,7 +117,7 @@ async def resync_generator_wrapper(
117
117
  result = await anext(generator)
118
118
  if not ocean.config.yield_items_to_parse:
119
119
  validated_result = validate_result(result)
120
- processed_result = _process_path_type_items(validated_result)
120
+ processed_result = _process_path_type_items(validated_result,items_to_parse)
121
121
  yield processed_result
122
122
  else:
123
123
  if items_to_parse:
@@ -179,7 +179,7 @@ async def test_search_entities_uses_datasource_route_when_query_is_none(
179
179
  ) -> None:
180
180
  """Test that search_entities uses datasource route when query is None"""
181
181
  mock_response = MagicMock()
182
- mock_response.json.return_value = {"entities": []}
182
+ mock_response.json.return_value = {"entities": [], "next": None}
183
183
  mock_response.is_error = False
184
184
  mock_response.status_code = 200
185
185
  mock_response.headers = {}
@@ -208,8 +208,74 @@ async def test_search_entities_uses_datasource_route_when_query_is_none(
208
208
  == "https://api.getport.io/v1/blueprints/entities/datasource-entities"
209
209
  )
210
210
 
211
- expected_json = {
212
- "datasource_prefix": "port-ocean/test-integration/",
213
- "datasource_suffix": "/test-identifier/sync",
211
+ sent_json = call_args[1]["json"]
212
+ assert sent_json["datasource_prefix"] == "port-ocean/test-integration/"
213
+ assert sent_json["datasource_suffix"] == "/test-identifier/sync"
214
+
215
+
216
+ async def test_search_entities_uses_datasource_route_when_query_is_none_two_pages(
217
+ entity_client: EntityClientMixin,
218
+ ) -> None:
219
+ """Test that search_entities uses datasource route when query is None"""
220
+ # First response with pagination token
221
+ mock_response_first = MagicMock()
222
+ mock_response_first.json.return_value = {
223
+ "entities": [
224
+ Entity(identifier="entity_1", blueprint="entity_1"),
225
+ Entity(identifier="entity_2", blueprint="entity_2"),
226
+ ],
227
+ "next": "next_page_token",
228
+ }
229
+ mock_response_first.is_error = False
230
+ mock_response_first.status_code = 200
231
+ mock_response_first.headers = {}
232
+
233
+ # Second response without pagination token (end of pagination)
234
+ mock_response_second = MagicMock()
235
+ mock_response_second.json.return_value = {
236
+ "entities": [Entity(identifier="entity_3", blueprint="entity_3")],
237
+ "next": None,
214
238
  }
215
- assert call_args[1]["json"] == expected_json
239
+ mock_response_second.is_error = False
240
+ mock_response_second.status_code = 200
241
+ mock_response_second.headers = {}
242
+
243
+ # Mock the client to return different responses for each call
244
+ entity_client.client.post = AsyncMock(side_effect=[mock_response_first, mock_response_second]) # type: ignore
245
+ entity_client.auth.headers = AsyncMock(return_value={"Authorization": "Bearer test"}) # type: ignore
246
+
247
+ entity_client.auth.integration_type = "test-integration"
248
+ entity_client.auth.integration_identifier = "test-identifier"
249
+ entity_client.auth.api_url = "https://api.getport.io/v1"
250
+
251
+ mock_user_agent_type = MagicMock()
252
+ mock_user_agent_type.value = "sync"
253
+
254
+ entities = await entity_client.search_entities(
255
+ user_agent_type=mock_user_agent_type,
256
+ query=None,
257
+ )
258
+
259
+ # Should call the datasource-entities endpoint exactly twice for pagination
260
+ assert entity_client.client.post.await_count == 2
261
+ assert len(entities) == 3
262
+
263
+ # Check first call
264
+ first_call_args = entity_client.client.post.call_args_list[0]
265
+ assert (
266
+ first_call_args[0][0]
267
+ == "https://api.getport.io/v1/blueprints/entities/datasource-entities"
268
+ )
269
+ first_sent_json = first_call_args[1]["json"]
270
+ assert first_sent_json["datasource_prefix"] == "port-ocean/test-integration/"
271
+ assert first_sent_json["datasource_suffix"] == "/test-identifier/sync"
272
+
273
+ # Check second call
274
+ second_call_args = entity_client.client.post.call_args_list[1]
275
+ assert (
276
+ second_call_args[0][0]
277
+ == "https://api.getport.io/v1/blueprints/entities/datasource-entities"
278
+ )
279
+ second_sent_json = second_call_args[1]["json"]
280
+ assert second_sent_json["datasource_prefix"] == "port-ocean/test-integration/"
281
+ assert second_sent_json["datasource_suffix"] == "/test-identifier/sync"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: port-ocean
3
- Version: 0.28.14
3
+ Version: 0.28.16
4
4
  Summary: Port Ocean is a CLI tool for managing your Port projects.
5
5
  Home-page: https://app.getport.io
6
6
  Keywords: ocean,port-ocean,port
@@ -60,7 +60,7 @@ port_ocean/clients/port/authentication.py,sha256=ZO1Vw1nm-NlVUPPtPS5O4GGDvRmyS3v
60
60
  port_ocean/clients/port/client.py,sha256=hBXgU0CDseN2F-vn20JqowfVkcd6oSVmYrjn6t4TI6c,3616
61
61
  port_ocean/clients/port/mixins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
62
62
  port_ocean/clients/port/mixins/blueprints.py,sha256=aMCG4zePsMSMjMLiGrU37h5z5_ElfMzTcTvqvOI5wXY,4683
63
- port_ocean/clients/port/mixins/entities.py,sha256=X2NqH00eK6TMJ3a3QEQRVQlKHzyj5l1FiPkIhonnbPg,24234
63
+ port_ocean/clients/port/mixins/entities.py,sha256=UiVssYYqJeHhrLahx1mW24B7oGVMZV2WVvUze_htuBk,25279
64
64
  port_ocean/clients/port/mixins/integrations.py,sha256=8EhGms1_iOaAPEexmHGF4PJaSSL4O09GtXr_Q8UyaJI,12049
65
65
  port_ocean/clients/port/mixins/migrations.py,sha256=vdL_A_NNUogvzujyaRLIoZEu5vmKDY2BxTjoGP94YzI,1467
66
66
  port_ocean/clients/port/mixins/organization.py,sha256=A2cP5V49KnjoAXxjmnm_XGth4ftPSU0qURNfnyUyS_Y,1041
@@ -101,7 +101,7 @@ port_ocean/core/handlers/entities_state_applier/port/get_related_entities.py,sha
101
101
  port_ocean/core/handlers/entities_state_applier/port/order_by_entities_dependencies.py,sha256=lyv6xKzhYfd6TioUgR3AVRSJqj7JpAaj1LxxU2xAqeo,1720
102
102
  port_ocean/core/handlers/entity_processor/__init__.py,sha256=FvFCunFg44wNQoqlybem9MthOs7p1Wawac87uSXz9U8,156
103
103
  port_ocean/core/handlers/entity_processor/base.py,sha256=PsnpNRqjHth9xwOvDRe7gKu8cjnVV0XGmTIHGvOelX0,1867
104
- port_ocean/core/handlers/entity_processor/jq_entity_processor.py,sha256=VEL_aEme7gGrS0jvKgYMcBPIX02ntW7lT5V1KG12pJA,32003
104
+ port_ocean/core/handlers/entity_processor/jq_entity_processor.py,sha256=Z0njO1z2FUh8hX4GTdH7CmO0Afv-WeYRtxPs34mxKWE,32181
105
105
  port_ocean/core/handlers/entity_processor/jq_input_evaluator.py,sha256=hInrBMQBbOqZApB53CMLyTgLtC7FltRtqK9PqD0CgM0,4803
106
106
  port_ocean/core/handlers/port_app_config/__init__.py,sha256=8AAT5OthiVM7KCcM34iEgEeXtn2pRMrT4Dze5r1Ixbk,134
107
107
  port_ocean/core/handlers/port_app_config/api.py,sha256=r_Th66NEw38IpRdnXZcRvI8ACfvxW_A6V62WLwjWXlQ,1044
@@ -124,8 +124,8 @@ port_ocean/core/integrations/mixins/events.py,sha256=2L7P3Jhp8XBqddh2_o9Cn4N261n
124
124
  port_ocean/core/integrations/mixins/handler.py,sha256=mZ7-0UlG3LcrwJttFbMe-R4xcOU2H_g33tZar7PwTv8,3771
125
125
  port_ocean/core/integrations/mixins/live_events.py,sha256=zM24dhNc7uHx9XYZ6toVhDADPA90EnpOmZxgDegFZbA,4196
126
126
  port_ocean/core/integrations/mixins/sync.py,sha256=Vm_898pLKBwfVewtwouDWsXoxcOLicnAy6pzyqqk6U8,4053
127
- port_ocean/core/integrations/mixins/sync_raw.py,sha256=Zga3fSxALuXmAMKmIS0hZYWRe22lSGhiSVFWUCI4f1U,40972
128
- port_ocean/core/integrations/mixins/utils.py,sha256=vfKBwJFKI2zN5VgimOZQzCXE7bbpSCkBP8QT-9hJiBs,14516
127
+ port_ocean/core/integrations/mixins/sync_raw.py,sha256=TrdgwaCNbE-VEJBDRqWmLQR_1Epz6y5nEIbPaLZbe3A,41009
128
+ port_ocean/core/integrations/mixins/utils.py,sha256=hRIkvxw1bIfilq6n_2fqUiv_5OSKFMl6HmJfimH2hTA,14590
129
129
  port_ocean/core/models.py,sha256=DNbKpStMINI2lIekKprTqBevqkw_wFuFayN19w1aDfQ,2893
130
130
  port_ocean/core/ocean_types.py,sha256=bkLlTd8XfJK6_JDl0eXUHfE_NygqgiInSMwJ4YJH01Q,1399
131
131
  port_ocean/core/utils/entity_topological_sorter.py,sha256=MDUjM6OuDy4Xj68o-7InNN0w1jqjxeDfeY8U02vySNI,3081
@@ -162,7 +162,7 @@ port_ocean/tests/cache/test_memory_cache.py,sha256=xlwIOBU0RVLYYJU83l_aoZDzZ6QID
162
162
  port_ocean/tests/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
163
163
  port_ocean/tests/clients/oauth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
164
164
  port_ocean/tests/clients/oauth/test_oauth_client.py,sha256=2XVMQUalDpiD539Z7_dk5BK_ngXQzsTmb2lNBsfEm9c,3266
165
- port_ocean/tests/clients/port/mixins/test_entities.py,sha256=_ZEQT7UMzg1gW8kH8oFjgRVcLwQb7dFac48Tw_vcCqk,8018
165
+ port_ocean/tests/clients/port/mixins/test_entities.py,sha256=jOMJ3ICUlhjjPTo4q6qUrEjTKvXRLUE6KjqjdFiDRBY,10766
166
166
  port_ocean/tests/clients/port/mixins/test_integrations.py,sha256=vRt_EMsLozQC1LJNXxlvnHj3-FlOBGgAYxg5T0IAqtA,7621
167
167
  port_ocean/tests/clients/port/mixins/test_organization_mixin.py,sha256=zzKYz3h8dl4Z5A2QG_924m0y9U6XTth1XYOfwNrd_24,914
168
168
  port_ocean/tests/config/test_config.py,sha256=Rk4N-ldVSOfn1p23NzdVdfqUpPrqG2cMut4Sv-sAOrw,1023
@@ -211,8 +211,8 @@ port_ocean/utils/repeat.py,sha256=U2OeCkHPWXmRTVoPV-VcJRlQhcYqPWI5NfmPlb1JIbc,32
211
211
  port_ocean/utils/signal.py,sha256=J1sI-e_32VHP_VUa5bskLMFoJjJOAk5isrnewKDikUI,2125
212
212
  port_ocean/utils/time.py,sha256=pufAOH5ZQI7gXvOvJoQXZXZJV-Dqktoj9Qp9eiRwmJ4,1939
213
213
  port_ocean/version.py,sha256=UsuJdvdQlazzKGD3Hd5-U7N69STh8Dq9ggJzQFnu9fU,177
214
- port_ocean-0.28.14.dist-info/LICENSE.md,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
215
- port_ocean-0.28.14.dist-info/METADATA,sha256=_w_kDhykkm9LosWg6OOe8HhARPQXRoL4duh__TvB68U,7016
216
- port_ocean-0.28.14.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
217
- port_ocean-0.28.14.dist-info/entry_points.txt,sha256=F_DNUmGZU2Kme-8NsWM5LLE8piGMafYZygRYhOVtcjA,54
218
- port_ocean-0.28.14.dist-info/RECORD,,
214
+ port_ocean-0.28.16.dist-info/LICENSE.md,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
215
+ port_ocean-0.28.16.dist-info/METADATA,sha256=F6ugYDYHUDQt0YMZ8cghhxj4skE6nM8c7hBrf5GCqZE,7016
216
+ port_ocean-0.28.16.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
217
+ port_ocean-0.28.16.dist-info/entry_points.txt,sha256=F_DNUmGZU2Kme-8NsWM5LLE8piGMafYZygRYhOVtcjA,54
218
+ port_ocean-0.28.16.dist-info/RECORD,,