Skip to content

Commit

Permalink
[Core] Added flag to destroy integration config while running clean d…
Browse files Browse the repository at this point in the history
…efaults cli command (#1378)
  • Loading branch information
oiadebayo authored Feb 9, 2025
1 parent 63c4a74 commit 9c0f2ca
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

<!-- towncrier release notes start -->
## 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
Expand Down
17 changes: 15 additions & 2 deletions port_ocean/cli/commands/defaults/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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! ⚓️")
Expand All @@ -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,
)
15 changes: 15 additions & 0 deletions port_ocean/clients/port/mixins/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
21 changes: 18 additions & 3 deletions port_ocean/core/defaults/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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
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.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"
Expand Down

0 comments on commit 9c0f2ca

Please sign in to comment.