From ee3ef92037e08092124f20b996e7079a6fc16f3a Mon Sep 17 00:00:00 2001 From: Nikita Melkozerov Date: Mon, 2 Dec 2024 12:56:58 +0100 Subject: [PATCH] Only overwrite created_at in case the account was deleted (#643) --- fixbackend/cloud_accounts/service.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fixbackend/cloud_accounts/service.py b/fixbackend/cloud_accounts/service.py index 685d5cb8..b05999ab 100644 --- a/fixbackend/cloud_accounts/service.py +++ b/fixbackend/cloud_accounts/service.py @@ -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") @@ -957,7 +960,7 @@ 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), @@ -965,9 +968,12 @@ def set_state(acc: CloudAccount) -> CloudAccount: 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")