-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TUF Offline Functionality #2363
Closed
Closed
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0d976f8
offline mode added to TrustedMetadataSet
omartounsi7 d0e5529
Fixed case where get_targetinfo() call would lead to _load_targets() …
emboman13 323eadf
Causing download_target() to fail if updater is offline
omartounsi7 d50ef8d
tests check for appropriate exceptions. updaterconfig class ignores t…
emilejbm 17b03d5
Merge branch 'develop' into develop
emboman13 ac76edc
checking for offline done with self._trusted_set.offline
emilejbm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,9 +101,11 @@ def __init__( | |
|
||
# Read trusted local root metadata | ||
data = self._load_local_metadata(Root.type) | ||
self._trusted_set = trusted_metadata_set.TrustedMetadataSet(data) | ||
self._fetcher = fetcher or requests_fetcher.RequestsFetcher() | ||
self.config = config or UpdaterConfig() | ||
self._trusted_set = trusted_metadata_set.TrustedMetadataSet( | ||
data, self.config.offline | ||
) | ||
|
||
def refresh(self) -> None: | ||
"""Refresh top-level metadata. | ||
|
@@ -129,6 +131,17 @@ def refresh(self) -> None: | |
DownloadError: Download of a metadata file failed in some way | ||
""" | ||
|
||
if self.config.offline: | ||
# Try loading only local data | ||
data = self._load_local_metadata(Timestamp.type) | ||
self._trusted_set.update_timestamp(data) | ||
data = self._load_local_metadata(Snapshot.type) | ||
self._trusted_set.update_snapshot(data, trusted=True) | ||
data = self._load_local_metadata(Targets.type) | ||
self._trusted_set.update_delegated_targets( | ||
data, Targets.type, Root.type | ||
) | ||
return | ||
self._load_root() | ||
self._load_timestamp() | ||
self._load_snapshot() | ||
|
@@ -224,11 +237,15 @@ def download_target( | |
DownloadError: Download of the target file failed in some way | ||
RepositoryError: Downloaded target failed to be verified in some way | ||
OSError: Failed to write target to file | ||
RuntimeError: Download of target file cannot occur because in offline mode | ||
|
||
Returns: | ||
Local path to downloaded file | ||
""" | ||
|
||
if self.config.offline: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably check |
||
raise RuntimeError("Cannot download when offline") | ||
|
||
if filepath is None: | ||
filepath = self._generate_target_file_path(targetinfo) | ||
|
||
|
@@ -386,6 +403,9 @@ def _load_targets(self, role: str, parent_role: str) -> Metadata[Targets]: | |
logger.debug("Local %s is valid: not downloading new one", role) | ||
return delegated_targets | ||
except (OSError, exceptions.RepositoryError) as e: | ||
# fails if local data is unavalible and in offline mode | ||
if self.config.offline: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably check |
||
raise exceptions.DownloadError("Local metadata is missing; cannot download new metadata in offline mode") | ||
# Local 'role' does not exist or is invalid: update from remote | ||
logger.debug("Failed to load local %s: %s", role, e) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably check
self._trusted_set.offline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that be necessary? That is just set as self.config,offline on line 106-107?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.config.offline
can be modified by the user after the Updater has been initialized but before the other methods are called. This does not make a lot of sense, but technically it is possible. In other words, if we check check self.config.offline here it may well be False even though self._trusted_set has been initialized as offline.The current test case seems to be a good example of this.