diff --git a/CHANGELOG b/CHANGELOG index fdd544a0..4b0c6e4b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,7 @@ When using `mass_background_update`, added `ignore_locked` attribute which will Add `date` option for schedules Add `trakt`, `omdb_metascore`, `omdb_tomatoes` ratings sources for mass operations. Add `trakt` ratings source for mass episode operations. +Added GitHub token validation during config validation. # Docs Added "getting started" page diff --git a/VERSION b/VERSION index c6edcf55..b8ca027e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.0-build49 +2.1.0-build50 diff --git a/kometa.py b/kometa.py index 2ccd4494..b67a4677 100644 --- a/kometa.py +++ b/kometa.py @@ -205,14 +205,12 @@ elif not os.path.exists(os.path.join(default_dir, "config.yml")): print(f"Configuration File ('config.yml') has been downloaded from GitHub (Branch: '{git_branch}') and saved as '{config_path}'. Please update this file with your API keys and other required settings.") sys.exit(1) else: - print(f"Config Error: Unable to download the configuration file from GitHub (URL: {github_url}'). Please save it as '{config_path}' before running Kometa again.") - sys.exit(1) + raise requests.RequestException except requests.RequestException as e: print(f"Config Error: Unable to download the configuration file from GitHub (URL: {github_url}'). Please save it as '{config_path}' before running Kometa again.") sys.exit(1) - logger = MyLogger("Kometa", default_dir, run_args["width"], run_args["divider"][0], run_args["ignore-ghost"], run_args["tests"] or run_args["debug"], run_args["trace"], run_args["log-requests"]) diff --git a/modules/config.py b/modules/config.py index 0b11fb83..687205cc 100644 --- a/modules/config.py +++ b/modules/config.py @@ -548,6 +548,7 @@ class ConfigFile: self.Cache = Cache(self.config_path, self.general["cache_expiration"]) else: self.Cache = None + self.GitHub = GitHub(self.Requests, { "token": check_for_attribute(self.data, "token", parent="github", default_is_none=True) }) diff --git a/modules/github.py b/modules/github.py index 768b0fc0..0a14c2d6 100644 --- a/modules/github.py +++ b/modules/github.py @@ -13,8 +13,19 @@ class GitHub: def __init__(self, requests, params): self.requests = requests self.token = params["token"] - logger.secret(self.token) - self.headers = {"Authorization": f"token {self.token}"} if self.token else None + self.headers = None + if self.token: + logger.separator() + logger.info("Connecting to GitHub...") + logger.secret(self.token) + self.headers = {"Authorization": f"token {self.token}"} + try: + response = self._requests("https://api.github.com/user", err_msg="The GitHub token specified could not be validated. Please verify that the token is correct.") + logger.info(f"GitHub token validated successfully. Authenticated as {response['login']}") + except Failed as e: + self.token = None + self.headers = None + logger.error(e) self.images_raw_url = f"{raw_url}/Kometa-Team/Image-Sets/master/sets/" self.translation_url = f"{raw_url}/Kometa-Team/Translations/master/defaults/" self._configs_url = None @@ -29,14 +40,13 @@ class GitHub: return self.requests.get_yaml(url, headers=self.headers, params=params) response = self.requests.get(url, headers=self.headers, params=params) if response.status_code >= 400: - logger.stacktrace() - logger.error(response.reason) - raise Failed(f"Git Error: {err_msg}") + raise Failed(f"GitHub Error: {err_msg} Response: {response.status_code} - {response.reason} ") try: return response.json() except ValueError: + logger.stacktrace() logger.error(str(response.content)) - raise + raise Failed("GitHub JSON Unpack Error") def get_top_tree(self, repo): if not str(repo).startswith("/"):