From 63f381c93e6bab93c153172514609a0916b5898d Mon Sep 17 00:00:00 2001 From: MennaEssa Date: Tue, 14 Sep 2021 15:58:42 +0200 Subject: [PATCH] support private repos but adding auth_token key to yaml --- mussels/mussels.py | 5 +++++ mussels/recipe.py | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mussels/mussels.py b/mussels/mussels.py index dfcf0b2..8a3b3a4 100644 --- a/mussels/mussels.py +++ b/mussels/mussels.py @@ -260,6 +260,11 @@ def load_directory(self, cookbook: str, load_path: str) -> tuple: continue else: recipe_class.url = yaml_file["url"] + + if "auth_token" in yaml_file: + recipe_class.auth_token = yaml_file["auth_token"] + self.logger.debug("found auth. token " + yaml_file["auth_token"] ) + if "archive_name_change" in yaml_file: recipe_class.archive_name_change = ( diff --git a/mussels/recipe.py b/mussels/recipe.py index ffa4909..38a0126 100644 --- a/mussels/recipe.py +++ b/mussels/recipe.py @@ -38,6 +38,7 @@ import requests import urllib.request import patch +from requests.api import head from mussels.utils.versions import pick_platform, nvc_str @@ -64,6 +65,8 @@ class BaseRecipe(object): # This hack is necessary because archives with changed names will extract to their original directory name. archive_name_change: tuple = ("", "") + auth_token = "" + platforms: dict = {} # Dictionary of recipe instructions for each platform. builds: dict = {} # Dictionary of build paths. @@ -192,7 +195,10 @@ def _download_archive(self) -> bool: return False else: try: - r = requests.get(self.url) + self.logger.debug("downloading using auth_token " + self.auth_token) + headers_dict={'Authorization': 'token '+self.auth_token} + r = requests.get(self.url , headers=headers_dict) + self.logger.debug(r.status_code) with open(self.download_path, "wb") as f: f.write(r.content) except Exception: