Skip to content

Commit

Permalink
add APP_INSTALL_DIR to example_app.py, copy trusted root.json directl…
Browse files Browse the repository at this point in the history
…y from repo example
  • Loading branch information
dennisvang committed Apr 15, 2022
1 parent 5ffc256 commit 0316bfa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 76 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# dirs
__pycache__/
examples/client/cache/
examples/client/programs/
examples/repo/keystore/
examples/repo/content/

Expand Down
27 changes: 22 additions & 5 deletions examples/client/example_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,47 @@

logger = logging.getLogger(__name__)

# This example stores all files in the notsotuf/examples/client directory
BASE_DIR = pathlib.Path(__file__).resolve().parent
# To get started, create a local example repository by running the
# repo_workflow_example.py script. Then serve the repo content directory on
# localhost:
#
# python -m http.server -d examples/repo/content

# App info
APP_NAME = 'example_app'
CURRENT_VERSION = '1.0'

# For this example, all files are stored in the notsotuf/examples/client
# directory. On Windows 10, a typical location for the BASE_DIR would be
# %PROGRAMDATA%\MyApp (per-machine), or %LOCALAPPDATA%\MyApp (per-user).
BASE_DIR = pathlib.Path(__file__).resolve().parent

# On Windows 10, typical app installation locations are %PROGRAMFILES%\MyApp
# (per-machine) or %LOCALAPPDATA%\Programs\MyApp (per-user). Also see:
# https://docs.microsoft.com/en-us/windows/win32/msi/installation-context
APP_INSTALL_DIR = BASE_DIR / 'programs' / APP_NAME

# App directories
CACHE_DIR = BASE_DIR / 'cache'
METADATA_DIR = CACHE_DIR / 'metadata'
TARGET_DIR = CACHE_DIR / 'targets'

# Update-server urls
METADATA_BASE_URL = 'http://localhost:8000/metadata/'
TARGET_BASE_URL = 'http://localhost:8000/targets/'


def main():
# The app must ensure dirs exist
for dir_path in [METADATA_DIR, TARGET_DIR]:
for dir_path in [APP_INSTALL_DIR, METADATA_DIR, TARGET_DIR]:
dir_path.mkdir(exist_ok=True, parents=True)

# The app must be shipped with a trusted "root.json" metadata file (
# created using tools.repo), and must ensure this file can found in the
# specified metadata_dir. The root metadata file lists all trusted keys
# and TUF roles.
source_path = BASE_DIR / 'trusted_root.json'
# and TUF roles. In this example we copy the root.json file from the
# repo, but normally it would be included in the app distribution.
source_path = BASE_DIR.parent / 'repo' / 'content' / 'metadata' / 'root.json'
destination_path = METADATA_DIR / 'root.json'
if not destination_path.exists():
shutil.copy(src=source_path, dst=destination_path)
Expand All @@ -39,6 +55,7 @@ def main():
# Create update client
client = Client(
app_name=APP_NAME,
app_install_dir=APP_INSTALL_DIR,
current_version=CURRENT_VERSION,
metadata_dir=METADATA_DIR,
metadata_base_url=METADATA_BASE_URL,
Expand Down
71 changes: 0 additions & 71 deletions examples/client/trusted_root.json

This file was deleted.

0 comments on commit 0316bfa

Please sign in to comment.