Skip to content

Commit fdf0aff

Browse files
committed
repository: Address review comments
This is a collection of comment, documentation and logging fixes. The noteworthy part is making it clear that repository is not stable API yet: I think this is a good idea. Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 0f94c03 commit fdf0aff

5 files changed

Lines changed: 27 additions & 21 deletions

File tree

examples/client_example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ In another terminal, run the client:
3232

3333
Note that unlike normal repositories, the example repository only exists in
3434
memory and is re-generated from scratch at every startup: This means your
35-
client needs to run `tofu` everytime you restart the repository application.
35+
client needs to run `tofu` every time you restart the repository application.
3636

3737

3838
### Example with a repository on the internet

examples/repository/README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
# TUF Repository Application Example
22

3+
:warning: This example uses the repository module which is not considered
4+
part of the python-tuf stable API quite yet.
35

4-
This TUF Repository Application Example has following features:
6+
This TUF Repository Application Example has the following features:
57
- Initializes a completely new repository on startup
68
- Stores everything (metadata, targets, signing keys) in-memory
79
- Serves metadata and targets on localhost (default port 8001)
810
- Simulates a live repository by automatically adding a new target
911
file every 10 seconds.
1012

1113

12-
### Example with the repository example
14+
### Usage
1315

1416
```console
1517
./repo
1618
```
1719
Your repository is now running and is accessible on localhost, See e.g.
18-
http://127.0.0.1:8001/metadata/1.root.json
19-
20-
Note that because the example generates a new repository at startup,
21-
clients need to also re-initialize their trust root when the repository
22-
application is restarted. With the example client this is done with
23-
`./client tofu`.
20+
http://127.0.0.1:8001/metadata/1.root.json. The
21+
[client example](../client_example/README.md) uses this address by default.

examples/repository/_simplerepo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ class SimpleRepository(Repository):
4242
4343
4444
Attributes:
45-
role_cache: Contains every historical metadata version of every role in
46-
this repositorys. Keys are rolenames and values are lists of
47-
Metadata
48-
signer_cache: Contains all signers available to the repository. Keys
49-
are rolenames, values are lists of signers
50-
target_cache:
45+
role_cache: Every historical metadata version of every role in this
46+
repositorys. Keys are role names and values are lists of Metadata
47+
signer_cache: All signers available to the repository. Keys are role
48+
names, values are lists of signers
49+
target_cache: All target files served by the repository. Keys are
50+
target paths and values are file contents as bytes.
5151
"""
5252

5353
expiry_period = timedelta(days=1)

tuf/repository/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Copyright 2021-2022 python-tuf contributors
22
# SPDX-License-Identifier: MIT OR Apache-2.0
33

4-
"""Repository API: A library to help repository implementations"""
4+
"""Repository API: A helper library for repository implementations
5+
6+
This module is intended to make any "metadata editing" applications easier to
7+
implement: this includes repository applications, CI integration components as
8+
well as developer and signing tools.
9+
10+
The repository module is not considered part of the stable python-tuf API yet.
11+
"""
512

613
from tuf.repository._repository import AbortEdit, Repository

tuf/repository/_repository.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class AbortEdit(Exception):
2121
class Repository(ABC):
2222
"""Abstract class for metadata modifying implementations
2323
24+
NOTE: The repository module is not considered part of the python-tuf
25+
stable API yet.
26+
2427
This class is intended to be a base class used in any metadata editing
2528
application, whether it is a real repository server or a developer tool.
2629
@@ -95,15 +98,15 @@ def snapshot(self, force: bool = False) -> Tuple[bool, Dict[str, MetaFile]]:
9598
"""Update snapshot meta information
9699
97100
Updates the snapshot meta information according to current targets
98-
metadata state and the current current snapshot meta information.
101+
metadata state and the current snapshot meta information.
99102
100103
Arguments:
101104
force: should new snapshot version be created even if meta
102105
information would not change?
103106
104107
Returns: Tuple of
105108
- True if snapshot was created, False if not
106-
- Meta information for targets metadata was removed from snapshot
109+
- Meta information for targets metadata that was removed from snapshot
107110
"""
108111

109112
# Snapshot update is needed if
@@ -135,9 +138,7 @@ def snapshot(self, force: bool = False) -> Tuple[bool, Dict[str, MetaFile]]:
135138
# this is reachable as edit() handles AbortEdit
136139
logger.debug("Snapshot update not needed") # type: ignore[unreachable]
137140
else:
138-
logger.debug(
139-
"Snapshot v%d, %d targets", snapshot.version, len(snapshot.meta)
140-
)
141+
logger.debug("Snapshot v%d", snapshot.version)
141142

142143
return update_version, removed
143144

0 commit comments

Comments
 (0)