MCPcopy
hub / github.com/mxrch/GHunt / _load_api

Method _load_api

ghunt/objects/apis.py:34–64  ·  view source on GitHub ↗
(self, creds: GHuntCreds, headers: Dict[str, str])

Source from the content-addressed store, hash-verified

32 self.key_origin: str = ""
33
34 def _load_api(self, creds: GHuntCreds, headers: Dict[str, str]):
35 if not creds.are_creds_loaded():
36 raise GHuntInsufficientCreds(f"This API requires a loaded GHuntCreds object, but it is not.")
37
38 if not is_headers_syntax_good(headers):
39 raise GHuntCorruptedHeadersError(f"The provided headers when loading the endpoint seems corrupted, please check it : {headers}")
40
41 if self.authentication_mode == "oauth":
42 self.gen_token_lock = asyncio.Semaphore(1)
43
44 cookies = {}
45 if self.authentication_mode in ["sapisidhash", "cookies_only"]:
46 if not (cookies := creds.cookies):
47 raise GHuntInsufficientCreds(f"This endpoint requires the cookies in the GHuntCreds object, but they aren't loaded.")
48
49 if (key_name := self.require_key):
50 if not (api_key := get_api_key(key_name)):
51 raise GHuntInsufficientCreds(f"This API requires the {key_name} API key in the GHuntCreds object, but it isn't loaded.")
52 if not self.key_origin:
53 self.key_origin = get_origin_of_key(key_name)
54 headers = {**headers, "X-Goog-Api-Key": api_key, **headers, "Origin": self.key_origin, "Referer": self.key_origin}
55
56 if self.authentication_mode == "sapisidhash":
57 if not (sapisidhash := creds.cookies.get("SAPISID")):
58 raise GHuntInsufficientCreds(f"This endpoint requires the SAPISID cookie in the GHuntCreds object, but it isn't loaded.")
59
60 headers = {**headers, "Authorization": f"SAPISIDHASH {gen_sapisidhash(sapisidhash, self.key_origin)}"}
61
62 self.creds = creds
63 self.headers = headers
64 self.cookies = cookies
65
66 def _load_endpoint(self, endpoint_name: str,
67 headers: Dict[str, str]={}, ext_metadata: Dict[str, str]={}):

Callers 9

__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80

Calls 7

get_api_keyFunction · 0.90
get_origin_of_keyFunction · 0.90
is_headers_syntax_goodFunction · 0.85
gen_sapisidhashFunction · 0.85
are_creds_loadedMethod · 0.80

Tested by

no test coverage detected