Skip to content

Commit 48865ae

Browse files
committed
repository: Remove sign_only argument from close()
This is only needed for threshold signing and not even used in the example: leave it to the implementations to handle for now. Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 9e9c156 commit 48865ae

2 files changed

Lines changed: 19 additions & 27 deletions

File tree

examples/repository/_simplerepo.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,21 @@ def open(self, role: str) -> Metadata:
100100
# return latest metadata from storage (but don't return a reference)
101101
return copy.deepcopy(self.role_cache[role][-1])
102102

103-
def close(self, role: str, md: Metadata, sign_only: bool = False) -> None:
103+
def close(self, role: str, md: Metadata) -> None:
104104
"""Store a version of metadata. Handle version bumps, expiry, signing"""
105-
if sign_only:
106-
for signer in self.signer_cache[role]:
107-
md.sign(signer, append=True)
108-
self.role_cache[role][-1] = md
109-
else:
110-
md.signed.version += 1
111-
md.signed.expires = datetime.utcnow() + self.expiry_period
112-
113-
md.signatures.clear()
114-
for signer in self.signer_cache[role]:
115-
md.sign(signer, append=True)
116-
117-
# store new metadata version, update version caches
118-
self.role_cache[role].append(md)
119-
if role == "snapshot":
120-
self._snapshot_info.version = md.signed.version
121-
elif role not in ["root", "timestamp"]:
122-
self._targets_infos[f"{role}.json"].version = md.signed.version
105+
md.signed.version += 1
106+
md.signed.expires = datetime.utcnow() + self.expiry_period
107+
108+
md.signatures.clear()
109+
for signer in self.signer_cache[role]:
110+
md.sign(signer, append=True)
111+
112+
# store new metadata version, update version caches
113+
self.role_cache[role].append(md)
114+
if role == "snapshot":
115+
self._snapshot_info.version = md.signed.version
116+
elif role not in ["root", "timestamp"]:
117+
self._targets_infos[f"{role}.json"].version = md.signed.version
123118

124119
def add_target(self, path: str, content: str) -> None:
125120
"""Add a target to repository"""

tuf/repository/_repository.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ class Repository(ABC):
2828
application, whether it is a real repository server or a developer tool.
2929
3030
Implementations must implement open() and close(), and can then use the
31-
edit() contextmanager to implement actual operations.
31+
edit() contextmanager to implement actual operations. Not that signing
32+
an already existing version of metadata (as could be done for threshold
33+
signing) does not fit into this model of open()+close() or edit().
3234
33-
A few operations (sign, snapshot and timestamp) are already implemented
35+
A few operations (snapshot and timestamp) are already implemented
3436
in this base class.
3537
"""
3638

@@ -42,7 +44,7 @@ def open(self, role: str) -> Metadata:
4244
raise NotImplementedError
4345

4446
@abstractmethod
45-
def close(self, role: str, md: Metadata, sign_only: bool = False) -> None:
47+
def close(self, role: str, md: Metadata) -> None:
4648
"""Write roles metadata into storage
4749
4850
If sign_only, then just append signatures of all available keys.
@@ -92,11 +94,6 @@ def edit(self, role: str) -> Generator[Signed, None, None]:
9294
yield md.signed
9395
self.close(role, md)
9496

95-
def sign(self, role: str) -> None:
96-
"""sign without modifying content, or removing existing signatures"""
97-
md = self.open(role)
98-
self.close(role, md, sign_only=True)
99-
10097
def snapshot(self, force: bool = False) -> Tuple[bool, Dict[str, MetaFile]]:
10198
"""Update snapshot meta information
10299

0 commit comments

Comments
 (0)