Skip to content

Commit 10703ac

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

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

Diff for: examples/client/client

+12-3
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,19 @@ 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

3741
if not os.path.isdir(metadata_dir):
3842
os.makedirs(metadata_dir)
3943

4044
data = requests.get(f"{base_url}/metadata/1.root.json").content
41-
updater = Updater(
45+
Updater(
4246
metadata_dir=metadata_dir,
4347
metadata_base_url=f"{base_url}/metadata/",
4448
target_base_url=f"{base_url}/targets/",
@@ -77,6 +81,9 @@ def download(base_url: str, target: str) -> bool:
7781
os.mkdir(DOWNLOAD_DIR)
7882

7983
try:
84+
# NOTE: initial root should be provided with ``bootstrap`` argument:
85+
# This examples uses unsafe Trust-On-First-Use initialization so it is
86+
# not possible here.
8087
updater = Updater(
8188
metadata_dir=metadata_dir,
8289
metadata_base_url=f"{base_url}/metadata/",
@@ -108,7 +115,7 @@ def download(base_url: str, target: str) -> bool:
108115
return True
109116

110117

111-
def main() -> None:
118+
def main() -> str | None:
112119
"""Main TUF Client Example function"""
113120

114121
client_args = argparse.ArgumentParser(description="TUF Client Example")
@@ -173,6 +180,8 @@ def main() -> None:
173180
else:
174181
client_args.print_help()
175182

183+
return None
184+
176185

177186
if __name__ == "__main__":
178187
sys.exit(main())

Diff for: tuf/ngclient/updater.py

+5-4
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
@@ -81,9 +82,9 @@ class Updater:
8182
download both metadata and targets. Default is ``RequestsFetcher``
8283
config: ``Optional``; ``UpdaterConfig`` could be used to setup common
8384
configuration options.
84-
bootstrap: ``Optional``; initial root metadata. If a boostrap root is
85-
not provided then the root.json in the metadata cache is used as the
86-
initial root.
85+
bootstrap: ``Optional``; initial root metadata. A boostrap root should
86+
always be provided. If it is not, the current root.json in the
87+
metadata cache is used as the initial root.
8788
8889
Raises:
8990
OSError: Local root.json cannot be read

0 commit comments

Comments
 (0)