Skip to content

Commit 38e4eab

Browse files
committed
updater: Improve comments on bootstrap arg
This includes some minor example improvements Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent c4cd793 commit 38e4eab

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

examples/client/client

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ def build_metadata_dir(base_url: str) -> str:
3030

3131
def init_tofu(base_url: str) -> bool:
3232
"""Initialize local trusted metadata (Trust-On-First-Use) and create a
33-
directory for downloads"""
33+
directory for downloads
34+
35+
NOTE: This is unsafe and for demonstration only: the bootstrap root
36+
should be deployed alongside your updater application
37+
"""
3438

3539
metadata_dir = build_metadata_dir(base_url)
3640

@@ -81,6 +85,9 @@ def download(base_url: str, target: str) -> bool:
8185
os.mkdir(DOWNLOAD_DIR)
8286

8387
try:
88+
# NOTE: initial root should be provided with ``bootstrap`` argument:
89+
# This examples uses unsafe Trust-On-First-Use initialization so it is
90+
# not possible here.
8491
updater = Updater(
8592
metadata_dir=metadata_dir,
8693
metadata_base_url=f"{base_url}/metadata/",
@@ -112,7 +119,7 @@ def download(base_url: str, target: str) -> bool:
112119
return True
113120

114121

115-
def main() -> None:
122+
def main() -> str | None:
116123
"""Main TUF Client Example function"""
117124

118125
client_args = argparse.ArgumentParser(description="TUF Client Example")
@@ -177,6 +184,8 @@ def main() -> None:
177184
else:
178185
client_args.print_help()
179186

187+
return None
188+
180189

181190
if __name__ == "__main__":
182191
sys.exit(main())

tuf/ngclient/updater.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
High-level description of ``Updater`` functionality:
1313
* Initializing an ``Updater`` loads and validates the trusted local root
1414
metadata: This root metadata is used as the source of trust for all other
15-
metadata.
15+
metadata. Updater should always be initialized with the ``bootstrap``
16+
argument: if this is not possible, it can be initialized from cache only.
1617
* ``refresh()`` can optionally be called to update and load all top-level
1718
metadata as described in the specification, using both locally cached
1819
metadata and metadata downloaded from the remote repository. If refresh is
@@ -75,9 +76,9 @@ class Updater:
7576
download both metadata and targets. Default is ``Urllib3Fetcher``
7677
config: ``Optional``; ``UpdaterConfig`` could be used to setup common
7778
configuration options.
78-
bootstrap: ``Optional``; initial root metadata. If a boostrap root is
79-
not provided then the root.json in the metadata cache is used as the
80-
initial root.
79+
bootstrap: ``Optional``; initial root metadata. A boostrap root should
80+
always be provided. If it is not, the current root.json in the
81+
metadata cache is used as the initial root.
8182
8283
Raises:
8384
OSError: Local root.json cannot be read

0 commit comments

Comments
 (0)