Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move accounts back to configured if failed scan count is zero #616

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions fixbackend/cloud_accounts/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ def compute_failed_scan_count(collect_info: CloudAccountCollectInfo, acc: CloudA
updated.id, "Too many consecutive failed scans", DegradationReason.other
)

if updated.failed_scan_count == 0:
await self.__undegrade_account(updated.id)

await send_pub_sub_message(event)
user_id = await self.analytics_event_sender.user_id_from_workspace(event.tenant_id)
if first_workspace_collect:
Expand Down Expand Up @@ -1151,6 +1154,35 @@ def set_degraded(cloud_account: CloudAccount) -> CloudAccount:
)
return account

async def __undegrade_account(self, account_id: FixCloudAccountId) -> CloudAccount:
account = await self.cloud_account_repository.get(account_id)
if account is None:
raise ResourceNotFound(f"Account {account_id} not found")

if not isinstance(account.state, CloudAccountStates.Degraded):
# already in not degraded state, no need to do anything
return account

def set_configured(cloud_account: CloudAccount) -> CloudAccount:
enabled = False
scan = False
match cloud_account.state:
case CloudAccountStates.Degraded(_, e, s, _):
enabled = e
scan = s

if access := cloud_account.state.cloud_access():
return evolve(
cloud_account,
state=CloudAccountStates.Configured(access, enabled=enabled, scan=scan),
state_updated_at=utc(),
)
else:
return cloud_account

account = await self.cloud_account_repository.update(account_id, set_configured)
return account

async def disable_cloud_accounts(self, workspace_id: WorkspaceId, keep_enabled: int) -> None:
async def disable_account(cloud_account: CloudAccount) -> None:
try:
Expand Down
Loading