Skip to content

Commit

Permalink
Port 4780 more verbosity for the integration startup (#204)
Browse files Browse the repository at this point in the history
### Features

- Added the current integration version to the port requests for future features and better debugging (PORT-4310)

### Bug Fixes

- Added the `install/prod` command to the integration scaffold template as was intended (PORT-5107)
- Changed the serializing of the port app config so when initializing it there wont be any None or default values displayed in the UI (PORT-5108)

### Improvements

- Removed version field from the spec.yml in the scaffolded integration (Version will be taken from the pyproject.toml) (PORT-5107)
- Changed the integration type in spec.yml to be the integration slug when scaffolding a new integration (PORT-5107)
- Added more logs to the ocean package for better debugging of the integration (PORT-4780)
- Seperated `SyncRawMixin` from `SyncRawMixin` (moved `SyncRawMixin` to `core/integrations/mixins/sync_raw.py`)
- Improved code readability for `SyncRawMixin`
  • Loading branch information
yairsimantov20 authored Nov 8, 2023
1 parent 0550392 commit fa09dcf
Show file tree
Hide file tree
Showing 21 changed files with 497 additions and 382 deletions.
1 change: 1 addition & 0 deletions .github/workflows/combine-dependabot-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
combine-prs:
# The type of runner that the job will run on
runs-on: ubuntu-latest
permissions: write-all

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

## 0.4.2 (2023-11-04)

### Features

- Added the current integration version to the port requests for future features and better debugging (PORT-4310)

### Bug Fixes

- Added the `install/prod` command to the integration scaffold template as was intended (PORT-5107)
- Changed the serializing of the port app config so when initializing it there wont be any None or default values displayed in the UI (PORT-5108)

### Improvements

- Removed version field from the spec.yml in the scaffolded integration (Version will be taken from the pyproject.toml) (PORT-5107)
- Changed the integration type in spec.yml to be the integration slug when scaffolding a new integration (PORT-5107)
- Added more logs to the ocean package for better debugging of the integration (PORT-4780)
- Seperated `SyncRawMixin` from `SyncRawMixin` (moved `SyncRawMixin` to `core/integrations/mixins/sync_raw.py`)
- Improved code readability for `SyncRawMixin`


## 0.4.1 (2023-11-03)

### Bug Fixes
Expand Down
35 changes: 13 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions port_ocean/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import warnings
from importlib.metadata import version


warnings.filterwarnings("ignore", category=FutureWarning)

from .ocean import Ocean # noqa: E402
from .run import run # noqa: E402

__version__ = version("port-ocean")
from .version import __integration_version__, __version__ # noqa: E402


__all__ = ["Ocean", "run", "__version__"]
__all__ = ["Ocean", "run", "__version__", "__integration_version__"]
3 changes: 3 additions & 0 deletions port_ocean/cli/commands/sail.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import click

from port_ocean import __version__, __integration_version__
from port_ocean.cli.commands.main import cli_start, print_logo, console
from port_ocean.config.settings import LogLevelType

Expand Down Expand Up @@ -62,6 +63,8 @@ def sail(
print_logo()

console.print("Setting sail... ⛵️⚓️⛵️⚓️ All hands on deck! ⚓️")
console.print(f"🌊 Ocean version: {__version__}")
console.print(f"🚢 Integration version: {__integration_version__}")

override = {}
if once:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
version: v0.1.0
type: gitlab
type: {{cookiecutter.integration_slug}}
description: {{cookiecutter.integration_name}} integration for Port Ocean
icon: Cookiecutter
icon: Cookiecutter # Should be one of the available icons in Port
features:
- type: exporter
section: Git Providers
section: Git Providers # Should be one of the available sections in Port
resources:
- kind: <ResourceName1>
- kind: <ResourceName2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ define deactivate_virtualenv
fi
endef

.SILENT: install lint run test clean
.SILENT: install install/prod lint run test clean

install:
$(call deactivate_virtualenv) && \
$(call install_poetry) && \
poetry install --with dev

install/prod:
$(call install_poetry) && \
poetry install --without dev --no-root --no-interaction --no-ansi --no-cache

lint:
$(ACTIVATE) && \
$(call run_checks,.)
Expand Down
4 changes: 3 additions & 1 deletion port_ocean/clients/port/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ def __init__(
api_url: str,
integration_identifier: str,
integration_type: str,
integration_version: str,
):
self.client = client
self.api_url = api_url
self.client_id = client_id
self.client_secret = client_secret
self.integration_identifier = integration_identifier
self.integration_type = integration_type
self.integration_version = integration_version
self._last_token_object: TokenResponse | None = None

async def _get_token(self, client_id: str, client_secret: str) -> TokenResponse:
Expand All @@ -53,7 +55,7 @@ async def _get_token(self, client_id: str, client_secret: str) -> TokenResponse:
return TokenResponse(**response.json())

def user_agent(self, user_agent_type: UserAgentType | None = None) -> str:
user_agent = f"port-ocean/{self.integration_type}/{self.integration_identifier}"
user_agent = f"port-ocean/{self.integration_type}/{self.integration_version}/{self.integration_identifier}"
if user_agent_type:
user_agent += f"/{user_agent_type.value or UserAgentType.exporter.value}"

Expand Down
5 changes: 3 additions & 2 deletions port_ocean/clients/port/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from port_ocean.clients.port.mixins.entities import EntityClientMixin
from port_ocean.clients.port.mixins.integrations import IntegrationClientMixin
from port_ocean.clients.port.mixins.migrations import MigrationClientMixin

from port_ocean.clients.port.types import (
KafkaCreds,
)
Expand All @@ -26,6 +25,7 @@ def __init__(
client_secret: str,
integration_identifier: str,
integration_type: str,
integration_version: str,
):
self.api_url = f"{base_url}/v1"
self.client = async_client
Expand All @@ -36,10 +36,11 @@ def __init__(
self.api_url,
integration_identifier,
integration_type,
integration_version,
)
EntityClientMixin.__init__(self, self.auth, self.client)
IntegrationClientMixin.__init__(
self, integration_identifier, self.auth, self.client
self, integration_identifier, integration_version, self.auth, self.client
)
BlueprintClientMixin.__init__(self, self.auth, self.client)
MigrationClientMixin.__init__(self, self.auth, self.client)
Expand Down
5 changes: 5 additions & 0 deletions port_ocean/clients/port/mixins/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class IntegrationClientMixin:
def __init__(
self,
integration_identifier: str,
integration_version: str,
auth: PortAuthentication,
client: httpx.AsyncClient,
):
self.integration_identifier = integration_identifier
self.integration_version = integration_version
self.auth = auth
self.client = client

Expand Down Expand Up @@ -48,6 +50,7 @@ async def create_integration(
json = {
"installationId": self.integration_identifier,
"installationAppType": _type,
"version": self.integration_version,
"changelogDestination": changelog_destination,
"config": {},
}
Expand All @@ -73,6 +76,7 @@ async def patch_integration(
json["changelogDestination"] = changelog_destination
if port_app_config:
json["config"] = port_app_config.to_request()
json["version"] = self.integration_version

response = await self.client.patch(
f"{self.auth.api_url}/integration/{self.integration_identifier}",
Expand All @@ -99,6 +103,7 @@ async def initialize_integration(
if (
integration["changelogDestination"] != changelog_destination
or integration["installationAppType"] != _type
or integration.get("version") != self.integration_version
):
await self.patch_integration(
_type, changelog_destination, port_app_config
Expand Down
5 changes: 4 additions & 1 deletion port_ocean/core/handlers/port_app_config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def to_request(self) -> dict[str, Any]:
"deleteDependentEntities": self.delete_dependent_entities,
"createMissingRelatedEntities": self.create_missing_related_entities,
"enableMergeEntity": self.enable_merge_entity,
"resources": [resource.dict(by_alias=True) for resource in self.resources],
"resources": [
resource.dict(by_alias=True, exclude_none=True, exclude_unset=True)
for resource in self.resources
],
}

class Config:
Expand Down
4 changes: 2 additions & 2 deletions port_ocean/core/integrations/mixins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .events import EventsMixin
from .handler import HandlerMixin
from .sync import SyncRawMixin, SyncMixin

from .sync import SyncMixin
from .sync_raw import SyncRawMixin

__all__ = [
"EventsMixin",
Expand Down
11 changes: 11 additions & 0 deletions port_ocean/core/integrations/mixins/events.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from collections import defaultdict

from loguru import logger

from port_ocean.core.ocean_types import (
IntegrationEventsCallbacks,
START_EVENT_LISTENER,
Expand All @@ -26,6 +28,10 @@ def __init__(self) -> None:
"resync": defaultdict(list),
}

@property
def available_resync_kinds(self) -> list[str]:
return list(self.event_strategy["resync"].keys())

def on_start(self, func: START_EVENT_LISTENER) -> START_EVENT_LISTENER:
"""Register a function as a listener for the "start" event.
Expand All @@ -35,6 +41,7 @@ def on_start(self, func: START_EVENT_LISTENER) -> START_EVENT_LISTENER:
Returns:
START_EVENT_LISTENER: The input function, unchanged.
"""
logger.debug(f"Registering {func} as a start event listener")
self.event_strategy["start"].append(func)
return func

Expand All @@ -50,5 +57,9 @@ def on_resync(
Returns:
RESYNC_EVENT_LISTENER: The input function, unchanged.
"""
if kind is None:
logger.debug(f"Registering resync event listener any kind")
else:
logger.info(f"Registering resync event listener for kind {kind}")
self.event_strategy["resync"][kind].append(func)
return func
Loading

0 comments on commit fa09dcf

Please sign in to comment.