Skip to content

Commit

Permalink
actions: Add a way to initialize client in test-repository
Browse files Browse the repository at this point in the history
Now the action will find a ./root.json in the working directory
and will pass that to tuf-on-ci-test-client: this file
will be used as the initial root file
  • Loading branch information
jku committed Apr 3, 2024
1 parent 86eff57 commit 16779a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
34 changes: 26 additions & 8 deletions actions/test-repository/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,39 @@ description: 'Test a published TUF-on-CI repository with a client'

inputs:
metadata_url:
description: 'base metadata URL the client should use'
description: |
base metadata URL the client should use. The client will be initialized with
`metadata_url/1.root.json` by default. However if there is a `root.json` file
in the working directory, that will be used instead.
default: ''
artifact_url:
description: 'Base artifact URL the client should use'
description: 'Base artifact URL the client should use.'
default: ''
update_base_url:
description: 'Optional metadata URL to use as previous repository state'
description: 'Optional metadata URL to use as previous repository state.'
default: ''
expected_artifact:
description: 'Optional artifact path that should be checked to exist in the repository'
description: |
Optional artifact path that should be checked to exist in the repository.
default: ''
compare_source:
description: 'When true, client metadata is compared to current repository content. Set to false if action is not running in a tuf-on-ci repository'
description: |
When true, client metadata is compared to current repository content. Set to
false if action is not running in a tuf-on-ci repository.
default: 'true'
valid_days:
description: 'Number of days. The repository is checked to be valid at "now + N days"'
description: |
Number of days. The repository is checked to be valid at "now + N days".
default: '0'
offline_valid_days:
description: 'Number of days. Root and targets role validity is checked to be valid at "now + N days". Can be larger than repository validity'
description: |
Number of days. Root and targets role validity is checked to be valid at
"now + N days". This number can be larger than repository validity.
default: '0'
metadata_dir:
description: 'Optional directory name. The metadata client receives will be stored here. Useful e.g. for deduplication purpose'
description: |
Optional directory name. The metadata client receives will be left here.
Useful e.g. for deduplication purposes.
default: ''

runs:
Expand Down Expand Up @@ -105,11 +116,18 @@ runs:
METADATA_DIR_ARG="--metadata-dir $METADATA_DIR"
fi
if [ -e root.json ]; then
ROOT_ARG="--initial-root root.json"
else
ROOT_ARG=""
fi
echo "Testing repository at metadata-url $METADATA_URL, artifact-url $ARTIFACT_URL"
tuf-on-ci-test-client \
--metadata-url "$METADATA_URL" \
--artifact-url "$ARTIFACT_URL" \
$UPDATE_BASE_URL_ARG \
$ROOT_ARG \
$ARTIFACT_ARG \
$COMPARE_SOURCE_ARG \
$TIME_ARG \
Expand Down
18 changes: 12 additions & 6 deletions repo/tuf_on_ci/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import logging
import os
import shutil
import sys
from datetime import datetime
from filecmp import cmp
Expand All @@ -31,6 +32,7 @@ def expiry_check(dir: str, role: str, timestamp: int):
@click.option("-m", "--metadata-url", type=str, required=True)
@click.option("-a", "--artifact-url", type=str, required=True)
@click.option("-u", "--update-base-url", type=str)
@click.option("-r", "--initial-root", type=str)
@click.option("-e", "--expected-artifact", type=str)
@click.option("--compare-source/--no-compare-source", default=True)
@click.option("-t", "--time", type=int)
Expand All @@ -41,6 +43,7 @@ def client(
metadata_url: str,
artifact_url: str,
update_base_url: str | None,
initial_root: str | None,
expected_artifact: str | None,
compare_source: bool,
time: int | None,
Expand All @@ -58,12 +61,15 @@ def client(
os.makedirs(metadata_dir, exist_ok=True)
os.mkdir(artifact_dir)

# initialize client with a root.json from metadata_url
root_url = f"{metadata_url}/1.root.json"
try:
request.urlretrieve(root_url, f"{metadata_dir}/root.json") # noqa: S310
except OSError as e:
sys.exit(f"Failed to download initial root {root_url}: {e}")
# initialize client with --initial-root or from metadata_url
if initial_root is not None:
shutil.copy(initial_root, os.path.join(metadata_dir, "root.json"))
else:
root_url = f"{metadata_url}/1.root.json"
try:
request.urlretrieve(root_url, f"{metadata_dir}/root.json") # noqa: S310
except OSError as e:
sys.exit(f"Failed to download initial root {root_url}: {e}")

if update_base_url is not None:
# Update client to update_base_url before doing the actual update
Expand Down

0 comments on commit 16779a7

Please sign in to comment.