Skip to content

Commit

Permalink
[Core] Fixed case where integration creation failed when using `WEBHO…
Browse files Browse the repository at this point in the history
…OKS_ONLY` (#1308)

# Description

What - Fixed case where integration creation failed when using
WEBHOOKS_ONLY event listener + added jira vscode launch config

Why - integration creation doesn't work

How - overriding to_request

## Type of change

Please leave one option from the following and delete the rest:

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] New Integration (non-breaking change which adds a new integration)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Non-breaking change (fix of existing functionality that will not
change current behavior)
- [ ] Documentation (added/updated documentation)

<h4> All tests should be run against the port production
environment(using a testing org). </h4>

### Core testing checklist

- [ ] Integration able to create all default resources from scratch
- [ ] Resync finishes successfully
- [ ] Resync able to create entities
- [ ] Resync able to update entities
- [ ] Resync able to detect and delete entities
- [ ] Scheduled resync able to abort existing resync and start a new one
- [ ] Tested with at least 2 integrations from scratch
- [ ] Tested with Kafka and Polling event listeners
- [ ] Tested deletion of entities that don't pass the selector


### Integration testing checklist

- [ ] Integration able to create all default resources from scratch
- [ ] Resync able to create entities
- [ ] Resync able to update entities
- [ ] Resync able to detect and delete entities
- [ ] Resync finishes successfully
- [ ] If new resource kind is added or updated in the integration, add
example raw data, mapping and expected result to the `examples` folder
in the integration directory.
- [ ] If resource kind is updated, run the integration with the example
data and check if the expected result is achieved
- [ ] If new resource kind is added or updated, validate that
live-events for that resource are working as expected
- [ ] Docs PR link [here](#)

### Preflight checklist

- [ ] Handled rate limiting
- [ ] Handled pagination
- [ ] Implemented the code in async
- [ ] Support Multi account

## Screenshots

Include screenshots from your environment showing how the resources of
the integration will look.

## API Documentation

Provide links to the API documentation used for this integration.
  • Loading branch information
matan84 authored Jan 12, 2025
1 parent 68de268 commit ac89208
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 16 deletions.
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/integrations/jira",
"envFile": "${workspaceFolder}/integrations/jira/.env",
"justMyCode": true,
"name": "Run jira integration",
"program": "${workspaceFolder}/integrations/jira/debug.py",
"python": "${workspaceFolder}/integrations/jira/.venv/bin/python",
"request": "launch",
"type": "debugpy"
},
{
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/integrations/snyk",
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

## 0.17.7 (2025-01-08)

### Bug Fixes

- Fixed a bug where creating an integration with WEBHOOKS_ONLY event listener failed.

### Improvements

- Added jira integration running config to vscode.

## 0.17.6 (2025-01-08)

### Bug Fixes
Expand Down
10 changes: 6 additions & 4 deletions port_ocean/core/defaults/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def _initialize_required_integration_settings(
)
integration = await port_client.create_integration(
integration_config.integration.type,
integration_config.event_listener.to_request(),
integration_config.event_listener.get_changelog_destination_details(),
port_app_config=default_mapping,
)
elif not integration.get("config"):
Expand All @@ -77,16 +77,18 @@ async def _initialize_required_integration_settings(
)
integration = await port_client.patch_integration(
integration_config.integration.type,
integration_config.event_listener.to_request(),
integration_config.event_listener.get_changelog_destination_details(),
port_app_config=default_mapping,
)
except httpx.HTTPStatusError as err:
logger.error(f"Failed to apply default mapping: {err.response.text}.")
raise err

logger.info("Checking for diff in integration configuration")
changelog_destination = integration_config.event_listener.to_request().get(
"changelog_destination"
changelog_destination = (
integration_config.event_listener.get_changelog_destination_details().get(
"changelog_destination"
)
)
if (
integration.get("changelogDestination") != changelog_destination
Expand Down
14 changes: 11 additions & 3 deletions port_ocean/core/event_listener/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@ class EventListenerSettings(BaseOceanModel, extra=Extra.allow):
type: str
should_resync: bool = True

def to_request(self) -> dict[str, Any]:
def get_changelog_destination_details(self) -> dict[str, Any]:
"""
Converts the Settings object to a dictionary representation (request format).
Returns the changelog destination configuration for the event listener.
By default, returns an empty dict. Only KAFKA and WEBHOOK event listeners need to override this
to provide their specific changelog destination details.
Returns:
dict[str, Any]: The changelog destination configuration. For example:
- KAFKA returns {"type": "KAFKA"}
- WEBHOOK returns {"type": "WEBHOOK", "url": "https://example.com/resync"}
- Other event listeners return {}
"""
return {"type": self.type}
return {}
12 changes: 10 additions & 2 deletions port_ocean/core/event_listener/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ class HttpEventListenerSettings(EventListenerSettings):
type: Literal["WEBHOOK"]
app_host: AnyHttpUrl = Field(..., sensitive=True)

def to_request(self) -> dict[str, Any]:
def get_changelog_destination_details(self) -> dict[str, Any]:
"""
Returns the changelog destination configuration for the webhook event listener.
For webhook event listeners, this specifies the URL where changelog events should be sent.
Returns:
dict[str, Any]: A dictionary with the webhook URL where changelog events should be sent,
constructed by appending "/resync" to the app_host.
"""
return {
**super().to_request(),
"type": self.type,
"url": self.app_host + "/resync",
}

Expand Down
13 changes: 13 additions & 0 deletions port_ocean/core/event_listener/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ class KafkaEventListenerSettings(EventListenerSettings):
kafka_security_enabled: bool = True
consumer_poll_timeout: int = 1

def get_changelog_destination_details(self) -> dict[str, Any]:
"""
Returns the changelog destination configuration for the Kafka event listener.
For Kafka event listeners, this specifies that changelog events should be sent via Kafka.
Returns:
dict[str, Any]: A dictionary with type "KAFKA" to indicate that changelog events
should be sent through the Kafka message bus.
"""
return {
"type": self.type,
}


class KafkaEventListener(BaseEventListener):
"""
Expand Down
3 changes: 0 additions & 3 deletions port_ocean/core/event_listener/once.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class OnceEventListenerSettings(EventListenerSettings):

type: Literal["ONCE"]

def to_request(self) -> dict[str, Any]:
return {}


class OnceEventListener(BaseEventListener):
"""
Expand Down
3 changes: 0 additions & 3 deletions port_ocean/core/event_listener/polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ class PollingEventListenerSettings(EventListenerSettings):
resync_on_start: bool = True
interval: int = 60

def to_request(self) -> dict[str, Any]:
return {}


class PollingEventListener(BaseEventListener):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "port-ocean"
version = "0.17.6"
version = "0.17.7"
description = "Port Ocean is a CLI tool for managing your Port projects."
readme = "README.md"
homepage = "https://app.getport.io"
Expand Down

0 comments on commit ac89208

Please sign in to comment.