Skip to content

Commit 13766cc

Browse files
reckless: remove remaining traces of API access
Including the canned server in the pytest infrastructure.
1 parent a1bc87f commit 13766cc

File tree

3 files changed

+12
-108
lines changed

3 files changed

+12
-108
lines changed

tests/data/recklessrepo/rkls_api_lightningd_plugins.json

Lines changed: 0 additions & 47 deletions
This file was deleted.

tests/test_reckless.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
from fixtures import * # noqa: F401,F403
2-
import subprocess
3-
from pathlib import PosixPath, Path
4-
import socket
5-
from pyln.testing.utils import VALGRIND
61
import json
7-
import pytest
82
import os
3+
from pathlib import PosixPath, Path
94
import re
10-
import shutil
5+
import subprocess
116
import time
127
import unittest
8+
from fixtures import * # noqa: F401,F403
9+
from pyln.testing.utils import VALGRIND
10+
import pytest
1311

1412

1513
@pytest.fixture(autouse=True)
@@ -22,20 +20,10 @@ def canned_github_server(directory):
2220
if os.environ.get('LIGHTNING_CLI') is None:
2321
os.environ['LIGHTNING_CLI'] = str(FILE_PATH.parent / 'cli/lightning-cli')
2422
print('LIGHTNING_CALL: ', os.environ.get('LIGHTNING_CLI'))
25-
# Use socket to provision a random free port
26-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
27-
sock.bind(('localhost', 0))
28-
free_port = str(sock.getsockname()[1])
29-
sock.close()
3023
global my_env
3124
my_env = os.environ.copy()
32-
# This tells reckless to redirect to the canned server rather than github.
33-
my_env['REDIR_GITHUB_API'] = f'http://127.0.0.1:{free_port}/api'
25+
# This tells reckless to redirect to the local test plugins repo rather than github.
3426
my_env['REDIR_GITHUB'] = directory
35-
my_env['FLASK_RUN_PORT'] = free_port
36-
my_env['FLASK_APP'] = str(FILE_PATH / 'rkls_github_canned_server')
37-
server = subprocess.Popen(["python3", "-m", "flask", "run"],
38-
env=my_env)
3927

4028
# Generate test plugin repository to test reckless against.
4129
repo_dir = os.path.join(directory, "lightningd")
@@ -84,13 +72,10 @@ def canned_github_server(directory):
8472
del my_env['GIT_DIR']
8573
del my_env['GIT_WORK_TREE']
8674
del my_env['GIT_INDEX_FILE']
87-
# We also need the github api data for the repo which will be served via http
88-
shutil.copyfile(str(FILE_PATH / 'data/recklessrepo/rkls_api_lightningd_plugins.json'), os.path.join(directory, 'rkls_api_lightningd_plugins.json'))
8975
yield
9076
# Delete requirements.txt from the testplugpass directory
9177
with open(requirements_file_path, 'w') as f:
9278
f.write(f"pyln-client\n\n")
93-
server.terminate()
9479

9580

9681
class RecklessResult:

tools/reckless

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import types
1818
from typing import Union
1919
from urllib.parse import urlparse
2020
from urllib.request import urlopen
21-
from urllib.error import HTTPError
2221
import venv
2322

2423

@@ -258,7 +257,7 @@ class Source(Enum):
258257
REMOTE_GIT_REPO = 3
259258
OTHER_URL = 4
260259
UNKNOWN = 5
261-
# Cloned from remote source before searching (rather than github API)
260+
# Cloned from remote source before searching
262261
GIT_LOCAL_CLONE = 6
263262

