Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mxrch
GitHub Repository: mxrch/GHunt
Path: blob/master/ghunt/apis/clientauthconfig.py
252 views
1
from ghunt.objects.base import GHuntCreds
2
from ghunt.errors import *
3
import ghunt.globals as gb
4
from ghunt.objects.apis import GAPI, EndpointConfig
5
from ghunt.parsers.clientauthconfig import CacBrand
6
7
import httpx
8
9
from typing import *
10
import inspect
11
import json
12
13
14
class ClientAuthConfigHttp(GAPI):
15
def __init__(self, creds: GHuntCreds, headers: Dict[str, str] = {}):
16
super().__init__()
17
18
if not headers:
19
headers = gb.config.headers
20
21
base_headers = {}
22
23
headers = {**headers, **base_headers}
24
25
self.hostname = "clientauthconfig.googleapis.com"
26
self.scheme = "https"
27
28
self._load_api(creds, headers)
29
30
async def get_brand(self, as_client: httpx.AsyncClient, project_number: int) -> Tuple[bool, CacBrand]:
31
endpoint = EndpointConfig(
32
name = inspect.currentframe().f_code.co_name,
33
verb = "GET",
34
data_type = None, # json, data or None
35
authentication_mode = None, # sapisidhash, cookies_only, oauth or None
36
require_key = "pantheon", # key name, or None
37
)
38
self._load_endpoint(endpoint)
39
40
base_url = f"/v1/brands/lookupkey/brand/{project_number}"
41
42
params = {
43
"readMask": "*",
44
"$outputDefaults": True
45
}
46
47
req = await self._query(endpoint.name, as_client, base_url, params=params)
48
49
# Parsing
50
data = json.loads(req.text)
51
52
brand = CacBrand()
53
if "error" in data:
54
return False, brand
55
56
brand._scrape(data)
57
58
return True, brand
59