Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mxrch
GitHub Repository: mxrch/GHunt
Path: blob/master/ghunt/helpers/iam.py
252 views
1
import httpx
2
import asyncio
3
4
from ghunt.objects.base import GHuntCreds
5
from ghunt.apis.mobilesdk import MobileSDKPaHttp
6
from ghunt.knowledge import iam
7
from ghunt.helpers.utils import chunkify
8
9
from typing import *
10
11
12
async def test_all_permissions(as_client: httpx.AsyncClient, ghunt_creds: GHuntCreds, project_identifier: str):
13
14
async def test_permission(as_client: httpx.AsyncClient, mobilesdk_api: MobileSDKPaHttp, limiter: asyncio.Semaphore,
15
project_identifier: str, permissions: List[str], results: List[str]):
16
async with limiter:
17
_, perms = await mobilesdk_api.test_iam_permissions(as_client, project_identifier, permissions)
18
results.extend(perms)
19
20
mobilesdk_api = MobileSDKPaHttp(ghunt_creds)
21
results: List[str] = []
22
limiter = asyncio.Semaphore(20)
23
tasks = []
24
for perms_chunk in chunkify(iam.permissions, 100): # Max 100 permissions per request
25
tasks.append(test_permission(as_client, mobilesdk_api, limiter, project_identifier, perms_chunk, results))
26
await asyncio.gather(*tasks)
27
28
results = list(set(results))
29
print(results)
30