Skip to content

Commit

Permalink
[SQUASH] Final flow
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzaadi committed Jan 21, 2025
1 parent 4d71af9 commit 29559af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
8 changes: 4 additions & 4 deletions port_ocean/clients/port/mixins/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def create_integration(
_type: str,
changelog_destination: dict[str, Any],
port_app_config: Optional["PortAppConfig"] = None,
use_provisioned_defaults: Optional[bool] = False,
create_resources: Optional[bool] = False,
) -> Dict[str, Any]:
logger.info(f"Creating integration with id: {self.integration_identifier}")
headers = await self.auth.headers()
Expand All @@ -105,10 +105,10 @@ async def create_integration(

query_params = {}

if use_provisioned_defaults:
if create_resources:
query_params[CREATE_RESOURCES_PARAM_NAME] = CREATE_RESOURCES_PARAM_VALUE

if port_app_config and not use_provisioned_defaults:
if port_app_config and not create_resources:
json["config"] = port_app_config.to_request()
response = await self.client.post(
f"{self.auth.api_url}/integration",
Expand All @@ -117,7 +117,7 @@ async def create_integration(
params=query_params,
)
handle_status_code(response)
if use_provisioned_defaults:
if create_resources:
result = (
await self._poll_integration_until_default_provisioning_is_complete()
)
Expand Down
10 changes: 9 additions & 1 deletion port_ocean/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class IntegrationConfiguration(BaseOceanSettings, extra=Extra.allow):
initialize_port_resources: bool = True
scheduled_resync_interval: int | None = None
client_timeout: int = 60
use_provisioned_defaults: bool = False
# Determines if Port should generate resources such as blueprints and pages instead of ocean
create_resources: bool = False
send_raw_data_examples: bool = True
port: PortSettings
event_listener: EventListenerSettingsType = Field(
Expand Down Expand Up @@ -102,6 +103,13 @@ def parse_config(model: Type[BaseModel], config: Any) -> BaseModel:

return values

@validator("create_resources")
def validate_create_resources(cls, create_resources: bool) -> bool:
spec = get_spec_file()
if spec:
return spec.get("create_resources", False) or create_resources
return create_resources

@validator("runtime")
def validate_runtime(cls, runtime: Runtime) -> Runtime:
if runtime.is_saas_runtime:
Expand Down
27 changes: 12 additions & 15 deletions port_ocean/core/defaults/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def _initialize_required_integration_settings(
integration_config.integration.type,
integration_config.event_listener.get_changelog_destination_details(),
port_app_config=default_mapping,
use_provisioned_defaults=integration_config.use_provisioned_defaults,
create_resources=integration_config.create_resources,
)
elif not integration.get("config"):
logger.info(
Expand Down Expand Up @@ -209,24 +209,23 @@ async def _initialize_defaults(
config_class, integration_config.resources_path
)

if integration_config.use_provisioned_defaults:
logger.info("`use_provisioned_defaults` set, verifying org feature toggle")
if integration_config.runtime.is_saas_runtime:
integration_config.create_resources = True

if integration_config.create_resources:
logger.info("`create_resources` set, verifying org feature toggle")
org_feature_flags = await port_client.get_organization_feature_flags()
if ORG_USE_PROVISIONED_DEFAULTS_FEATURE_FLAG not in org_feature_flags:
logger.info(
"Although `use_provisioned_defaults` was set, it was not enabled in the organizations feature flags, disabling"
"Although `create_resources` was set, it was not enabled in the organizations feature flags, disabling"
)
integration_config.use_provisioned_defaults = False
integration_config.create_resources = False

if not integration_config.use_provisioned_defaults and not defaults:
if not integration_config.create_resources and not defaults:
logger.warning("No defaults found. Skipping initialization...")
return None

if (
defaults
and defaults.port_app_config
or integration_config.use_provisioned_defaults
):
if defaults and defaults.port_app_config or integration_config.create_resources:
await _initialize_required_integration_settings(
port_client,
integration_config,
Expand All @@ -236,10 +235,8 @@ async def _initialize_defaults(
if not integration_config.initialize_port_resources:
return

if integration_config.use_provisioned_defaults:
logger.info(
"Skipping creating defaults resources due to `use_provisioned_defaults`"
)
if integration_config.create_resources:
logger.info("Skipping creating defaults resources due to `create_resources`")
return
try:
logger.info("Found default resources, starting creation process")
Expand Down

0 comments on commit 29559af

Please sign in to comment.