port-ocean 0.12.2.dev21__py3-none-any.whl → 0.12.2.dev23__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,6 +1,7 @@
1
1
  from typing import Callable, TYPE_CHECKING, Any, Literal, Union
2
2
 
3
3
  from pydantic.main import BaseModel
4
+ from starlette.routing import Router
4
5
  from werkzeug.local import LocalProxy
5
6
 
6
7
  from port_ocean.clients.port.types import UserAgentType
@@ -43,6 +44,10 @@ class PortOceanContext:
43
44
  def config(self) -> "IntegrationConfiguration":
44
45
  return self.app.config
45
46
 
47
+ @property
48
+ def router(self) -> Router:
49
+ return self.app.integration_router
50
+
46
51
  @property
47
52
  def integration(self) -> "BaseIntegration":
48
53
  return self.app.integration
port_ocean/ocean.py CHANGED
@@ -1,13 +1,17 @@
1
1
  import asyncio
2
+ import contextlib
2
3
  import sys
3
4
  import threading
4
- from typing import Callable, Any, Dict, Type
5
+ from typing import Callable, Any, Dict, AsyncIterator, Type
5
6
 
7
+ from fastapi import FastAPI, APIRouter
6
8
  from loguru import logger
7
9
  from pydantic import BaseModel
10
+ from starlette.applications import Starlette
8
11
  from starlette.middleware import Middleware
12
+ from starlette.requests import Request
9
13
  from starlette.responses import JSONResponse
10
- from starlette.routing import Route
14
+ from starlette.routing import Route, Mount, Router
11
15
  from starlette.types import Scope, Receive, Send
12
16
 
13
17
  from port_ocean.clients.port.client import PortClient
@@ -27,9 +31,6 @@ from port_ocean.middlewares import RequestHandlerMiddleware
27
31
  from port_ocean.utils.repeat import repeat_every
28
32
  from port_ocean.utils.signal import signal_handler
29
33
  from port_ocean.version import __integration_version__
30
- import contextlib
31
-
32
- from starlette.applications import Starlette
33
34
 
34
35
 
35
36
  class Ocean:
@@ -37,35 +38,14 @@ class Ocean:
37
38
  self,
38
39
  app: Starlette | None = None,
39
40
  integration_class: Callable[[PortOceanContext], BaseIntegration] | None = None,
40
- integration_router: None = None,
41
+ integration_router: Router | None = None,
41
42
  config_factory: Type[BaseModel] | None = None,
42
43
  config_override: Dict[str, Any] | None = None,
43
44
  ):
44
45
  initialize_port_ocean_context(self)
45
46
 
46
- @contextlib.asynccontextmanager
47
- async def lifespan(app):
48
- try:
49
- await self.integration.start()
50
- await self._setup_scheduled_resync()
51
- yield None
52
- except Exception:
53
- logger.exception("Integration had a fatal error. Shutting down.")
54
- sys.exit("Server stopped")
55
- finally:
56
- signal_handler.exit()
57
-
58
- async def handle_webhook_request(data: dict[str, Any]) -> dict[str, Any]:
59
- return JSONResponse({"ok": True})
60
-
61
- self.starlette_app = Starlette(
62
- routes=[
63
- Route("/docs", endpoint=handle_webhook_request),
64
- Route("/integration/webhook", endpoint=handle_webhook_request),
65
- ],
66
- # middleware=[Middleware(RequestHandlerMiddleware)],
67
- lifespan=lifespan,
68
- )
47
+ self.starlette_app = app or Starlette()
48
+ self.integration_router = integration_router or Router()
69
49
 
