reckless: use environment variable redirects

This will be used during CI testing in the following commit.
This commit is contained in:
Alex Myers 2023-04-05 19:28:17 -05:00 committed by Rusty Russell
parent 55cddcd350
commit cf203369bc

View File

@ -51,7 +51,12 @@ class InstInfo:
Populate installation details from a github repo url.
Return True if all data is found.
"""
r = urlopen(self.git_url, timeout=5)
if "api.github.com" in self.git_url:
# This lets us redirect to handle blackbox testing
redir_addr = API_GITHUB_COM + self.git_url.split("api.github.com")[-1]
r = urlopen(redir_addr, timeout=5)
else:
r = urlopen(self.git_url, timeout=5)
if r.status != 200:
return False
if 'git/tree' in self.git_url:
@ -278,7 +283,7 @@ def _search_repo(name: str, url: str) -> InstInfo:
repo_name = parsed_url.path.split('/')[start + 1]
# Get details from the github API.
api_url = f'https://api.github.com/repos/{repo_user}/{repo_name}/contents/'
api_url = f'{API_GITHUB_COM}/repos/{repo_user}/{repo_name}/contents/'
plugins_cont = api_url
r = urlopen(plugins_cont, timeout=5)
if r.status != 200:
@ -311,6 +316,7 @@ def _search_repo(name: str, url: str) -> InstInfo:
MyPlugin.repo = MyPlugin.repo.split('/tree/')[0]
logging.debug(f'repo using commit: {MyPlugin.commit}')
if not MyPlugin.get_inst_details():
logging.debug(f"Found plugin in {url}, but missing install details")
return False
return MyPlugin
return False
@ -337,12 +343,16 @@ def _install_plugin(src: InstInfo) -> bool:
shutil.rmtree(clone_path)
# clone git repository to /tmp/reckless-...
if ('http' in src.repo[:4]) or ('github.com' in src.repo):
if 'github.com' in src.repo:
url = f"{GITHUB_COM}" + src.repo.split("github.com")[-1]
else:
url = src.repo
# Ugly, but interactively handling stderr gets hairy.
if logging.root.level < logging.WARNING:
git = Popen(['git', 'clone', src.repo, str(clone_path)],
stdout=PIPE)
git = Popen(['git', 'clone', url, str(clone_path)],
stdout=PIPE, stderr=PIPE)
else:
git = Popen(['git', 'clone', src.repo, str(clone_path)],
git = Popen(['git', 'clone', url, str(clone_path)],
stdout=PIPE, stderr=PIPE)
git.wait()
if git.returncode != 0:
@ -725,7 +735,10 @@ if __name__ == '__main__':
else:
print(f"Error: {args.network} network not supported")
LIGHTNING_DIR = Path(args.lightning)
LIGHTNING_CLI_CALL = ['lightning-cli']
# This env variable is set under CI testing
LIGHTNING_CLI_CALL = [os.environ.get('LIGHTNING_CLI')]
if LIGHTNING_CLI_CALL is None:
LIGHTNING_CLI_CALL = ['lightning-cli']
if NETWORK != 'bitcoin':
LIGHTNING_CLI_CALL.append(f'--network={NETWORK}')
if LIGHTNING_DIR != Path.home().joinpath('.lightning'):
@ -738,6 +751,13 @@ if __name__ == '__main__':
RECKLESS_CONFIG = load_config(reckless_dir=RECKLESS_DIR,
network=NETWORK)
RECKLESS_SOURCES = loadSources()
API_GITHUB_COM = 'https://api.github.com'
GITHUB_COM = 'https://github.com'
# Used for blackbox testing to avoid hitting github servers
if 'REDIR_GITHUB_API' in os.environ:
API_GITHUB_COM = os.environ['REDIR_GITHUB_API']
if 'REDIR_GITHUB' in os.environ:
GITHUB_COM = os.environ['REDIR_GITHUB']
logging.root.setLevel(args.loglevel)
if 'targets' in args: