Skip to content

Commit ee3ef92

Browse files
authored
Only overwrite created_at in case the account was deleted (#643)
1 parent 5ac207a commit ee3ef92

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

fixbackend/cloud_accounts/service.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,16 +874,19 @@ async def create_gcp_account(
874874
if existing:
875875

876876
def set_state(acc: CloudAccount) -> CloudAccount:
877-
return evolve(
877+
evolved = evolve(
878878
acc,
879879
state=CloudAccountStates.Configured(
880880
access=GcpCloudAccess(key_id), enabled=should_be_enabled, scan=should_be_enabled
881881
),
882882
account_name=account_name,
883883
state_updated_at=utc(),
884-
created_at=created_at,
885884
updated_at=created_at,
886885
)
886+
if isinstance(existing.state, CloudAccountStates.Deleted):
887+
evolved = evolve(evolved, created_at=created_at)
888+
889+
return evolved
887890

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

959962
def set_state(acc: CloudAccount) -> CloudAccount:
960-
return evolve(
963+
evolved = evolve(
961964
acc,
962965
state=CloudAccountStates.Configured(
963966
access=AzureCloudAccess(subscription_credentials_id),
964967
enabled=should_be_enabled,
965968
scan=should_be_enabled,
966969
),
967970
state_updated_at=utc(),
968-
created_at=created_at,
969971
updated_at=created_at,
970972
)
973+
if isinstance(existing.state, CloudAccountStates.Deleted):
974+
evolved = evolve(evolved, created_at=created_at)
975+
976+
return evolved
971977

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

0 commit comments

Comments
 (0)