-
Notifications
You must be signed in to change notification settings - Fork 278
Refactor add_target_to_bin
and remove_target_from_bin
#994
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
Comments
Note, the snippet above assumes that the hash_prefix is correctly left-zero-padded. It might be safer to pass |
If I'm not mistaken this should be as easy as def add_target_to_bin(self, target_filepath, number_of_bins):
path_hash = _get_hash(target_filepath) # TODO: add helper using 'securesystemslib.hash'
bin_name = _ find_bin_for_hash(path_hash, number_of_bins) # TODO: Slightly modify and add 'find_bin_for_hash' from above
self._delegated_roles[hashed_bin_name]).add_target(target_filepath) ... (modulo testing, sanitizing inputs, failing gracefully). And the same should work for |
Add a helper function to determine the name of a bin that a hashed targetfile will be delegated to. Based sketches by Lukas Puehringer in issues theupdateframework#994 & theupdateframework#995 Signed-off-by: Joshua Lock <jlock@vmware.com>
Add a helper function to determine the name of a bin that a hashed targetfile will be delegated to. Based sketches by Lukas Puehringer in issues theupdateframework#994 & theupdateframework#995 Signed-off-by: Joshua Lock <jlock@vmware.com>
Add a helper function to determine the name of a bin that a hashed targetfile will be delegated to. Based sketches by Lukas Puehringer in issues theupdateframework#994 & theupdateframework#995 Signed-off-by: Joshua Lock <jlock@vmware.com>
Add a helper function to determine the name of a bin that a hashed targetfile will be delegated to. Based sketches by Lukas Puehringer in issues theupdateframework#994 & theupdateframework#995 Signed-off-by: Joshua Lock <jlock@vmware.com>
Add a helper function to determine the name of a bin that a hashed targetfile will be delegated to. Based sketches by Lukas Puehringer in issues theupdateframework#994 & theupdateframework#995 Signed-off-by: Joshua Lock <jlock@vmware.com>
Fixed in #1007 |
Description of issue or feature request:
The TUF repository tool provides a functionality to distribute a large number of target files over multiple delegated roles (see
delegate_hashed_bins
).To add a target to the corresponding bin, identified by the hash of the target path, or remove one from a bin the methods remove
add_target_to_bin
andremove_target_from_bin
are provided. These methods are wrappers aroundadd_target
andremove_target
, which don't call those methods directly but via a dispatcher helper_locate_and_update_target_in_bin
, which also implements common functionality for the wrappers.These methods should be refactored for the reasons and as outlined below:
Current behavior:
The current architecture doesn't allow to pass through different arguments to the wrapped methods, e.g. the
custom
argument only supported byadd_target
:https://github.com/theupdateframework/tuf/blob/4fe29d138df02035eed9716657cfe0a76e17e178/tuf/repository_tool.py#L2672
_locate_and_update_target_in_bin
doesn't seem to be designed to dispatch to any other methods thanadd_target
andremove_target
to justify the dispatcher architecture_locate_and_update_target_in_bin
replicates functionality from the wrapped methods, e.g. that the targets path exists as file in the current directoryhttps://github.com/theupdateframework/tuf/blob/4fe29d138df02035eed9716657cfe0a76e17e178/tuf/repository_tool.py#L2737-L2739
(see Targets'
add_target(s)
methods do not correctly check passed paths #957 for reasons why that might not even be necessary)._locate_and_update_target_in_bin
makes risky assumption, e.g. it infers thehash_prefix_length
(i.e.len(hex(number_of_bins - 1)[2:])
), by taking the length of the first element in thepath_hash_prefixes
field of the first delegation of the targets object on which it is called.https://github.com/theupdateframework/tuf/blob/4fe29d138df02035eed9716657cfe0a76e17e178/tuf/repository_tool.py#L2719-L2733
_locate_and_update_target_in_bin
makes aO(1)
searchO(n)
.https://github.com/theupdateframework/tuf/blob/4fe29d138df02035eed9716657cfe0a76e17e178/tuf/repository_tool.py#L2749-L2756
Expected behavior:
custom
argument toadd_target_to_bin
that gets passed throughhash_prefix_length
ornumber_of_bins
instead of inferring it from the metadata (the calling code should know this).O(1)
, e.g.:The text was updated successfully, but these errors were encountered: