diff --git a/examples/client/client b/examples/client/client index ed8e266b65..9c509816e5 100755 --- a/examples/client/client +++ b/examples/client/client @@ -14,12 +14,13 @@ from pathlib import Path from urllib import request from tuf.api.exceptions import DownloadError, RepositoryError -from tuf.ngclient import Updater +from tuf.ngclient import Updater, UpdaterConfig # constants DOWNLOAD_DIR = "./downloads" CLIENT_EXAMPLE_DIR = os.path.dirname(os.path.abspath(__file__)) + def build_metadata_dir(base_url: str) -> str: """build a unique and reproducible directory name for the repository url""" name = sha256(base_url.encode()).hexdigest()[:8] @@ -46,7 +47,7 @@ def init_tofu(base_url: str) -> bool: return True -def download(base_url: str, target: str) -> bool: +def download(base_url: str, target: str, use_dsse: bool) -> bool: """ Download the target file using ``ngclient`` Updater. @@ -72,12 +73,16 @@ def download(base_url: str, target: str) -> bool: if not os.path.isdir(DOWNLOAD_DIR): os.mkdir(DOWNLOAD_DIR) + config = UpdaterConfig() + config.use_dsse = use_dsse + try: updater = Updater( metadata_dir=metadata_dir, metadata_base_url=f"{base_url}/metadata/", target_base_url=f"{base_url}/targets/", target_dir=DOWNLOAD_DIR, + config=config, ) updater.refresh() @@ -146,6 +151,13 @@ def main() -> None: help="Target file", ) + download_parser.add_argument( + "--use-dsse", + help="Parse TUF metadata as DSSE", + default=False, + action="store_true", + ) + command_args = client_args.parse_args() if command_args.verbose == 0: @@ -164,7 +176,9 @@ def main() -> None: if not init_tofu(command_args.url): return "Failed to initialize local repository" elif command_args.sub_command == "download": - if not download(command_args.url, command_args.target): + if not download( + command_args.url, command_args.target, command_args.use_dsse + ): return f"Failed to download {command_args.target}" else: client_args.print_help()