From bdad361787afcaf627b96ae542561c2cc24d057c Mon Sep 17 00:00:00 2001 From: "Nikita Melkozerov (aider)" Date: Tue, 22 Oct 2024 23:06:22 +0200 Subject: [PATCH] feat: add can_access parameter to list_created_after and update its usage --- fixbackend/cloud_accounts/azure_subscription_repo.py | 9 +++++---- fixbackend/cloud_accounts/azure_subscription_service.py | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/fixbackend/cloud_accounts/azure_subscription_repo.py b/fixbackend/cloud_accounts/azure_subscription_repo.py index 6548f6ae..3e91e14f 100644 --- a/fixbackend/cloud_accounts/azure_subscription_repo.py +++ b/fixbackend/cloud_accounts/azure_subscription_repo.py @@ -120,11 +120,12 @@ async def get_by_tenant(self, tenant_id: WorkspaceId) -> Optional[AzureSubscript return entity.to_model() - async def list_created_after(self, time: datetime) -> List[AzureSubscriptionCredentials]: + async def list_created_after(self, time: datetime, can_access_azure_account: Optional[bool] = None) -> List[AzureSubscriptionCredentials]: async with self._session_maker() as session: - query = select(AzureSubscriptionCredentialsEntity).filter( - AzureSubscriptionCredentialsEntity.created_at > time - ) + filters = [AzureSubscriptionCredentialsEntity.created_at > time] + if can_access_azure_account is not None: + filters.append(AzureSubscriptionCredentialsEntity.can_access_azure_account.is_(can_access_azure_account)) + query = select(AzureSubscriptionCredentialsEntity).filter(*filters) result = await session.execute(query) return [entity.to_model() for entity in result.scalars()] diff --git a/fixbackend/cloud_accounts/azure_subscription_service.py b/fixbackend/cloud_accounts/azure_subscription_service.py index 6bd8dd49..d0824242 100644 --- a/fixbackend/cloud_accounts/azure_subscription_service.py +++ b/fixbackend/cloud_accounts/azure_subscription_service.py @@ -139,7 +139,8 @@ async def _import_subscriptions(self, creds: AzureSubscriptionCredentials) -> No async def _ping_new_subscriptions(self) -> None: created_less_than_30_minutes_ago = await self.azure_subscriptions_repo.list_created_after( - utc() - timedelta(minutes=30) + utc() - timedelta(minutes=30), + can_access_azure_account=False ) async with asyncio.TaskGroup() as tg: