Skip to content

Commit

Permalink
PORT-8491 Add search relation capabilities (#687)
Browse files Browse the repository at this point in the history
# Description

What - Add to Ocean the feature of search relations (Ingesting relations
with search query)
Why - Easier to connect entities if you don't have the identifier of the
related entity
How -  Support new object type in the mapping relation field

## Type of change

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

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] 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)

## 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
razsamuel authored Jun 16, 2024
1 parent f6572e2 commit 1187e01
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .idea/watcherTasks.xml

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

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

## 0.8.0 (2024-06-11)


### Improvements

- Add search relation support (Allow to to run a search query to find the relation to the entity as part of the mapping)

## 0.7.1 (2024-06-13)


Expand Down
14 changes: 11 additions & 3 deletions port_ocean/core/handlers/entity_processor/jq_entity_processor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import functools
from asyncio import Task
from dataclasses import dataclass, field
from functools import lru_cache
from typing import Any, Optional
Expand Down Expand Up @@ -70,9 +71,13 @@ async def _search_as_bool(self, data: dict[str, Any], pattern: str) -> bool:
async def _search_as_object(
self, data: dict[str, Any], obj: dict[str, Any]
) -> dict[str, Any | None]:
search_tasks = {}
search_tasks: dict[str,Task[dict[str,Any | None]] | list[Task[dict[str,Any | None]]]] = {}
for key, value in obj.items():
if isinstance(value, dict):

if isinstance(value,list):
search_tasks[key] = [asyncio.create_task(self._search_as_object(data,obj)) for obj in value]

elif isinstance(value, dict):
search_tasks[key] = asyncio.create_task(
self._search_as_object(data, value)
)
Expand All @@ -82,7 +87,10 @@ async def _search_as_object(
result: dict[str, Any | None] = {}
for key, task in search_tasks.items():
try:
result[key] = await task
if isinstance(task,list):
result[key] = [await task for task in task]
else:
result[key] = await task
except Exception:
result[key] = None

Expand Down
22 changes: 18 additions & 4 deletions port_ocean/core/handlers/port_app_config/models.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
from __future__ import annotations

from typing import Any

from pydantic import BaseModel, Field

from port_ocean.clients.port.types import RequestOptions


class Rule(BaseModel):
property: str
operator: str
value: str


class SearchRelation(BaseModel):
combinator: str
rules: list[Rule | SearchRelation]


class EntityMapping(BaseModel):
identifier: str
title: str | None
blueprint: str
team: str | None
properties: dict[str, str] = Field(default_factory=dict)
relations: dict[str, str] = Field(default_factory=dict)
relations: dict[str, str | SearchRelation] = Field(default_factory=dict)


class PortResourceConfig(BaseModel):
class MappingsConfig(BaseModel):
mappings: EntityMapping
class MappingsConfig(BaseModel):
mappings: EntityMapping


class PortResourceConfig(BaseModel):
entity: MappingsConfig
items_to_parse: str | None = Field(alias="itemsToParse")

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.7.1"
version = "0.8.0"
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 1187e01

Please sign in to comment.