|
131 | 131 |
|
132 | 132 | import tuf |
133 | 133 | import tuf.download |
| 134 | +import tuf.fetcher |
134 | 135 | import tuf.formats |
135 | 136 | import tuf.settings |
136 | 137 | import tuf.keydb |
@@ -619,7 +620,7 @@ class Updater(object): |
619 | 620 | http://www.python.org/dev/peps/pep-0008/#method-names-and-instance-variables |
620 | 621 | """ |
621 | 622 |
|
622 | | - def __init__(self, repository_name, repository_mirrors): |
| 623 | + def __init__(self, repository_name, repository_mirrors, fetcher=None): |
623 | 624 | """ |
624 | 625 | <Purpose> |
625 | 626 | Constructor. Instantiating an updater object causes all the metadata |
@@ -659,6 +660,11 @@ def __init__(self, repository_name, repository_mirrors): |
659 | 660 | 'targets_path': 'targets', |
660 | 661 | 'confined_target_dirs': ['']}} |
661 | 662 |
|
| 663 | + fetcher: |
| 664 | + A concrete 'FetcherInterface' implementation. Performs the network |
| 665 | + related download operations. If an external implementation is not |
| 666 | + provided, tuf.fetcher.RequestsFetcher is used. |
| 667 | +
|
662 | 668 | <Exceptions> |
663 | 669 | securesystemslib.exceptions.FormatError: |
664 | 670 | If the arguments are improperly formatted. |
@@ -688,6 +694,13 @@ def __init__(self, repository_name, repository_mirrors): |
688 | 694 | self.repository_name = repository_name |
689 | 695 | self.mirrors = repository_mirrors |
690 | 696 |
|
| 697 | + # Initialize Updater with an externally provided 'fetcher' implementing |
| 698 | + # the network download. By default tuf.fetcher.RequestsFetcher is used. |
| 699 | + if fetcher is None: |
| 700 | + self.fetcher = tuf.fetcher.RequestsFetcher() |
| 701 | + else: |
| 702 | + self.fetcher = fetcher |
| 703 | + |
691 | 704 | # Store the trusted metadata read from disk. |
692 | 705 | self.metadata = {} |
693 | 706 |
|
@@ -1311,7 +1324,8 @@ def _get_target_file(self, target_filepath, file_length, file_hashes, |
1311 | 1324 |
|
1312 | 1325 | for file_mirror in file_mirrors: |
1313 | 1326 | try: |
1314 | | - file_object = tuf.download.safe_download(file_mirror, file_length) |
| 1327 | + file_object = tuf.download.safe_download(file_mirror, |
| 1328 | + file_length, self.fetcher) |
1315 | 1329 |
|
1316 | 1330 | # Verify 'file_object' against the expected length and hashes. |
1317 | 1331 | self._check_file_length(file_object, file_length) |
@@ -1509,7 +1523,7 @@ def _get_metadata_file(self, metadata_role, remote_filename, |
1509 | 1523 | for file_mirror in file_mirrors: |
1510 | 1524 | try: |
1511 | 1525 | file_object = tuf.download.unsafe_download(file_mirror, |
1512 | | - upperbound_filelength) |
| 1526 | + upperbound_filelength, self.fetcher) |
1513 | 1527 | file_object.seek(0) |
1514 | 1528 |
|
1515 | 1529 | # Verify 'file_object' according to the callable function. |
|
0 commit comments