Skip to content

Commit

Permalink
improvement(Port 8335) ocean make config yml not required (#652)
Browse files Browse the repository at this point in the history
# Description

What - There are a lot of unused config.yml files
Why - Most of the time we prefer to control it with the env vars
How - made it unrequired and only using it for defaults

## Type of change

- [X] Non-breaking change (fix of existing functionality that will not
change current behavior)
  • Loading branch information
yairsimantov20 authored May 26, 2024
1 parent 462dc88 commit 02f4da0
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 40 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/release-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ jobs:
run: |
current_integration_spec=${{ matrix.integration }}
type=$(yq eval '.type' "$current_integration_spec")
folder=$(dirname "$current_integration_spec")
context_dir=$(dirname "$folder")
echo "context_dir=$context_dir" >> $GITHUB_OUTPUT
version=$(grep -E '^version = ".*"' "$folder/../pyproject.toml" | cut -d'"' -f2)
type=$(grep -E '^name = ".*"' "$folder/../pyproject.toml" | cut -d'"' -f2)
echo "version=$version" >> $GITHUB_OUTPUT
dockerfile_path=integrations/_infra/Dockerfile
Expand Down Expand Up @@ -154,13 +154,17 @@ jobs:
find integrations/*/.port -type f -name "spec.yaml" > file_list.txt
while IFS= read -r file; do
# Extract the version from pyproject.toml
integration_dir=$(dirname "$file")
# Extract the type for pyproject.toml
type=$(grep -E '^name = ".*"' "$integration_dir/../pyproject.toml" | cut -d'"' -f2)
# Extract the version from pyproject.toml
version=$(grep -E '^version = ".*"' "$integration_dir/../pyproject.toml" | cut -d'"' -f2)
# Store the integration's yaml file content into a temporary file
integration_dest="$(echo $integration_dir | awk -F'/' '{print $2}').json"
sed 's/^/ /' "$file" > "$specific_integration_temp_file"
echo " type: $type" >> "$specific_integration_temp_file"
echo " version: $version" >> "$specific_integration_temp_file"
yq -o=json . < "$specific_integration_temp_file" > "$integration_dest"
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

## 0.5.20 (2024-05-26)


### Improvements

- Made config.yaml file optional in the integration setup process.
- Integration type is now determined by the name specified in the pyproject.toml file.
- Switched to using the FastAPI lifespan feature instead of the deprecated on_shutdown and on_start methods.

### Bug Fixes

- Fixed the FastAPI server staying stale after shutdown by using the FastAPI lifespan feature for handling shutdown signals, preventing override of the shutdown process.
- Fixed issue with integration continuing to run after shutdown by canceling the resync async generator task.


## 0.5.19 (2024-05-16)

### Improvements
Expand Down
1 change: 0 additions & 1 deletion changelog/1.bugfix.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog/1.improvement.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog/2.bugfix.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
type: {{cookiecutter.integration_slug}}
description: {{cookiecutter.integration_name}} integration for Port Ocean
icon: Cookiecutter # Should be one of the available icons in Port
features:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "{{cookiecutter.integration_name}}"
name = "{{cookiecutter.integration_slug}}"
version = "0.1.0"
description = "{{cookiecutter.integration_short_description}}"
authors = ["{{cookiecutter.full_name}} <{{cookiecutter.email}}>"]
Expand Down
10 changes: 4 additions & 6 deletions port_ocean/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

def read_yaml_config_settings_source(
settings: "BaseOceanSettings", base_path: str
) -> str:
) -> dict[str, Any]:
yaml_file = getattr(settings.__config__, "yaml_file", "")

assert yaml_file, "Settings.yaml_file not properly configured"
path = Path(base_path, yaml_file)

if not path.exists():
raise FileNotFoundError(f"Could not open yaml settings file at: {path}")

return path.read_text("utf-8")
return {}
return yaml.safe_load(path.read_text("utf-8"))


def parse_config_provider(value: str) -> tuple[str, str]:
Expand Down Expand Up @@ -122,8 +121,7 @@ def decamelize_config(
def load_providers(
settings: "BaseOceanSettings", existing_values: dict[str, Any], base_path: str
) -> dict[str, Any]:
yaml_content = read_yaml_config_settings_source(settings, base_path)
data = yaml.safe_load(yaml_content)
data = read_yaml_config_settings_source(settings, base_path)
snake_case_config = decamelize_config(settings, data)
return parse_providers(settings, snake_case_config, existing_values)

Expand Down
24 changes: 18 additions & 6 deletions port_ocean/config/settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import Any, Literal

from pydantic import Extra, AnyHttpUrl, parse_obj_as, validator
from pydantic import Extra, AnyHttpUrl, parse_obj_as
from pydantic.class_validators import root_validator
from pydantic.env_settings import InitSettingsSource, EnvSettingsSource, BaseSettings
from pydantic.fields import Field
from pydantic.main import BaseModel

from port_ocean.config.base import BaseOceanSettings, BaseOceanModel
from port_ocean.core.event_listener import EventListenerSettingsType
from port_ocean.utils.misc import get_integration_name

LogLevelType = Literal["ERROR", "WARNING", "INFO", "DEBUG", "CRITICAL"]

Expand Down Expand Up @@ -40,13 +42,23 @@ class PortSettings(BaseOceanModel, extra=Extra.allow):


class IntegrationSettings(BaseOceanModel, extra=Extra.allow):
identifier: str
type: str
identifier: str = Field(..., min_length=1)
type: str = Field(..., min_length=1)
config: dict[str, Any] | BaseModel

@validator("identifier", "type")
def validate_lower(cls, v: str) -> str:
return v.lower()
@root_validator(pre=True)
def a(cls, values: dict[str, Any]) -> dict[str, Any]:
integ_type = values.get("type")

if not integ_type:
integ_type = get_integration_name()

values["type"] = integ_type.lower() if integ_type else None
values["identifier"] = values.get(
"identifier", f"my-{integ_type}-integration".lower()
)

return values


class IntegrationConfiguration(BaseOceanSettings, extra=Extra.allow):
Expand Down
18 changes: 15 additions & 3 deletions port_ocean/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ def get_function_location(func: Callable[..., Any]) -> str:
return f"{file_path}:{line_number}"


def get_integration_version() -> str:
def get_pyproject_data() -> dict[str, Any] | None:
try:
with open("./pyproject.toml", "rb") as toml_file:
pyproject_data = tomli.load(toml_file)
return pyproject_data["tool"]["poetry"]["version"]
return pyproject_data["tool"]["poetry"]
except (FileNotFoundError, KeyError):
return ""
return None


def get_integration_version() -> str:
if data := get_pyproject_data():
return data["version"]
return ""


def get_integration_name() -> str:
if data := get_pyproject_data():
return data["name"]
return ""


def get_spec_file(path: Path = Path(".")) -> dict[str, Any] | None:
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.5.19"
version = "0.5.20"
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 02f4da0

Please sign in to comment.