Skip to content

Commit

Permalink
Simulator to work with succinct hash delegations
Browse files Browse the repository at this point in the history
Change RepositorySimulator.add_delegations() to work with delegated
role "role" that uses succinct hash delegations.
This case is special as for that role we are not creating one target,
but we are creating target metadata instances for all bins.

Signed-off-by: Martin Vrachev <[email protected]>
  • Loading branch information
MVrachev committed May 4, 2022
1 parent ffe8591 commit 4a24ed6
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions tests/repository_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ def add_target(self, role: str, data: bytes, path: str) -> None:
self.target_files[path] = RepositoryTarget(data, target)

def add_delegation(
self, delegator_name: str, role: DelegatedRole, targets: Targets
self,
delegator_name: str,
role: DelegatedRole,
targets: Optional[Targets],
) -> None:
"""Add delegated target role to the repository."""
if delegator_name == Targets.type:
Expand All @@ -359,20 +362,31 @@ def add_delegation(
delegator.delegations = Delegations({}, {})

role_name: str = role.name if role.name is not None else ""
key, signer = self.create_key()

if role.succinct_hash_info:
# Add target metadata for all bins.
for delegated_name in role.succinct_hash_info.get_all_bin_names():
self.md_delegates[delegated_name] = Metadata(
Targets(expires=self.safe_expiry)
)

self.add_signer(delegated_name, signer)

role_name = role.succinct_hash_info.get_bin_name()

else:
# By default add one new key for the role
self.add_signer(role_name, signer)

# Add metadata for the role
if targets is not None:
if role_name not in self.md_delegates:
self.md_delegates[role_name] = Metadata(targets)

# put delegation last by default
delegator.delegations.roles[role_name] = role

# By default add one new key for the role
key, signer = self.create_key()
delegator.add_key(role_name, key)
self.add_signer(role_name, signer)

# Add metadata for the role
if role_name not in self.md_delegates:
self.md_delegates[role_name] = Metadata(targets, {})

def write(self) -> None:
"""Dump current repository metadata to self.dump_dir
Expand Down

0 comments on commit 4a24ed6

Please sign in to comment.