From f05e120c838ebd5d2573ba16242be6ad40c7d555 Mon Sep 17 00:00:00 2001 From: Dom Whewell Date: Mon, 11 Dec 2023 19:25:09 +0000 Subject: [PATCH] Created an optional_api_key async function to check if an API key has been supplied for any github module --- bbot/modules/templates/github.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/bbot/modules/templates/github.py b/bbot/modules/templates/github.py index ecf797c69f..be3d75486c 100644 --- a/bbot/modules/templates/github.py +++ b/bbot/modules/templates/github.py @@ -9,10 +9,29 @@ class github(subdomain_enum_apikey): base_url = "https://api.github.com" + async def optional_api_key(self): + self.api_key = None + for module_name in ("github", "github_codesearch", "github_org"): + module_config = self.scan.config.get("modules", {}).get(module_name, {}) + api_key = module_config.get("api_key", "") + if api_key: + self.api_key = api_key + break + if self.api_key: + try: + await self.ping() + self.hugesuccess(f"API is ready") + self.headers = {"Authorization": f"token {self.api_key}"} + return True + except Exception as e: + return None, f"Error with API ({str(e).strip()})" + else: + self.headers = {} + return True + async def setup(self): - ret = await super().setup() - self.headers = {"Authorization": f"token {self.api_key}"} - return ret + self.processed = set() + return await self.optional_api_key() async def ping(self): url = f"{self.base_url}/zen"