Skip to content
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

repo: Use delegation tree to decide which metadata to include in publishing #344

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions repo/tuf_on_ci/_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,21 +498,32 @@ def build(self, metadata_path: str, artifact_path: str | None):
dst_path = os.path.join(metadata_path, f"{snapshot.version}.snapshot.json")
shutil.copy(os.path.join(self._dir, "snapshot.json"), dst_path)

for filename, metafile in snapshot.meta.items():
# Include all targets/artifacts that are part of the delegation tree
delegated_roles = ["targets"]
while delegated_roles:
rolename = delegated_roles.pop()
filename = f"{rolename}.json"
role = self.targets(rolename)

# copy delegated targets role metadata
src_path = os.path.join(self._dir, filename)
dst_path = os.path.join(metadata_path, f"{metafile.version}.{filename}")
dst_path = os.path.join(metadata_path, f"{role.version}.{filename}")
shutil.copy(src_path, dst_path)

if artifact_path:
targets = self.targets(filename[: -len(".json")])
for target in targets.targets.values():
role, sep, name = target.path.rpartition("/")
os.makedirs(os.path.join(artifact_path, role), exist_ok=True)
src_path = os.path.join(self._dir, "..", "targets", role, name)
# copy artifacts
for target in role.targets.values():
rdir, sep, name = target.path.rpartition("/")
os.makedirs(os.path.join(artifact_path, rdir), exist_ok=True)
src_path = os.path.join(self._dir, "..", "targets", rdir, name)
for hash in target.hashes.values():
dst_path = os.path.join(artifact_path, role, f"{hash}.{name}")
dst_path = os.path.join(artifact_path, rdir, f"{hash}.{name}")
shutil.copy(src_path, dst_path)

# Add delegated roles
if role.delegations and role.delegations.roles:
delegated_roles.extend(role.delegations.roles.keys())

def bump_expiring(self, rolename: str) -> int | None:
"""Create a new version of role if it is about to expire"""
now = datetime.utcnow()
Expand Down