264263
@classmethod
@@ -302,7 +301,7 @@ class SubmoduleSource:
302301
class LoadedSource:
303302
"""Allows loading all sources only once per call of reckless. Initialized
304303
with a single line of the reckless .sources file. Keeping state also allows
305-
minimizing API calls and refetching repositories."""
304+
minimizing refetching repositories."""
306305
def __init__(self, source: str):
307306
self.original_source = source
308307
self.type = Source.get_type(source)
@@ -445,16 +444,12 @@ class InstInfo:
445444
# Set recursion for how many directories deep we should search
446445
depth = 0
447446
if self.srctype in [Source.DIRECTORY, Source.LOCAL_REPO,
448-
Source.GIT_LOCAL_CLONE]:
447+
Source.GIT_LOCAL_CLONE, Source.REMOTE_GIT_REPO]:
449448
depth = 5
450-
elif self.srctype == Source.REMOTE_GIT_REPO:
451-
depth = 1
452449

453450
def search_dir(self, sub: SourceDir, subdir: bool,
454451
recursion: int) -> Union[SourceDir, None]:
455452
assert isinstance(recursion, int)
456-
# carveout for archived plugins in lightningd/plugins. Other repos
457-
# are only searched by API at the top level.
458453
if recursion == 0 and 'archive' in sub.name.lower():
459454
pass
460455
# If unable to search deeper, resort to matching directory name
@@ -501,27 +496,7 @@ class InstInfo:
501496
return success
502497
return None
503498

504-
try:
505-
result = search_dir(self, target, False, depth)
506-
# Using the rest API of github.com may result in a
507-
# "Error 403: rate limit exceeded" or other access issues.
508-
# Fall back to cloning and searching the local copy instead.
509-
except HTTPError:
510-
result = None
511-
if self.srctype == Source.REMOTE_GIT_REPO:
512-
# clone source to reckless dir
513-
target = copy_remote_git_source(self)
514-
if not target:
515-
log.warning(f"could not clone github source {self}")
516-
return False
517-
log.debug(f"falling back to cloning remote repo {self}")
518-
# Update to reflect use of a local clone
519-
self.source_loc = str(target.location)
520-
self.srctype = target.srctype
521-
result = search_dir(self, target, False, 5)
522-
523-
if not result:
524-
return False
499+
result = search_dir(self, target, False, depth)
525500

526501
if result:
527502
if result != target:
@@ -1217,8 +1192,7 @@ def help_alias(targets: list):
12171192

12181193

12191194
def _get_local_clone(source: str) -> Union[Path, None]:
1220-
"""Returns the path of a local repository clone of a github source. If one
1221-
already exists, prefer searching that to accessing the github API."""
1195+
"""Returns the path of a local repository clone of a github source."""
12221196
user, repo = Source.get_github_user_repo(source)
12231197
local_clone_location = RECKLESS_DIR / '.remote_sources' / user / repo
12241198
if local_clone_location.exists():
@@ -1232,8 +1206,7 @@ def _source_search(name: str, src: LoadedSource) -> Union[InstInfo, None]:
12321206
root_dir = src.content
12331207
source = InstInfo(name, root_dir.location)
12341208

1235-
# If a local clone of a github source already exists, prefer searching
1236-
# that instead of accessing the github API.
1209+
# Remote git sources require a local clone before searching.
12371210
if src.type == Source.REMOTE_GIT_REPO:
12381211
if src.local_clone:
12391212
if not src.local_clone_fetched:
@@ -2454,18 +2427,11 @@ if __name__ == '__main__':
24542427
LIGHTNING_CONFIG = args.conf
24552428
RECKLESS_CONFIG = load_config(reckless_dir=str(RECKLESS_DIR),
24562429
network=NETWORK)
2457-
API_GITHUB_COM = 'https://api.github.com'
24582430
GITHUB_COM = 'https://github.com'
24592431
# Used for blackbox testing to avoid hitting github servers
2460-
if 'REDIR_GITHUB_API' in os.environ:
2461-
API_GITHUB_COM = os.environ['REDIR_GITHUB_API']
24622432
if 'REDIR_GITHUB' in os.environ:
24632433
GITHUB_COM = os.environ['REDIR_GITHUB']
24642434

2465-
GITHUB_API_FALLBACK = False
2466-
if 'GITHUB_API_FALLBACK' in os.environ:
2467-
GITHUB_API_FALLBACK = os.environ['GITHUB_API_FALLBACK']
2468-
24692435
RECKLESS_SOURCES = load_sources()
24702436
if 'targets' in args: # and len(args.targets) > 0:
24712437
if args.func.__name__ == 'help_alias':

0 commit comments

Comments
 (0)