diff --git a/CHANGELOG.md b/CHANGELOG.md index 0979b03368..9f2e474e2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.18.9 (2025-02-07) + +### Improvements + +- Added option to destroy integration config while performing defaults clean cli command: `ocean defaults clean --force --wait --destroy` + ## 0.18.8 (2025-02-04) ### Bug Fixes diff --git a/port_ocean/cli/commands/defaults/clean.py b/port_ocean/cli/commands/defaults/clean.py index 2c6fd2eeb1..919f179328 100644 --- a/port_ocean/cli/commands/defaults/clean.py +++ b/port_ocean/cli/commands/defaults/clean.py @@ -8,6 +8,7 @@ from port_ocean.core.defaults import clean_defaults from port_ocean.ocean import Ocean from port_ocean.utils.misc import load_module +from port_ocean.utils.signal import init_signal_handler from .group import defaults @@ -27,12 +28,20 @@ is_flag=True, help="Wait for the migration to finish. when force is set to true.", ) -def clean(path: str, force: bool, wait: bool) -> None: +@click.option( + "-d", + "--destroy", + "destroy", + is_flag=True, + help="Destroy the integration after cleaning the defaults.", +) +def clean(path: str, force: bool, wait: bool, destroy: bool) -> None: """ Clean defaults of the integration from the .port/resources PATH. PATH: Path to the integration. If not provided, the current directory will be used. """ + init_signal_handler() print_logo() console.print("Cleaning blueprints and configurations! ⚓️") @@ -52,5 +61,9 @@ def clean(path: str, force: bool, wait: bool) -> None: ) clean_defaults( - app.integration.AppConfigHandlerClass.CONFIG_CLASS, app.config, force, wait + app.integration.AppConfigHandlerClass.CONFIG_CLASS, + app.config, + force, + wait, + destroy, ) diff --git a/port_ocean/clients/port/mixins/integrations.py b/port_ocean/clients/port/mixins/integrations.py index f281644a0d..fe8e86c12c 100644 --- a/port_ocean/clients/port/mixins/integrations.py +++ b/port_ocean/clients/port/mixins/integrations.py @@ -178,3 +178,18 @@ async def ingest_integration_kind_examples( ) handle_status_code(response, should_log=should_log) logger.debug(f"Examples for kind {kind} successfully ingested") + + async def _delete_current_integration(self) -> httpx.Response: + logger.info(f"Deleting integration with id: {self.integration_identifier}") + response = await self.client.delete( + f"{self.auth.api_url}/integration/{self.integration_identifier}", + headers=await self.auth.headers(), + ) + return response + + async def delete_current_integration( + self, should_raise: bool = True, should_log: bool = True + ) -> dict[str, Any]: + response = await self._delete_current_integration() + handle_status_code(response, should_raise, should_log) + return response.json() diff --git a/port_ocean/core/defaults/clean.py b/port_ocean/core/defaults/clean.py index 0a10d90b40..6e6a77672b 100644 --- a/port_ocean/core/defaults/clean.py +++ b/port_ocean/core/defaults/clean.py @@ -18,10 +18,11 @@ def clean_defaults( integration_config: IntegrationConfiguration, force: bool, wait: bool, + destroy: bool, ) -> None: try: asyncio.new_event_loop().run_until_complete( - _clean_defaults(config_class, integration_config, force, wait) + _clean_defaults(config_class, integration_config, force, wait, destroy) ) except Exception as e: @@ -33,6 +34,7 @@ async def _clean_defaults( integration_config: IntegrationConfiguration, force: bool, wait: bool, + destroy: bool, ) -> None: port_client = ocean.port_client is_exists = await is_integration_exists(port_client) @@ -54,9 +56,9 @@ async def _clean_defaults( ) ) - if not force: + if not force and not destroy: logger.info( - "Finished deleting blueprints and configurations! ⚓️", + "Finished deleting blueprints! ⚓️", ) return None @@ -73,6 +75,19 @@ async def _clean_defaults( for migration_id in migration_ids ) ) + if not destroy: + logger.info( + "Migrations completed successfully! ⚓️", + ) + return None + + result = await ocean.port_client.delete_current_integration() + if result.get("ok"): + logger.info( + "Blueprints deleted, migrations completed, and integration destroyed successfully! ⚓️", + ) + return None + except httpx.HTTPStatusError as e: logger.error(f"Failed to delete blueprints: {e.response.text}.") raise e diff --git a/pyproject.toml b/pyproject.toml index 6563b53895..5642236783 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "port-ocean" -version = "0.18.8" +version = "0.18.9" description = "Port Ocean is a CLI tool for managing your Port projects." readme = "README.md" homepage = "https://app.getport.io"