Skip to content

Commit

Permalink
move account from deleted to configured when creating
Browse files Browse the repository at this point in the history
  • Loading branch information
meln1k committed Nov 29, 2024
1 parent 13da374 commit bb402b2
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions fixbackend/cloud_accounts/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,9 @@ async def create_azure_account(
raise ResourceNotFound("Organization does not exist")

if existing := await self.cloud_account_repository.get_by_account_id(workspace_id, account_id):
log.info("Azure account already exists")
return existing
if not isinstance(existing.state, CloudAccountStates.Deleted):
log.info("Azure account already exists")
return existing

should_be_enabled = await self._should_be_enabled(workspace)

Expand Down Expand Up @@ -935,8 +936,26 @@ async def create_azure_account(
last_degraded_scan_started_at=None,
)

result = await self.cloud_account_repository.create(account)
log.info(f"Azure cloud Account {account_id} created")
if existing:

def set_state(acc: CloudAccount) -> CloudAccount:
return evolve(
acc,
state=CloudAccountStates.Configured(
access=AzureCloudAccess(subscription_credentials_id),
enabled=should_be_enabled,
scan=should_be_enabled,
),
state_updated_at=utc(),
created_at=created_at,
updated_at=created_at,
)

result = await self.cloud_account_repository.update(existing.id, set_state)
log.info(f"Azure cloud Account {account_id} updated from deleted to configured")
else:
result = await self.cloud_account_repository.create(account)
log.info(f"Azure cloud Account {account_id} created")

await self.domain_events.publish(
CloudAccountConfigured(
Expand Down

0 comments on commit bb402b2

Please sign in to comment.