@@ -30,15 +30,19 @@ def build_metadata_dir(base_url: str) -> str:
30
30
31
31
def init_tofu (base_url : str ) -> bool :
32
32
"""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
+ """
34
38
35
39
metadata_dir = build_metadata_dir (base_url )
36
40
37
41
if not os .path .isdir (metadata_dir ):
38
42
os .makedirs (metadata_dir )
39
43
40
44
data = requests .get (f"{ base_url } /metadata/1.root.json" ).content
41
- updater = Updater (
45
+ Updater (
42
46
metadata_dir = metadata_dir ,
43
47
metadata_base_url = f"{ base_url } /metadata/" ,
44
48
target_base_url = f"{ base_url } /targets/" ,
@@ -77,6 +81,9 @@ def download(base_url: str, target: str) -> bool:
77
81
os .mkdir (DOWNLOAD_DIR )
78
82
79
83
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.
80
87
updater = Updater (
81
88
metadata_dir = metadata_dir ,
82
89
metadata_base_url = f"{ base_url } /metadata/" ,
@@ -108,7 +115,7 @@ def download(base_url: str, target: str) -> bool:
108
115
return True
109
116
110
117
111
- def main () -> None :
118
+ def main () -> str | None :
112
119
"""Main TUF Client Example function"""
113
120
114
121
client_args = argparse .ArgumentParser (description = "TUF Client Example" )
@@ -173,6 +180,8 @@ def main() -> None:
173
180
else :
174
181
client_args .print_help ()
175
182
183
+ return None
184
+
176
185
177
186
if __name__ == "__main__" :
178
187
sys .exit (main ())
0 commit comments