Skip to content

Commit 69cb140

Browse files
committed
examples: Add README for repository example
Tweak comments as well Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 87c74a8 commit 69cb140

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

examples/repository/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# TUF Repository Application Example
2+
3+
4+
This TUF Repository Application Example has following features:
5+
- Initializes a completely new repository on startup
6+
- Stores everything (metadata, targets, signing keys) in-memory
7+
- Serves metadata and targets on localhost (default port 8001)
8+
- Simulates a live repository by automatically adding a new target
9+
file every 10 seconds.
10+
11+
12+
### Example with the repository example
13+
14+
```console
15+
./repo
16+
```
17+
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`.

examples/repository/repo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"""Simple repository example application
66
77
The application stores metadata and targets in memory, and serves them via http.
8-
* Keys are generated at startup
9-
* The application simulates a live reposittory by adding a new target every few seconds
8+
Nothing is persisted on disk or loaded from disk. The application simulates a
9+
live repository by adding new target files periodically.
1010
"""
1111

1212
import argparse
@@ -28,7 +28,7 @@ class ReqHandler(BaseHTTPRequestHandler):
2828
if self.path.startswith("/metadata/") and self.path.endswith(".json"):
2929
self.get_metadata(self.path[len("/metadata/"):-len(".json")])
3030
elif self.path.startswith("/targets/"):
31-
self.get_target(self.path[len("/targets/"):])
31+
self.get_target(self.path[len("/targets/"):])
3232
else:
3333
self.send_error(404, "Only serving /metadata/*.json")
3434

@@ -46,7 +46,7 @@ class ReqHandler(BaseHTTPRequestHandler):
4646
self.send_error(404, f"Role {role} version {ver} not found")
4747
return
4848

49-
# send the metadata json
49+
# send the metadata json
5050
data = repo.role_cache[role][ver-1].to_bytes()
5151
self.send_response(200)
5252
self.send_header('Content-length', len(data))
@@ -80,7 +80,7 @@ class RepositoryServer(HTTPServer):
8080

8181
def main(argv: List[str]) -> None:
8282
"""Example repository server"""
83-
83+
8484
parser = argparse.ArgumentParser()
8585
parser.add_argument("-v", "--verbose", action="count")
8686
parser.add_argument("-p", "--port", type=int, default=8001)
@@ -92,7 +92,7 @@ def main(argv: List[str]) -> None:
9292
server = RepositoryServer(args.port)
9393
last_change = 0
9494
counter = 0
95-
95+
9696
logger.info(f"Now serving. Root v1 at http://127.0.0.1:{server.server_port}/metadata/1.root.json")
9797

9898
while True:

0 commit comments

Comments
 (0)