Issue #698: Fix roles list keys - #755
Conversation
renatav
left a comment
There was a problem hiding this comment.
I think is very close to being what we need. My main concern is keeping the public api as intuitive and clean as possible, so it might be a good idea to refactor this a bit before merging.
| return f"Role: {role_label}\n" + "\n".join(key_lines) | ||
|
|
||
|
|
||
| def _roles_for_keys(auth_repo: AuthenticationRepository) -> Dict[str, set]: |
There was a problem hiding this comment.
It was surprising that a similar utility was not already somewhere in the codebase. Let's move this to tuf/repository/MetadataRepository
|
|
||
| def _roles_for_keys(auth_repo: AuthenticationRepository) -> Dict[str, set]: | ||
| roles_for_key: Dict[str, set] = defaultdict(set) | ||
| for role_name in auth_repo.get_all_roles(): |
There was a problem hiding this comment.
This works, but is not the most efficient solution. That is fine as we do not expect to ever encounter a situation where we have hundreds of roles.
get_all_roles() walks the full delegation tree and in doing so, it already knows each role's parent, but throws that away and returns a flat list. Then, for each of those role names, get_role_keys(role_name) has to call find_delegated_roles_parent(role). Implementing something similar to find_keysid_roles would be more efficient.
However, this is fine as is, unless you want to tackle the harder implementation as a way of getting more familiar with the system.
| on_exceptions=TAFError, | ||
| reraise=True, | ||
| ) | ||
| def list_keys_of_role( |
There was a problem hiding this comment.
I think it's actually better to split the two up:kKeep list_keys_of_role(path, role) exactly as it was (role required), and add a new function for the "all roles" case list_keys_by_roles. This preserves the existing function's contract, and the existing tests should pass without needing any modifications. And then the CLI could call one or the other.
Description
Fix
taf roles list-keyswhen called without a role argument so it prints each key with its associated role(s), instead of only showing key IDs.Also added CLI test coverage for
taf roles list-keys --path <repo>with no role positional argument.Code review checklist (for code reviewer to complete)