Skip to content

Commit 79aa42a

Browse files
author
Jussi Kukkonen
authored
Merge pull request #1352 from sechkova/mirrors-loop
client refactor: simplify mirrors loop
2 parents d7b68fc + dd11098 commit 79aa42a

File tree

3 files changed

+253
-215
lines changed

3 files changed

+253
-215
lines changed

tuf/client_rework/metadata_wrapper.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ def __init__(self, meta):
2222
self._meta = meta
2323

2424
@classmethod
25-
def from_json_object(cls, tmp_file):
25+
def from_json_object(cls, raw_data):
2626
"""Loads JSON-formatted TUF metadata from a file object."""
27-
raw_data = tmp_file.read()
2827
# Use local scope import to avoid circular import errors
2928
# pylint: disable=import-outside-toplevel
3029
from tuf.api.serialization.json import JSONDeserializer

tuf/client_rework/mirrors.py

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
"""
2424

2525
import os
26-
from typing import BinaryIO, Dict, TextIO
2726
from urllib import parse
2827

2928
from securesystemslib import exceptions as sslib_exceptions
3029
from securesystemslib import formats as sslib_formats
3130
from securesystemslib import util as sslib_util
3231

33-
from tuf import exceptions, formats
34-
from tuf.client_rework import download
32+
from tuf import formats
3533

3634
# The type of file to be downloaded from a repository. The
3735
# 'get_list_of_mirrors' function supports these file types.
@@ -130,67 +128,3 @@ def get_list_of_mirrors(file_type, file_path, mirrors_dict):
130128
list_of_mirrors.append(url.replace("\\", "/"))
131129

132130
return list_of_mirrors
133-
134-
135-
def mirror_meta_download(
136-
filename: str,
137-
upper_length: int,
138-
mirrors_config: Dict,
139-
fetcher: "FetcherInterface",
140-
) -> TextIO:
141-
"""
142-
Download metadata file from the list of metadata mirrors
143-
"""
144-
file_mirrors = get_list_of_mirrors("meta", filename, mirrors_config)
145-
146-
file_mirror_errors = {}
147-
for file_mirror in file_mirrors:
148-
try:
149-
temp_obj = download.download_file(
150-
file_mirror, upper_length, fetcher, strict_required_length=False
151-
)
152-
153-
temp_obj.seek(0)
154-
yield temp_obj
155-
156-
# pylint cannot figure out that we store the exceptions
157-
# in a dictionary to raise them later so we disable
158-
# the warning. This should be reviewed in the future still.
159-
except Exception as exception: # pylint: disable=broad-except
160-
file_mirror_errors[file_mirror] = exception
161-
162-
finally:
163-
if file_mirror_errors:
164-
raise exceptions.NoWorkingMirrorError(file_mirror_errors)
165-
166-
167-
def mirror_target_download(
168-
fileinfo: str, mirrors_config: Dict, fetcher: "FetcherInterface"
169-
) -> BinaryIO:
170-
"""
171-
Download target file from the list of target mirrors
172-
"""
173-
# full_filename = _get_full_name(filename)
174-
file_mirrors = get_list_of_mirrors(
175-
"target", fileinfo["filepath"], mirrors_config
176-
)
177-
178-
file_mirror_errors = {}
179-
for file_mirror in file_mirrors:
180-
try:
181-
temp_obj = download.download_file(
182-
file_mirror, fileinfo["fileinfo"]["length"], fetcher
183-
)
184-
185-
temp_obj.seek(0)
186-
yield temp_obj
187-
188-
# pylint cannot figure out that we store the exceptions
189-
# in a dictionary to raise them later so we disable
190-
# the warning. This should be reviewed in the future still.
191-
except Exception as exception: # pylint: disable=broad-except
192-
file_mirror_errors[file_mirror] = exception
193-
194-
finally:
195-
if file_mirror_errors:
196-
raise exceptions.NoWorkingMirrorError(file_mirror_errors)

0 commit comments

Comments
 (0)