Skip to content

Commit

Permalink
Only overwrite created_at in case the account was deleted (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
meln1k authored Dec 2, 2024
1 parent 5ac207a commit ee3ef92
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions fixbackend/cloud_accounts/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,16 +874,19 @@ async def create_gcp_account(
if existing:

def set_state(acc: CloudAccount) -> CloudAccount:
return evolve(
evolved = evolve(
acc,
state=CloudAccountStates.Configured(
access=GcpCloudAccess(key_id), enabled=should_be_enabled, scan=should_be_enabled
),
account_name=account_name,
state_updated_at=utc(),
created_at=created_at,
updated_at=created_at,
)
if isinstance(existing.state, CloudAccountStates.Deleted):
evolved = evolve(evolved, created_at=created_at)

return evolved

result = await self.cloud_account_repository.update(existing.id, set_state)
log.info(f"GCP cloud Account {account_id} updated from deleted to configured")
Expand Down Expand Up @@ -957,17 +960,20 @@ async def create_azure_account(
if existing:

def set_state(acc: CloudAccount) -> CloudAccount:
return evolve(
evolved = 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,
)
if isinstance(existing.state, CloudAccountStates.Deleted):
evolved = evolve(evolved, created_at=created_at)

return evolved

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

0 comments on commit ee3ef92

Please sign in to comment.