Skip to content

Commit

Permalink
Merge 660eb25 into 5dde1e7
Browse files Browse the repository at this point in the history
  • Loading branch information
sechkova committed Apr 20, 2021
2 parents 5dde1e7 + 660eb25 commit 51b60c3
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 214 deletions.
3 changes: 1 addition & 2 deletions tuf/client_rework/metadata_wrapper.py
Expand Up @@ -22,9 +22,8 @@ def __init__(self, meta):
self._meta = meta

@classmethod
def from_json_object(cls, tmp_file):
def from_json_object(cls, raw_data):
"""Loads JSON-formatted TUF metadata from a file object."""
raw_data = tmp_file.read()
# Use local scope import to avoid circular import errors
# pylint: disable=import-outside-toplevel
from tuf.api.serialization.json import JSONDeserializer
Expand Down
68 changes: 1 addition & 67 deletions tuf/client_rework/mirrors.py
Expand Up @@ -23,15 +23,13 @@
"""

import os
from typing import BinaryIO, Dict, TextIO
from urllib import parse

from securesystemslib import exceptions as sslib_exceptions
from securesystemslib import formats as sslib_formats
from securesystemslib import util as sslib_util

from tuf import exceptions, formats
from tuf.client_rework import download
from tuf import formats

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

return list_of_mirrors


def mirror_meta_download(
filename: str,
upper_length: int,
mirrors_config: Dict,
fetcher: "FetcherInterface",
) -> TextIO:
"""
Download metadata file from the list of metadata mirrors
"""
file_mirrors = get_list_of_mirrors("meta", filename, mirrors_config)

file_mirror_errors = {}
for file_mirror in file_mirrors:
try:
temp_obj = download.download_file(
file_mirror, upper_length, fetcher, strict_required_length=False
)

temp_obj.seek(0)
yield temp_obj

# pylint cannot figure out that we store the exceptions
# in a dictionary to raise them later so we disable
# the warning. This should be reviewed in the future still.
except Exception as exception: # pylint: disable=broad-except
file_mirror_errors[file_mirror] = exception

finally:
if file_mirror_errors:
raise exceptions.NoWorkingMirrorError(file_mirror_errors)


def mirror_target_download(
fileinfo: str, mirrors_config: Dict, fetcher: "FetcherInterface"
) -> BinaryIO:
"""
Download target file from the list of target mirrors
"""
# full_filename = _get_full_name(filename)
file_mirrors = get_list_of_mirrors(
"target", fileinfo["filepath"], mirrors_config
)

file_mirror_errors = {}
for file_mirror in file_mirrors:
try:
temp_obj = download.download_file(
file_mirror, fileinfo["fileinfo"]["length"], fetcher
)

temp_obj.seek(0)
yield temp_obj

# pylint cannot figure out that we store the exceptions
# in a dictionary to raise them later so we disable
# the warning. This should be reviewed in the future still.
except Exception as exception: # pylint: disable=broad-except
file_mirror_errors[file_mirror] = exception

finally:
if file_mirror_errors:
raise exceptions.NoWorkingMirrorError(file_mirror_errors)

0 comments on commit 51b60c3

Please sign in to comment.