Skip to content

Commit

Permalink
feat: add can_access parameter to list_created_after and update its u…
Browse files Browse the repository at this point in the history
…sage
  • Loading branch information
meln1k committed Oct 22, 2024
1 parent 5c778e4 commit bdad361
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions fixbackend/cloud_accounts/azure_subscription_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]

Expand Down
3 changes: 2 additions & 1 deletion fixbackend/cloud_accounts/azure_subscription_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bdad361

Please sign in to comment.