70
50
  self.config = IntegrationConfiguration(
71
51
  # type: ignore
@@ -137,4 +117,28 @@ class Ocean:
137
117
  await repeated_function()
138
118
 
139
119
  async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
120
+ @contextlib.asynccontextmanager
121
+ async def lifespan(_: FastAPI) -> AsyncIterator[None]:
122
+ try:
123
+ await self.integration.start()
124
+ await self._setup_scheduled_resync()
125
+ yield None
126
+ except Exception:
127
+ logger.exception("Integration had a fatal error. Shutting down.")
128
+ sys.exit("Server stopped")
129
+ finally:
130
+ signal_handler.exit()
131
+
132
+ async def health(request: Request) -> JSONResponse:
133
+ return JSONResponse({"ok": True})
134
+
135
+ self.starlette_app = Starlette(
136
+ routes=[
137
+ Route("/docs", endpoint=health),
138
+ Mount("/integration", routes=self.integration_router.routes),
139
+ ],
140
+ middleware=[Middleware(RequestHandlerMiddleware)],
141
+ lifespan=lifespan,
142
+ )
143
+
140
144
  await self.starlette_app(scope, receive, send)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: port-ocean
3
- Version: 0.12.2.dev21
3
+ Version: 0.12.2.dev23
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
@@ -57,7 +57,7 @@ port_ocean/consumers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
57
57
  port_ocean/consumers/kafka_consumer.py,sha256=N8KocjBi9aR0BOPG8hgKovg-ns_ggpEjrSxqSqF_BSo,4710
58
58
  port_ocean/context/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
59
59
  port_ocean/context/event.py,sha256=WduGbCPgm2J2a63EY4J3XWwFGSt3ja1acBVpyI_ciMo,5430
60
- port_ocean/context/ocean.py,sha256=0NQj6nPCAYAKvYgb00zRDz88_7BDUR04-dFsA2XBXQE,4534
60
+ port_ocean/context/ocean.py,sha256=UDlsk6CUCRLb0Oc01piU3CdtG9LpBcw-yswk8DtiDAw,4661
61
61
  port_ocean/context/resource.py,sha256=yDj63URzQelj8zJPh4BAzTtPhpKr9Gw9DRn7I_0mJ1s,1692
62
62
  port_ocean/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
63
63
  port_ocean/core/defaults/__init__.py,sha256=8qCZg8n06WAdMu9s_FiRtDYLGPGHbOuS60vapeUoAks,142
@@ -115,7 +115,7 @@ port_ocean/log/handlers.py,sha256=k9G_Mb4ga2-Jke9irpdlYqj6EYiwv0gEsh4TgyqqOmI,28
115
115
  port_ocean/log/logger_setup.py,sha256=qSeVwnivV4WoLx_4SfBwn2PtmUpNdkSEgfm0C8B3yUw,2332
116
116
  port_ocean/log/sensetive.py,sha256=lVKiZH6b7TkrZAMmhEJRhcl67HNM94e56x12DwFgCQk,2920
117
117
  port_ocean/middlewares.py,sha256=K_FGt39YgiC0397W3ON1Z0n0bRIke95sZkw7a0xOiII,2737
118
- port_ocean/ocean.py,sha256=svLEWxBB_pM-a-_vrXZJGp5X-gFutldynpaRb7QKgVA,5231
118
+ port_ocean/ocean.py,sha256=vK3C-AJfN3FNJHKFA97JPV75tF7lH--SoarMtbj7u3M,5449
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
@@ -140,8 +140,8 @@ port_ocean/utils/repeat.py,sha256=0EFWM9d8lLXAhZmAyczY20LAnijw6UbIECf5lpGbOas,32
140
140
  port_ocean/utils/signal.py,sha256=K-6kKFQTltcmKDhtyZAcn0IMa3sUpOHGOAUdWKgx0_E,1369
141
141
  port_ocean/utils/time.py,sha256=pufAOH5ZQI7gXvOvJoQXZXZJV-Dqktoj9Qp9eiRwmJ4,1939
142
142
  port_ocean/version.py,sha256=UsuJdvdQlazzKGD3Hd5-U7N69STh8Dq9ggJzQFnu9fU,177
143
- port_ocean-0.12.2.dev21.dist-info/LICENSE.md,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
144
- port_ocean-0.12.2.dev21.dist-info/METADATA,sha256=WdhB305pKmHPhhf83Erc0HJ4QmxkyB8khDZDTbzfYGE,6671
145
- port_ocean-0.12.2.dev21.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
146
- port_ocean-0.12.2.dev21.dist-info/entry_points.txt,sha256=F_DNUmGZU2Kme-8NsWM5LLE8piGMafYZygRYhOVtcjA,54
147
- port_ocean-0.12.2.dev21.dist-info/RECORD,,
143
+ port_ocean-0.12.2.dev23.dist-info/LICENSE.md,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
144
+ port_ocean-0.12.2.dev23.dist-info/METADATA,sha256=rBbKmrKXMWvkd4fIbJ8cEWJ7M5oHFRw6k_0eXogt-NE,6671
145
+ port_ocean-0.12.2.dev23.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
146
+ port_ocean-0.12.2.dev23.dist-info/entry_points.txt,sha256=F_DNUmGZU2Kme-8NsWM5LLE8piGMafYZygRYhOVtcjA,54
147
+ port_ocean-0.12.2.dev23.dist-info/RECORD,,