port-ocean 0.10.12__py3-none-any.whl → 0.12.0__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.
- port_ocean/core/handlers/entity_processor/jq_entity_processor.py +14 -7
- port_ocean/core/integrations/base.py +1 -1
- port_ocean/log/sensetive.py +1 -1
- port_ocean/ocean.py +2 -1
- port_ocean/tests/core/handlers/entity_processor/test_jq_entity_processor.py +236 -0
- port_ocean/tests/helpers/fixtures.py +13 -77
- port_ocean/tests/helpers/integration.py +31 -0
- port_ocean/tests/helpers/port_client.py +21 -0
- port_ocean/tests/helpers/smoke_test.py +82 -0
- port_ocean/tests/test_smoke.py +4 -1
- {port_ocean-0.10.12.dist-info → port_ocean-0.12.0.dist-info}/METADATA +2 -2
- {port_ocean-0.10.12.dist-info → port_ocean-0.12.0.dist-info}/RECORD +15 -12
- port_ocean/tests/test_sample.py +0 -2
- {port_ocean-0.10.12.dist-info → port_ocean-0.12.0.dist-info}/LICENSE.md +0 -0
- {port_ocean-0.10.12.dist-info → port_ocean-0.12.0.dist-info}/WHEEL +0 -0
- {port_ocean-0.10.12.dist-info → port_ocean-0.12.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
import functools
|
|
3
2
|
from asyncio import Task
|
|
4
3
|
from dataclasses import dataclass, field
|
|
5
4
|
from functools import lru_cache
|
|
6
5
|
from typing import Any, Optional
|
|
7
6
|
|
|
8
|
-
import
|
|
7
|
+
import jq # type: ignore
|
|
9
8
|
from loguru import logger
|
|
10
9
|
|
|
11
10
|
from port_ocean.context.ocean import ocean
|
|
@@ -52,8 +51,8 @@ class JQEntityProcessor(BaseEntityProcessor):
|
|
|
52
51
|
try:
|
|
53
52
|
loop = asyncio.get_event_loop()
|
|
54
53
|
compiled_pattern = self._compile(pattern)
|
|
55
|
-
|
|
56
|
-
return await loop.run_in_executor(None,
|
|
54
|
+
func = compiled_pattern.input_value(data)
|
|
55
|
+
return await loop.run_in_executor(None, func.first)
|
|
57
56
|
except Exception as exc:
|
|
58
57
|
logger.debug(
|
|
59
58
|
f"Failed to search for pattern {pattern} in data {data}, {exc}"
|
|
@@ -62,10 +61,18 @@ class JQEntityProcessor(BaseEntityProcessor):
|
|
|
62
61
|
|
|
63
62
|
async def _search_as_bool(self, data: dict[str, Any], pattern: str) -> bool:
|
|
64
63
|
loop = asyncio.get_event_loop()
|
|
64
|
+
start_time = loop.time()
|
|
65
65
|
compiled_pattern = self._compile(pattern)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
func = compiled_pattern.input_value(data)
|
|
67
|
+
compile_time = loop.time() - start_time
|
|
68
|
+
value = await loop.run_in_executor(None, func.first)
|
|
69
|
+
execute_time = loop.time() - start_time - compile_time
|
|
70
|
+
logger.debug(
|
|
71
|
+
f"Search for pattern {execute_time:.2f} seconds, compile time {compile_time:.2f} seconds",
|
|
72
|
+
pattern=pattern,
|
|
73
|
+
compile_time=compile_time,
|
|
74
|
+
execute_time=execute_time,
|
|
75
|
+
)
|
|
69
76
|
if isinstance(value, bool):
|
|
70
77
|
return value
|
|
71
78
|
|
|
@@ -54,7 +54,7 @@ class BaseIntegration(SyncRawMixin, SyncMixin):
|
|
|
54
54
|
"""
|
|
55
55
|
Initializes handlers, establishes integration at the specified port, and starts the event listener.
|
|
56
56
|
"""
|
|
57
|
-
logger.info("Starting integration")
|
|
57
|
+
logger.info("Starting integration", integration_type=self.context.config.integration.type)
|
|
58
58
|
if self.started:
|
|
59
59
|
raise IntegrationAlreadyStartedException("Integration already started")
|
|
60
60
|
|
port_ocean/log/sensetive.py
CHANGED
|
@@ -21,7 +21,7 @@ secret_patterns = {
|
|
|
21
21
|
"GitHub": r"[g|G][i|I][t|T][h|H][u|U][b|B].*['|\"][0-9a-zA-Z]{35,40}['|\"]",
|
|
22
22
|
"Google Cloud Platform API Key": r"AIza[0-9A-Za-z\\-_]{35}",
|
|
23
23
|
"Google Cloud Platform OAuth": r"[0-9]+-[0-9A-Za-z_]{32}\\.apps\\.googleusercontent\\.com",
|
|
24
|
-
"Google (GCP) Service-account":
|
|
24
|
+
"Google (GCP) Service-account": f'"type":{" "}"service_account"',
|
|
25
25
|
"Google OAuth Access Token": r"ya29\\.[0-9A-Za-z\\-_]+",
|
|
26
26
|
"Connection String": r"[a-zA-Z]+:\/\/[^/\s]+:[^/\s]+@[^/\s]+\/[^/\s]+",
|
|
27
27
|
}
|
port_ocean/ocean.py
CHANGED
|
@@ -96,7 +96,8 @@ class Ocean:
|
|
|
96
96
|
loop = asyncio.get_event_loop()
|
|
97
97
|
if interval is not None:
|
|
98
98
|
logger.info(
|
|
99
|
-
f"Setting up scheduled resync, the integration will automatically perform a full resync every {interval} minutes)"
|
|
99
|
+
f"Setting up scheduled resync, the integration will automatically perform a full resync every {interval} minutes)",
|
|
100
|
+
scheduled_interval=interval,
|
|
100
101
|
)
|
|
101
102
|
repeated_function = repeat_every(
|
|
102
103
|
seconds=interval * 60,
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
from unittest.mock import AsyncMock, Mock
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from port_ocean.context.ocean import PortOceanContext
|
|
6
|
+
from port_ocean.core.handlers.entity_processor.jq_entity_processor import (
|
|
7
|
+
JQEntityProcessor,
|
|
8
|
+
)
|
|
9
|
+
from port_ocean.core.ocean_types import CalculationResult
|
|
10
|
+
from port_ocean.exceptions.core import EntityProcessorException
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@pytest.mark.asyncio
|
|
14
|
+
class TestJQEntityProcessor:
|
|
15
|
+
|
|
16
|
+
@pytest.fixture
|
|
17
|
+
def mocked_processor(self, monkeypatch: Any) -> JQEntityProcessor:
|
|
18
|
+
mock_context = AsyncMock()
|
|
19
|
+
monkeypatch.setattr(PortOceanContext, "app", mock_context)
|
|
20
|
+
return JQEntityProcessor(mock_context)
|
|
21
|
+
|
|
22
|
+
async def test_compile(self, mocked_processor: JQEntityProcessor) -> None:
|
|
23
|
+
pattern = ".foo"
|
|
24
|
+
compiled = mocked_processor._compile(pattern)
|
|
25
|
+
assert compiled is not None
|
|
26
|
+
|
|
27
|
+
async def test_search(self, mocked_processor: JQEntityProcessor) -> None:
|
|
28
|
+
data = {"foo": "bar"}
|
|
29
|
+
pattern = ".foo"
|
|
30
|
+
result = await mocked_processor._search(data, pattern)
|
|
31
|
+
assert result == "bar"
|
|
32
|
+
|
|
33
|
+
async def test_search_as_bool(self, mocked_processor: JQEntityProcessor) -> None:
|
|
34
|
+
data = {"foo": True}
|
|
35
|
+
pattern = ".foo"
|
|
36
|
+
result = await mocked_processor._search_as_bool(data, pattern)
|
|
37
|
+
assert result is True
|
|
38
|
+
|
|
39
|
+
async def test_search_as_object(self, mocked_processor: JQEntityProcessor) -> None:
|
|
40
|
+
data = {"foo": {"bar": "baz"}}
|
|
41
|
+
obj = {"foo": ".foo.bar"}
|
|
42
|
+
result = await mocked_processor._search_as_object(data, obj)
|
|
43
|
+
assert result == {"foo": "baz"}
|
|
44
|
+
|
|
45
|
+
async def test_get_mapped_entity(self, mocked_processor: JQEntityProcessor) -> None:
|
|
46
|
+
data = {"foo": "bar"}
|
|
47
|
+
raw_entity_mappings = {"foo": ".foo"}
|
|
48
|
+
selector_query = '.foo == "bar"'
|
|
49
|
+
result = await mocked_processor._get_mapped_entity(
|
|
50
|
+
data, raw_entity_mappings, selector_query
|
|
51
|
+
)
|
|
52
|
+
assert result.entity == {"foo": "bar"}
|
|
53
|
+
assert result.did_entity_pass_selector is True
|
|
54
|
+
|
|
55
|
+
async def test_calculate_entity(self, mocked_processor: JQEntityProcessor) -> None:
|
|
56
|
+
data = {"foo": "bar"}
|
|
57
|
+
raw_entity_mappings = {"foo": ".foo"}
|
|
58
|
+
selector_query = '.foo == "bar"'
|
|
59
|
+
result, errors = await mocked_processor._calculate_entity(
|
|
60
|
+
data, raw_entity_mappings, None, selector_query
|
|
61
|
+
)
|
|
62
|
+
assert len(result) == 1
|
|
63
|
+
assert result[0].entity == {"foo": "bar"}
|
|
64
|
+
assert result[0].did_entity_pass_selector is True
|
|
65
|
+
assert not errors
|
|
66
|
+
|
|
67
|
+
async def test_parse_items(self, mocked_processor: JQEntityProcessor) -> None:
|
|
68
|
+
mapping = Mock()
|
|
69
|
+
mapping.port.entity.mappings.dict.return_value = {
|
|
70
|
+
"identifier": ".foo",
|
|
71
|
+
"blueprint": ".foo",
|
|
72
|
+
"properties": {"foo": ".foo"},
|
|
73
|
+
}
|
|
74
|
+
mapping.port.items_to_parse = None
|
|
75
|
+
mapping.selector.query = '.foo == "bar"'
|
|
76
|
+
raw_results = [{"foo": "bar"}]
|
|
77
|
+
result = await mocked_processor._parse_items(mapping, raw_results)
|
|
78
|
+
assert isinstance(result, CalculationResult)
|
|
79
|
+
assert len(result.entity_selector_diff.passed) == 1
|
|
80
|
+
assert result.entity_selector_diff.passed[0].properties.get("foo") == "bar"
|
|
81
|
+
assert not result.errors
|
|
82
|
+
|
|
83
|
+
async def test_in_operator(self, mocked_processor: JQEntityProcessor) -> None:
|
|
84
|
+
data = {
|
|
85
|
+
"key": "GetPort_SelfService",
|
|
86
|
+
"name": "GetPort SelfService",
|
|
87
|
+
"desc": "Test",
|
|
88
|
+
"qualifier": "VW",
|
|
89
|
+
"visibility": "public",
|
|
90
|
+
"selectionMode": "NONE",
|
|
91
|
+
"subViews": [
|
|
92
|
+
{
|
|
93
|
+
"key": "GetPort_SelfService_Second",
|
|
94
|
+
"name": "GetPort SelfService Second",
|
|
95
|
+
"qualifier": "SVW",
|
|
96
|
+
"selectionMode": "NONE",
|
|
97
|
+
"subViews": [
|
|
98
|
+
{
|
|
99
|
+
"key": "GetPort_SelfService_Third",
|
|
100
|
+
"name": "GetPort SelfService Third",
|
|
101
|
+
"qualifier": "SVW",
|
|
102
|
+
"selectionMode": "NONE",
|
|
103
|
+
"subViews": [],
|
|
104
|
+
"referencedBy": [],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"key": "Port_Test",
|
|
108
|
+
"name": "Port Test",
|
|
109
|
+
"qualifier": "SVW",
|
|
110
|
+
"selectionMode": "NONE",
|
|
111
|
+
"subViews": [],
|
|
112
|
+
"referencedBy": [],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
"referencedBy": [],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"key": "Python",
|
|
119
|
+
"name": "Python",
|
|
120
|
+
"qualifier": "SVW",
|
|
121
|
+
"selectionMode": "NONE",
|
|
122
|
+
"subViews": [
|
|
123
|
+
{
|
|
124
|
+
"key": "Time",
|
|
125
|
+
"name": "Time",
|
|
126
|
+
"qualifier": "SVW",
|
|
127
|
+
"selectionMode": "NONE",
|
|
128
|
+
"subViews": [
|
|
129
|
+
{
|
|
130
|
+
"key": "port_*****",
|
|
131
|
+
"name": "port-*****",
|
|
132
|
+
"qualifier": "SVW",
|
|
133
|
+
"selectionMode": "NONE",
|
|
134
|
+
"subViews": [
|
|
135
|
+
{
|
|
136
|
+
"key": "port_*****:REferenced",
|
|
137
|
+
"name": "REferenced",
|
|
138
|
+
"qualifier": "VW",
|
|
139
|
+
"visibility": "public",
|
|
140
|
+
"originalKey": "REferenced",
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
"referencedBy": [],
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"referencedBy": [],
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
"referencedBy": [],
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"key": "GetPort_SelfService:Authentication_Application",
|
|
153
|
+
"name": "Authentication Application",
|
|
154
|
+
"desc": "For auth services",
|
|
155
|
+
"qualifier": "APP",
|
|
156
|
+
"visibility": "private",
|
|
157
|
+
"selectedBranches": ["main"],
|
|
158
|
+
"originalKey": "Authentication_Application",
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
"referencedBy": [],
|
|
162
|
+
}
|
|
163
|
+
pattern = '.subViews | map(select((.qualifier | IN("VW", "SVW"))) | .key)'
|
|
164
|
+
result = await mocked_processor._search(data, pattern)
|
|
165
|
+
assert result == ["GetPort_SelfService_Second", "Python"]
|
|
166
|
+
|
|
167
|
+
async def test_failure_of_jq_expression(
|
|
168
|
+
self, mocked_processor: JQEntityProcessor
|
|
169
|
+
) -> None:
|
|
170
|
+
data = {"foo": "bar"}
|
|
171
|
+
pattern = ".foo."
|
|
172
|
+
result = await mocked_processor._search(data, pattern)
|
|
173
|
+
assert result is None
|
|
174
|
+
|
|
175
|
+
async def test_search_as_object_failure(
|
|
176
|
+
self, mocked_processor: JQEntityProcessor
|
|
177
|
+
) -> None:
|
|
178
|
+
data = {"foo": {"bar": "baz"}}
|
|
179
|
+
obj = {"foo": ".foo.bar."}
|
|
180
|
+
result = await mocked_processor._search_as_object(data, obj)
|
|
181
|
+
assert result == {"foo": None}
|
|
182
|
+
|
|
183
|
+
async def test_double_quotes_in_jq_expression(
|
|
184
|
+
self, mocked_processor: JQEntityProcessor
|
|
185
|
+
) -> None:
|
|
186
|
+
data = {"foo": "bar"}
|
|
187
|
+
pattern = '"shalom"'
|
|
188
|
+
result = await mocked_processor._search(data, pattern)
|
|
189
|
+
assert result == "shalom"
|
|
190
|
+
|
|
191
|
+
async def test_search_as_bool_failure(
|
|
192
|
+
self, mocked_processor: JQEntityProcessor
|
|
193
|
+
) -> None:
|
|
194
|
+
data = {"foo": "bar"}
|
|
195
|
+
pattern = ".foo"
|
|
196
|
+
with pytest.raises(
|
|
197
|
+
EntityProcessorException,
|
|
198
|
+
match="Expected boolean value, got <class 'str'> instead",
|
|
199
|
+
):
|
|
200
|
+
await mocked_processor._search_as_bool(data, pattern)
|
|
201
|
+
|
|
202
|
+
@pytest.mark.timeout(3)
|
|
203
|
+
async def test_search_performance_10000(
|
|
204
|
+
self, mocked_processor: JQEntityProcessor
|
|
205
|
+
) -> None:
|
|
206
|
+
"""
|
|
207
|
+
This test is to check the performance of the search method when called 10000 times.
|
|
208
|
+
"""
|
|
209
|
+
data = {"foo": "bar"}
|
|
210
|
+
pattern = ".foo"
|
|
211
|
+
for _ in range(10000):
|
|
212
|
+
result = await mocked_processor._search(data, pattern)
|
|
213
|
+
assert result == "bar"
|
|
214
|
+
|
|
215
|
+
@pytest.mark.timeout(15)
|
|
216
|
+
async def test_parse_items_performance_10000(
|
|
217
|
+
self, mocked_processor: JQEntityProcessor
|
|
218
|
+
) -> None:
|
|
219
|
+
"""
|
|
220
|
+
This test is to check the performance of the parse_items method when called 10000 times.
|
|
221
|
+
"""
|
|
222
|
+
mapping = Mock()
|
|
223
|
+
mapping.port.entity.mappings.dict.return_value = {
|
|
224
|
+
"identifier": ".foo",
|
|
225
|
+
"blueprint": ".foo",
|
|
226
|
+
"properties": {"foo": ".foo"},
|
|
227
|
+
}
|
|
228
|
+
mapping.port.items_to_parse = None
|
|
229
|
+
mapping.selector.query = '.foo == "bar"'
|
|
230
|
+
raw_results = [{"foo": "bar"}]
|
|
231
|
+
for _ in range(10000):
|
|
232
|
+
result = await mocked_processor._parse_items(mapping, raw_results)
|
|
233
|
+
assert isinstance(result, CalculationResult)
|
|
234
|
+
assert len(result.entity_selector_diff.passed) == 1
|
|
235
|
+
assert result.entity_selector_diff.passed[0].properties.get("foo") == "bar"
|
|
236
|
+
assert not result.errors
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from os import
|
|
2
|
-
from typing import Any,
|
|
1
|
+
from os import path
|
|
2
|
+
from typing import Any, Callable, List, Tuple
|
|
3
3
|
|
|
4
|
+
import pytest
|
|
4
5
|
import pytest_asyncio
|
|
5
|
-
from pydantic import BaseModel
|
|
6
6
|
|
|
7
7
|
from port_ocean.clients.port.client import PortClient
|
|
8
8
|
from port_ocean.core.handlers.port_app_config.models import ResourceConfig
|
|
@@ -11,83 +11,19 @@ from port_ocean.tests.helpers.ocean_app import (
|
|
|
11
11
|
get_integation_resource_configs,
|
|
12
12
|
get_integration_ocean_app,
|
|
13
13
|
)
|
|
14
|
+
from port_ocean.tests.helpers.smoke_test import (
|
|
15
|
+
SmokeTestDetails,
|
|
16
|
+
get_port_client_for_fake_integration,
|
|
17
|
+
get_smoke_test_details,
|
|
18
|
+
)
|
|
14
19
|
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
integration_type: str,
|
|
21
|
-
integration_version: str,
|
|
22
|
-
base_url: Union[str, None],
|
|
23
|
-
) -> PortClient:
|
|
24
|
-
return PortClient(
|
|
25
|
-
base_url=base_url or "https://api.getport/io",
|
|
26
|
-
client_id=client_id,
|
|
27
|
-
client_secret=client_secret,
|
|
28
|
-
integration_identifier=integration_identifier,
|
|
29
|
-
integration_type=integration_type,
|
|
30
|
-
integration_version=integration_version,
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
async def cleanup_integration(client: PortClient, blueprints: List[str]) -> None:
|
|
35
|
-
for blueprint in blueprints:
|
|
36
|
-
bp = await client.get_blueprint(blueprint)
|
|
37
|
-
if bp is not None:
|
|
38
|
-
migration_id = await client.delete_blueprint(
|
|
39
|
-
identifier=blueprint, delete_entities=True
|
|
40
|
-
)
|
|
41
|
-
if migration_id:
|
|
42
|
-
await client.wait_for_migration_to_complete(migration_id=migration_id)
|
|
43
|
-
headers = await client.auth.headers()
|
|
44
|
-
await client.client.delete(f"{client.auth.api_url}/integrations", headers=headers)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
class SmokeTestDetails(BaseModel):
|
|
48
|
-
integration_identifier: str
|
|
49
|
-
blueprint_department: str
|
|
50
|
-
blueprint_person: str
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@pytest_asyncio.fixture()
|
|
54
|
-
async def port_client_for_fake_integration() -> (
|
|
55
|
-
AsyncGenerator[Tuple[SmokeTestDetails, PortClient], None]
|
|
56
|
-
):
|
|
57
|
-
blueprint_department = "fake-department"
|
|
58
|
-
blueprint_person = "fake-person"
|
|
59
|
-
integration_identifier = "smoke-test-integration"
|
|
60
|
-
smoke_test_suffix = environ.get("SMOKE_TEST_SUFFIX")
|
|
61
|
-
client_id = environ.get("PORT_CLIENT_ID")
|
|
62
|
-
client_secret = environ.get("PORT_CLIENT_SECRET")
|
|
63
|
-
|
|
64
|
-
if not client_secret or not client_id:
|
|
65
|
-
assert False, "Missing port credentials"
|
|
66
|
-
|
|
67
|
-
base_url = environ.get("PORT_BASE_URL")
|
|
68
|
-
integration_version = "0.1.1-dev"
|
|
69
|
-
integration_type = "smoke-test"
|
|
70
|
-
if smoke_test_suffix is not None:
|
|
71
|
-
integration_identifier = f"{integration_identifier}-{smoke_test_suffix}"
|
|
72
|
-
blueprint_person = f"{blueprint_person}-{smoke_test_suffix}"
|
|
73
|
-
blueprint_department = f"{blueprint_department}-{smoke_test_suffix}"
|
|
74
|
-
|
|
75
|
-
client = get_port_client_for_integration(
|
|
76
|
-
client_id,
|
|
77
|
-
client_secret,
|
|
78
|
-
integration_identifier,
|
|
79
|
-
integration_type,
|
|
80
|
-
integration_version,
|
|
81
|
-
base_url,
|
|
82
|
-
)
|
|
21
|
+
@pytest.fixture
|
|
22
|
+
def port_client_for_fake_integration() -> Tuple[SmokeTestDetails, PortClient]:
|
|
23
|
+
smoke_test_details = get_smoke_test_details()
|
|
24
|
+
port_client = get_port_client_for_fake_integration()
|
|
83
25
|
|
|
84
|
-
smoke_test_details
|
|
85
|
-
integration_identifier=integration_identifier,
|
|
86
|
-
blueprint_person=blueprint_person,
|
|
87
|
-
blueprint_department=blueprint_department,
|
|
88
|
-
)
|
|
89
|
-
yield smoke_test_details, client
|
|
90
|
-
await cleanup_integration(client, [blueprint_department, blueprint_person])
|
|
26
|
+
return smoke_test_details, port_client
|
|
91
27
|
|
|
92
28
|
|
|
93
29
|
@pytest_asyncio.fixture
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from loguru import logger
|
|
4
|
+
|
|
5
|
+
from port_ocean.clients.port.client import PortClient
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
async def cleanup_integration(client: PortClient, blueprints: List[str]) -> None:
|
|
9
|
+
for blueprint in blueprints:
|
|
10
|
+
try:
|
|
11
|
+
bp = await client.get_blueprint(blueprint)
|
|
12
|
+
if bp is not None:
|
|
13
|
+
migration_id = await client.delete_blueprint(
|
|
14
|
+
identifier=blueprint, delete_entities=True
|
|
15
|
+
)
|
|
16
|
+
if migration_id:
|
|
17
|
+
await client.wait_for_migration_to_complete(
|
|
18
|
+
migration_id=migration_id
|
|
19
|
+
)
|
|
20
|
+
except Exception as bp_e:
|
|
21
|
+
logger.info(f"Skipping missing blueprint ({blueprint}): {bp_e}")
|
|
22
|
+
headers = await client.auth.headers()
|
|
23
|
+
try:
|
|
24
|
+
await client.client.delete(
|
|
25
|
+
f"{client.auth.api_url}/integrations/{client.integration_identifier}",
|
|
26
|
+
headers=headers,
|
|
27
|
+
)
|
|
28
|
+
except Exception as int_e:
|
|
29
|
+
logger.info(
|
|
30
|
+
f"Failed to delete integration ({client.integration_identifier}): {int_e}"
|
|
31
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
from port_ocean.clients.port.client import PortClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_port_client_for_integration(
|
|
7
|
+
client_id: str,
|
|
8
|
+
client_secret: str,
|
|
9
|
+
integration_identifier: str,
|
|
10
|
+
integration_type: str,
|
|
11
|
+
integration_version: str,
|
|
12
|
+
base_url: Union[str, None],
|
|
13
|
+
) -> PortClient:
|
|
14
|
+
return PortClient(
|
|
15
|
+
base_url=base_url or "https://api.getport/io",
|
|
16
|
+
client_id=client_id,
|
|
17
|
+
client_secret=client_secret,
|
|
18
|
+
integration_identifier=integration_identifier,
|
|
19
|
+
integration_type=integration_type,
|
|
20
|
+
integration_version=integration_version,
|
|
21
|
+
)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from os import environ
|
|
2
|
+
from port_ocean.clients.port.client import PortClient
|
|
3
|
+
|
|
4
|
+
from loguru import logger
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
from port_ocean.tests.helpers.integration import cleanup_integration
|
|
8
|
+
from port_ocean.tests.helpers.port_client import get_port_client_for_integration
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SmokeTestDetails(BaseModel):
|
|
12
|
+
integration_identifier: str
|
|
13
|
+
blueprint_department: str
|
|
14
|
+
blueprint_person: str
|
|
15
|
+
integration_type: str
|
|
16
|
+
integration_version: str
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_smoke_test_details() -> SmokeTestDetails:
|
|
20
|
+
blueprint_department = "fake-department"
|
|
21
|
+
blueprint_person = "fake-person"
|
|
22
|
+
integration_identifier = "smoke-test-integration"
|
|
23
|
+
smoke_test_suffix = environ.get("SMOKE_TEST_SUFFIX")
|
|
24
|
+
if smoke_test_suffix is not None:
|
|
25
|
+
integration_identifier = f"{integration_identifier}-{smoke_test_suffix}"
|
|
26
|
+
blueprint_person = f"{blueprint_person}-{smoke_test_suffix}"
|
|
27
|
+
blueprint_department = f"{blueprint_department}-{smoke_test_suffix}"
|
|
28
|
+
|
|
29
|
+
return SmokeTestDetails(
|
|
30
|
+
integration_identifier=integration_identifier,
|
|
31
|
+
blueprint_person=blueprint_person,
|
|
32
|
+
blueprint_department=blueprint_department,
|
|
33
|
+
integration_version="0.1.4-dev",
|
|
34
|
+
integration_type="smoke-test",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
async def cleanup_smoke_test() -> None:
|
|
39
|
+
smoke_test_details = get_smoke_test_details()
|
|
40
|
+
client_id = environ.get("PORT_CLIENT_ID")
|
|
41
|
+
client_secret = environ.get("PORT_CLIENT_SECRET")
|
|
42
|
+
|
|
43
|
+
if not client_secret or not client_id:
|
|
44
|
+
assert False, "Missing port credentials"
|
|
45
|
+
|
|
46
|
+
base_url = environ.get("PORT_BASE_URL")
|
|
47
|
+
client = get_port_client_for_integration(
|
|
48
|
+
client_id,
|
|
49
|
+
client_secret,
|
|
50
|
+
smoke_test_details.integration_identifier,
|
|
51
|
+
smoke_test_details.integration_type,
|
|
52
|
+
smoke_test_details.integration_version,
|
|
53
|
+
base_url,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
logger.info("Cleaning up fake integration")
|
|
57
|
+
await cleanup_integration(
|
|
58
|
+
client,
|
|
59
|
+
[smoke_test_details.blueprint_department, smoke_test_details.blueprint_person],
|
|
60
|
+
)
|
|
61
|
+
logger.info("Cleaning up fake integration complete")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def get_port_client_for_fake_integration() -> PortClient:
|
|
65
|
+
smoke_test_details = get_smoke_test_details()
|
|
66
|
+
client_id = environ.get("PORT_CLIENT_ID")
|
|
67
|
+
client_secret = environ.get("PORT_CLIENT_SECRET")
|
|
68
|
+
|
|
69
|
+
if not client_secret or not client_id:
|
|
70
|
+
assert False, "Missing port credentials"
|
|
71
|
+
|
|
72
|
+
base_url = environ.get("PORT_BASE_URL")
|
|
73
|
+
client = get_port_client_for_integration(
|
|
74
|
+
client_id,
|
|
75
|
+
client_secret,
|
|
76
|
+
smoke_test_details.integration_identifier,
|
|
77
|
+
smoke_test_details.integration_type,
|
|
78
|
+
smoke_test_details.integration_version,
|
|
79
|
+
base_url,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
return client
|
port_ocean/tests/test_smoke.py
CHANGED
|
@@ -4,7 +4,10 @@ import pytest
|
|
|
4
4
|
|
|
5
5
|
from port_ocean.clients.port.client import PortClient
|
|
6
6
|
from port_ocean.clients.port.types import UserAgentType
|
|
7
|
-
from port_ocean.tests.helpers.
|
|
7
|
+
from port_ocean.tests.helpers.smoke_test import SmokeTestDetails
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
pytestmark = pytest.mark.smoke
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
@pytest.mark.skipif(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: port-ocean
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.0
|
|
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
|
|
@@ -28,11 +28,11 @@ Requires-Dist: cookiecutter (>=2.1.1,<3.0.0) ; extra == "cli"
|
|
|
28
28
|
Requires-Dist: fastapi (>=0.100,<0.112)
|
|
29
29
|
Requires-Dist: httpx (>=0.24.1,<0.28.0)
|
|
30
30
|
Requires-Dist: jinja2-time (>=0.2.0,<0.3.0) ; extra == "cli"
|
|
31
|
+
Requires-Dist: jq (>=1.8.0,<2.0.0)
|
|
31
32
|
Requires-Dist: loguru (>=0.7.0,<0.8.0)
|
|
32
33
|
Requires-Dist: pydantic[dotenv] (>=1.10.8,<2.0.0)
|
|
33
34
|
Requires-Dist: pydispatcher (>=2.0.7,<3.0.0)
|
|
34
35
|
Requires-Dist: pyhumps (>=3.8.0,<4.0.0)
|
|
35
|
-
Requires-Dist: pyjq (>=2.6.0,<3.0.0)
|
|
36
36
|
Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
|
|
37
37
|
Requires-Dist: pyyaml (>=6.0,<7.0)
|
|
38
38
|
Requires-Dist: rich (>=13.4.1,<14.0.0) ; extra == "cli"
|
|
@@ -81,7 +81,7 @@ port_ocean/core/handlers/entities_state_applier/port/get_related_entities.py,sha
|
|
|
81
81
|
port_ocean/core/handlers/entities_state_applier/port/order_by_entities_dependencies.py,sha256=82BvU8t5w9uhsxX8hbnwuRPuWhW3cMeuT_5sVIkip1I,1550
|
|
82
82
|
port_ocean/core/handlers/entity_processor/__init__.py,sha256=FvFCunFg44wNQoqlybem9MthOs7p1Wawac87uSXz9U8,156
|
|
83
83
|
port_ocean/core/handlers/entity_processor/base.py,sha256=udR0w5TstTOS5xOfTjAZIEdldn4xr6Oyb3DylatYX3Q,1869
|
|
84
|
-
port_ocean/core/handlers/entity_processor/jq_entity_processor.py,sha256=
|
|
84
|
+
port_ocean/core/handlers/entity_processor/jq_entity_processor.py,sha256=HQ3lnOqNITHxSn0_9TXZFaQYfMZvvPaJwnsvlNKGDKQ,8703
|
|
85
85
|
port_ocean/core/handlers/port_app_config/__init__.py,sha256=8AAT5OthiVM7KCcM34iEgEeXtn2pRMrT4Dze5r1Ixbk,134
|
|
86
86
|
port_ocean/core/handlers/port_app_config/api.py,sha256=6VbKPwFzsWG0IYsVD81hxSmfqtHUFqrfUuj1DBX5g4w,853
|
|
87
87
|
port_ocean/core/handlers/port_app_config/base.py,sha256=4Nxt2g8voEIHJ4Y1Km5NJcaG2iSbCklw5P8-Kus7Y9k,3007
|
|
@@ -89,7 +89,7 @@ port_ocean/core/handlers/port_app_config/models.py,sha256=YvYtf_44KD_rN4xK-3xHtd
|
|
|
89
89
|
port_ocean/core/handlers/resync_state_updater/__init__.py,sha256=kG6y-JQGpPfuTHh912L_bctIDCzAK4DN-d00S7rguWU,81
|
|
90
90
|
port_ocean/core/handlers/resync_state_updater/updater.py,sha256=Yg9ET6ZV5B9GW7u6zZA6GlB_71kmvxvYX2FWgQNzMvo,3182
|
|
91
91
|
port_ocean/core/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
92
|
-
port_ocean/core/integrations/base.py,sha256=
|
|
92
|
+
port_ocean/core/integrations/base.py,sha256=JxqQApEf7phi_Q_b4U0mKNomxIPdDyKPq3AbApFmhjU,3007
|
|
93
93
|
port_ocean/core/integrations/mixins/__init__.py,sha256=FA1FEKMM6P-L2_m7Q4L20mFa4_RgZnwSRmTCreKcBVM,220
|
|
94
94
|
port_ocean/core/integrations/mixins/events.py,sha256=Ddfx2L4FpghV38waF8OfVeOV0bHBxNIgjU-q5ffillI,2341
|
|
95
95
|
port_ocean/core/integrations/mixins/handler.py,sha256=mZ7-0UlG3LcrwJttFbMe-R4xcOU2H_g33tZar7PwTv8,3771
|
|
@@ -113,20 +113,23 @@ port_ocean/helpers/retry.py,sha256=IQ0RfQ2T5o6uoZh2WW2nrFH5TT6K_k3y2Im0HDp5j9Y,1
|
|
|
113
113
|
port_ocean/log/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
114
114
|
port_ocean/log/handlers.py,sha256=k9G_Mb4ga2-Jke9irpdlYqj6EYiwv0gEsh4TgyqqOmI,2853
|
|
115
115
|
port_ocean/log/logger_setup.py,sha256=BaXt-mh9CVXhneh37H46d04lqOdIBixG1pFyGfotuZs,2328
|
|
116
|
-
port_ocean/log/sensetive.py,sha256=
|
|
116
|
+
port_ocean/log/sensetive.py,sha256=lVKiZH6b7TkrZAMmhEJRhcl67HNM94e56x12DwFgCQk,2920
|
|
117
117
|
port_ocean/middlewares.py,sha256=9wYCdyzRZGK1vjEJ28FY_DkfwDNENmXp504UKPf5NaQ,2727
|
|
118
|
-
port_ocean/ocean.py,sha256=
|
|
118
|
+
port_ocean/ocean.py,sha256=Oe4H3kKtkj52uNO4Rd_47iY3MBdrTtshXZ_16q7A8bM,5071
|
|
119
119
|
port_ocean/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
120
120
|
port_ocean/run.py,sha256=rTxBlrQd4yyrtgErCFJCHCEHs7d1OXrRiJehUYmIbN0,2212
|
|
121
121
|
port_ocean/sonar-project.properties,sha256=X_wLzDOkEVmpGLRMb2fg9Rb0DxWwUFSvESId8qpvrPI,73
|
|
122
122
|
port_ocean/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
123
123
|
port_ocean/tests/clients/port/mixins/test_entities.py,sha256=A9myrnkLhKSQrnOLv1Zz2wiOVSxW65Q9RIUIRbn_V7w,1586
|
|
124
124
|
port_ocean/tests/conftest.py,sha256=JXASSS0IY0nnR6bxBflhzxS25kf4iNaABmThyZ0mZt8,101
|
|
125
|
+
port_ocean/tests/core/handlers/entity_processor/test_jq_entity_processor.py,sha256=fqhlLTFkP0SS12bqViYWgqayNGXWZhqpDSJObHVRnNg,9472
|
|
125
126
|
port_ocean/tests/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
126
|
-
port_ocean/tests/helpers/fixtures.py,sha256=
|
|
127
|
+
port_ocean/tests/helpers/fixtures.py,sha256=blc4ZgPEkKOmmwT6GVxceS9r1ERUwSdOIBGxWFwvRyY,1398
|
|
128
|
+
port_ocean/tests/helpers/integration.py,sha256=_RxS-RHpu11lrbhUXYPZp862HLWx8AoD7iZM6iXN8rs,1104
|
|
127
129
|
port_ocean/tests/helpers/ocean_app.py,sha256=Dp1bwEDhWsx_G-KVxOfJX1eVIS4168ajLu39wAY275g,1693
|
|
128
|
-
port_ocean/tests/
|
|
129
|
-
port_ocean/tests/
|
|
130
|
+
port_ocean/tests/helpers/port_client.py,sha256=5d6GNr8vNNSOkrz1AdOhxBUKuusr_-UPDP7AVpHasQw,599
|
|
131
|
+
port_ocean/tests/helpers/smoke_test.py,sha256=_9aJJFRfuGJEg2D2YQJVJRmpreS6gEPHHQq8Q01x4aQ,2697
|
|
132
|
+
port_ocean/tests/test_smoke.py,sha256=uix2uIg_yOm8BHDgHw2hTFPy1fiIyxBGW3ENU_KoFlo,2557
|
|
130
133
|
port_ocean/utils/__init__.py,sha256=KMGnCPXZJbNwtgxtyMycapkDz8tpSyw23MSYT3iVeHs,91
|
|
131
134
|
port_ocean/utils/async_http.py,sha256=arnH458TExn2Dju_Sy6pHas_vF5RMWnOp-jBz5WAAcE,1226
|
|
132
135
|
port_ocean/utils/async_iterators.py,sha256=iw3cUHxfQm3zUSPdw2FmSXDU8E1Ppnys4TGhswNuQ8s,1569
|
|
@@ -137,8 +140,8 @@ port_ocean/utils/repeat.py,sha256=0EFWM9d8lLXAhZmAyczY20LAnijw6UbIECf5lpGbOas,32
|
|
|
137
140
|
port_ocean/utils/signal.py,sha256=K-6kKFQTltcmKDhtyZAcn0IMa3sUpOHGOAUdWKgx0_E,1369
|
|
138
141
|
port_ocean/utils/time.py,sha256=pufAOH5ZQI7gXvOvJoQXZXZJV-Dqktoj9Qp9eiRwmJ4,1939
|
|
139
142
|
port_ocean/version.py,sha256=UsuJdvdQlazzKGD3Hd5-U7N69STh8Dq9ggJzQFnu9fU,177
|
|
140
|
-
port_ocean-0.
|
|
141
|
-
port_ocean-0.
|
|
142
|
-
port_ocean-0.
|
|
143
|
-
port_ocean-0.
|
|
144
|
-
port_ocean-0.
|
|
143
|
+
port_ocean-0.12.0.dist-info/LICENSE.md,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
|
144
|
+
port_ocean-0.12.0.dist-info/METADATA,sha256=PrJZo5rBOy6h2_slD1tjSHcTdHCc-PgyIsk9DNqk0pY,6614
|
|
145
|
+
port_ocean-0.12.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
146
|
+
port_ocean-0.12.0.dist-info/entry_points.txt,sha256=F_DNUmGZU2Kme-8NsWM5LLE8piGMafYZygRYhOVtcjA,54
|
|
147
|
+
port_ocean-0.12.0.dist-info/RECORD,,
|
port_ocean/tests/test_sample.py
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|