Skip to content

Commit

Permalink
enhance documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ghubertpalo committed Jan 17, 2024
1 parent 79c5c09 commit ae68278
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
19 changes: 17 additions & 2 deletions mithril-aggregator-fake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,32 @@ For each file, the identifiers of the corresponding artifacts are extracted and

If a file is missing or incomplete, the software will stop with an error message.

This project comes with a shell script that reads data from a given Mithril Aggregator URL and creates the data files in a directory:

```
./scripts/import.sh some/data/directory http://valid.mithril.url/aggregator
```

## Command line synopsis

Usage: `mithril-fake-aggregator [OPTIONS]`
Usage: `mithril-aggregator-fake [OPTIONS]`

Options:

```
-d, --data-directory <DATA_DIRECTORY> Directory where the response files are located
-v, --verbose... Verbose mode (-q, -v, -vv, -vvv, etc)
-v, --verbose... Verbose mode (-v, -vv, -vvv, etc)
-q, --quiet Quiet mode. Suppress all outputs.
-p, --tcp-port <TCP_PORT> TCP port to listen on [default: 80]
-i, --ip-address <IP_ADDRESS> IP Address to bind server to [default: 127.0.0.1]
-h, --help Print help
-V, --version Print version
```

## Examples

Launching the fake Aggregator on `127.0.0.1:80` (requires root privileges) using builtin data with the ERROR verbose level:
`./mithril-aggregator-fake`

Launching the fake Aggregator on `127.0.0.1:8000` reading data from `some/data/directory` subdirectory with the INFO verbose level:
`./mithril-aggregator-fake -p 8000 -d some/data/directory -vv`
31 changes: 26 additions & 5 deletions mithril-aggregator-fake/scripts/import.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
#!/usr/bin/env bash
set +a -eu -o pipefail
#set -v
#set -vx

check_requirements() {
which wget >/dev/null ||
error "It seems 'wget' is not installed or not in the path.";
}

display_help() {
if [ -n "${1-""}" ]; then echo "ERROR: ${1}"; echo; fi
echo "HELP"
echo $0
echo
echo "Import and save data from a given Mithril Aggregator."
echo
echo "Usage: $0 DATA_DIRECTORY URL"
echo
exit 1;
}

error() {
echo $1;
echo "ERROR: $1";
exit 1;
}

Expand Down Expand Up @@ -63,14 +80,18 @@ download_certificate_chain() {

# MAIN execution

declare -r DATA_DIR=${1:?"No data directory given to download JSON files."};
declare -r BASE_URL=${2:?"No Mithril Aggregator URL given."};
if [ -z "${1-""}" ]; then display_help "No data directory given to download JSON files."; fi;
if [ -z "${2-""}" ]; then display_help "No Mithril Aggregator URL given."; fi;

declare -r DATA_DIR=$1;
declare -r BASE_URL=$2;

if [ ! -d "$DATA_DIR" ]; then error "Specified directory '${DATA_DIR}' is not a directory."; fi
wget --quiet --server-response --spider $BASE_URL || error "Could not reach URL '${BASE_URL}'.";
wget --quiet --server-response --spider $BASE_URL 2>/dev/null || error "Could not reach URL '${BASE_URL}'.";

export DATA_DIR URL;

check_requirements;
clean_directory;

download_list "$BASE_URL/certificates" "certificates"
Expand Down

0 comments on commit ae68278

Please sign in to comment.