Skip to content

Commit

Permalink
Fix cloud account enabled bug (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
meln1k authored Sep 2, 2024
1 parent 2d8311d commit b1ed287
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fixbackend/cloud_accounts/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def from_model(model: CloudAccount) -> "CloudAccountRead":
scan = model.state.scan
is_configured = True

case CloudAccountStates.Degraded():
enabled = model.state.enabled
scan = model.state.scan

last_scan_finished = None
if model.last_scan_started_at:
last_scan_finished = model.last_scan_started_at + timedelta(seconds=model.last_scan_duration_seconds)
Expand Down
31 changes: 31 additions & 0 deletions tests/fixbackend/cloud_accounts/router_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ async def test_last_scan(client: AsyncClient, workspace: Workspace) -> None:
async def test_get_cloud_account(client: AsyncClient, workspace: Workspace) -> None:
cloud_account_service.accounts = {}
cloud_account_id = FixCloudAccountId(uuid.uuid4())
degraded_cloud_account_id = FixCloudAccountId(uuid.uuid4())
next_scan = datetime.utcnow()
started_at = datetime.utcnow()
cloud_account_service.accounts[cloud_account_id] = CloudAccount(
Expand All @@ -335,6 +336,29 @@ async def test_get_cloud_account(client: AsyncClient, workspace: Workspace) -> N
last_task_id=None,
last_degraded_scan_started_at=None,
)
cloud_account_service.accounts[degraded_cloud_account_id] = CloudAccount(
id=degraded_cloud_account_id,
account_id=account_id,
workspace_id=workspace.id,
cloud=CloudNames.AWS,
state=CloudAccountStates.Degraded(AwsCloudAccess(external_id, role_name), enabled=True, scan=True, error="foo"),
account_name=CloudAccountName("foo"),
account_alias=CloudAccountAlias("foo_alias"),
user_account_name=UserCloudAccountName("foo_user"),
privileged=True,
last_scan_duration_seconds=10,
last_scan_resources_scanned=100,
last_scan_started_at=started_at,
last_scan_resources_errors=456,
next_scan=next_scan,
created_at=utc(),
updated_at=utc(),
state_updated_at=utc(),
cf_stack_version=42,
failed_scan_count=123,
last_task_id=None,
last_degraded_scan_started_at=None,
)

response = await client.get(f"/api/workspaces/{workspace.id}/cloud_account/{cloud_account_id}")
assert response.status_code == 200
Expand All @@ -356,6 +380,13 @@ async def test_get_cloud_account(client: AsyncClient, workspace: Workspace) -> N
assert data["cf_stack_version"] == 42
assert data["errors"] == 456

degraded_response = await client.get(f"/api/workspaces/{workspace.id}/cloud_account/{degraded_cloud_account_id}")
assert degraded_response.status_code == 200
data = degraded_response.json()
assert data["state"] == "degraded"
assert data["enabled"] is True
assert data["scan"] is True


@pytest.mark.asyncio
async def test_list_cloud_accounts(client: AsyncClient, workspace: Workspace) -> None:
Expand Down

0 comments on commit b1ed287

Please sign in to comment.