diff --git a/devel/scripts/.gitignore b/devel/scripts/.gitignore new file mode 100644 index 0000000000..78f10da8f8 --- /dev/null +++ b/devel/scripts/.gitignore @@ -0,0 +1 @@ +headers.txt diff --git a/devel/scripts/README.md b/devel/scripts/README.md new file mode 100644 index 0000000000..4e0eada994 --- /dev/null +++ b/devel/scripts/README.md @@ -0,0 +1,47 @@ +# Testing scripts + +This directory contains some scripts that you can use to test the API. For them to work, you need to +specify the URL of your Agama server (it might be running, for instance, on a virtual machine): + +``` +export AGAMA_URL=https://192.168.122.10 +``` + +## Logging in + +Before running any other script, you need to log into the API. You can use the `login.sh` script for +that. It will generate a `headers.txt` file that contains the authentication token. By default, it +uses the password `linux`, which is hardcoded into the script. + +``` +$ ./login.sh +Logging in https://192.168.122.10 +Using token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NjU2MzA2MjYsImNsaWVudF9pZCI6IjczNTJmYzFjLWVlNGItNDUzMC05NzY2LTFiMGEyODk3ZDlkZCJ9.fjkk4mab0mTEc-e3IevhKJu2pOkz6Ie0kVQD9GXZ_ZQ + +``` + +## Setting the configuration + +The `set-config.sh` script allows to partially update the configuration. It receives a JSON file +containing the body of the PATCH request. Check `examples/*.patch.json` for some examples. + +``` +$ ./set-config.sh examples/tumbleweed.patch.json +``` + +You can check the user configuration using the `get-config.sh` script. + +## Getting the status + +There are a few scripts to retrieve different aspects of the system (status, system information, +configuration, etc.). Check for `get-*.sh` scripts. + +## Listening to events + +You can listen to Agama events using the `monitor-*.sh` scripts: + +- `monitor-websocat.sh`: it relies on [websocat](https://github.com/vi/websocat). Unfortunately, the + program is not available in the official openSUSE repositories, so you might need to use + `cargo install` (or `cargo binstall`). +- `monitor-curl.sh`: it uses `curl` under the hood. The output is less convenient, but you do not + need an extra tool (TODO: improve the `curl` invocation). diff --git a/devel/scripts/examples/sles-missing-pattern.patch.json b/devel/scripts/examples/sles-missing-pattern.patch.json new file mode 100644 index 0000000000..f5773781df --- /dev/null +++ b/devel/scripts/examples/sles-missing-pattern.patch.json @@ -0,0 +1,13 @@ +{ + "update": { + "product": { + "id": "SLES" + }, + "software": { + "patterns": [ + "gnome", + "unknown" + ] + } + } +} diff --git a/devel/scripts/examples/sles.patch.json b/devel/scripts/examples/sles.patch.json new file mode 100644 index 0000000000..625f39f7ec --- /dev/null +++ b/devel/scripts/examples/sles.patch.json @@ -0,0 +1,12 @@ +{ + "update": { + "product": { + "id": "SLES" + }, + "software": { + "patterns": [ + "gnome" + ] + } + } +} diff --git a/devel/scripts/examples/slowroll.patch.json b/devel/scripts/examples/slowroll.patch.json new file mode 100644 index 0000000000..9d8842425d --- /dev/null +++ b/devel/scripts/examples/slowroll.patch.json @@ -0,0 +1,13 @@ +{ + "update": { + "product": { + "id": "Slowroll" + }, + "software": { + "patterns": [ + "gnome", + "kde" + ] + } + } +} diff --git a/devel/scripts/examples/tumbleweed.patch.json b/devel/scripts/examples/tumbleweed.patch.json new file mode 100644 index 0000000000..7c1e15e8bd --- /dev/null +++ b/devel/scripts/examples/tumbleweed.patch.json @@ -0,0 +1,13 @@ +{ + "update": { + "product": { + "id": "Tumbleweed" + }, + "software": { + "patterns": [ + "gnome", + "kde" + ] + } + } +} diff --git a/devel/scripts/get-config.sh b/devel/scripts/get-config.sh new file mode 100644 index 0000000000..c3c63b9f45 --- /dev/null +++ b/devel/scripts/get-config.sh @@ -0,0 +1,5 @@ +#!/usr/bin/bash + +# Return the users' configuration. + +curl -k --silent -H @headers.txt -X GET $AGAMA_URL/api/v2/config | jq diff --git a/devel/scripts/get-extended-config.sh b/devel/scripts/get-extended-config.sh new file mode 100644 index 0000000000..419dda0174 --- /dev/null +++ b/devel/scripts/get-extended-config.sh @@ -0,0 +1,5 @@ +#!/usr/bin/bash + +# Return the full (extended) configuration. + +curl -k --silent -H @headers.txt -X GET $AGAMA_URL/api/v2/extended_config | jq diff --git a/devel/scripts/get-issues.sh b/devel/scripts/get-issues.sh new file mode 100755 index 0000000000..9487948a34 --- /dev/null +++ b/devel/scripts/get-issues.sh @@ -0,0 +1,5 @@ +#!/usr/bin/bash + +# Retrieves the list of issues. + +curl -k --silent -H @headers.txt -X GET $AGAMA_URL/api/v2/issues | jq diff --git a/devel/scripts/get-status.sh b/devel/scripts/get-status.sh new file mode 100755 index 0000000000..09798e4601 --- /dev/null +++ b/devel/scripts/get-status.sh @@ -0,0 +1,5 @@ +#!/usr/bin/bash + +# Retrieves the installer status (stage and progress). + +curl -k --silent -H @headers.txt -X GET $AGAMA_URL/api/v2/status | jq diff --git a/devel/scripts/get-system.sh b/devel/scripts/get-system.sh new file mode 100755 index 0000000000..916a19be20 --- /dev/null +++ b/devel/scripts/get-system.sh @@ -0,0 +1,5 @@ +#!/usr/bin/bash + +# Retrieves the system information. + +curl -k --silent -H @headers.txt -X GET $AGAMA_URL/api/v2/system | jq diff --git a/devel/scripts/install.sh b/devel/scripts/install.sh new file mode 100755 index 0000000000..1516bb05bd --- /dev/null +++ b/devel/scripts/install.sh @@ -0,0 +1,5 @@ +#!/usr/bin/bash + +# Starts the installation process. + +curl -k --silent -H @headers.txt -X POST $AGAMA_URL/api/v2/action -d '"install"' diff --git a/devel/scripts/login.sh b/devel/scripts/login.sh new file mode 100755 index 0000000000..91d9ecc3c0 --- /dev/null +++ b/devel/scripts/login.sh @@ -0,0 +1,19 @@ +#!/usr/bin/sh + +# Log into an Agama server, writing the headers for subsequent requests in +# the headers.txt file. + +echo "Logging in $AGAMA_URL" +TOKEN=$(curl -k --silent "$AGAMA_URL/api/auth" -d '{"password": "linux"}' \ + -H "Content-Type: application/json" | jq .token | tr -d '"') + +if [ -z "$TOKEN" ] +then + echo "Failed to authenticate" + exit 1 +fi + +echo "Content-Type: application/json" >headers.txt +printf "Authorization: Bearer " >>headers.txt +echo "$TOKEN" >>headers.txt +echo Using token "$TOKEN" diff --git a/devel/scripts/monitor-curl.sh b/devel/scripts/monitor-curl.sh new file mode 100644 index 0000000000..d559556c8b --- /dev/null +++ b/devel/scripts/monitor-curl.sh @@ -0,0 +1,16 @@ +#!/usr/bin/bash + +# Connect to Agama's WebSocket using curl. +# +curl \ + --insecure \ + --http1.1 \ + --include \ + --no-buffer \ + --header @headers.txt \ + --header "Connection: Upgrade" \ + --header "Upgrade: websocket" \ + --header "Sec-WebSocket-Key: testing" \ + --header "Sec-WebSocket-Version: 13" \ + --output - \ + $AGAMA_URL/api/ws diff --git a/devel/scripts/monitor-websocat.sh b/devel/scripts/monitor-websocat.sh new file mode 100755 index 0000000000..ca67434ec0 --- /dev/null +++ b/devel/scripts/monitor-websocat.sh @@ -0,0 +1,8 @@ +#!/usr/bin/bash + +# Connect to Agama's WebSocket using websocat. + +TOKEN=`awk '/Authorization/{print $3}' headers.txt` +URL=$(echo $AGAMA_URL | sed -e 's/https/wss/') +websocat $URL/api/ws -k -H "Authorization: Bearer $TOKEN" + diff --git a/devel/scripts/set-config.sh b/devel/scripts/set-config.sh new file mode 100755 index 0000000000..f2bc9d19cc --- /dev/null +++ b/devel/scripts/set-config.sh @@ -0,0 +1,14 @@ +#!/usr/bin/bash + +# Partially update the configuration. You need to pass a file containing +# the payload of the PATCH request. Check the examples/ directory for some +# inspiration. + +if [ -z "$1" ] +then + echo "You need to specify a file to load the configuration from" + exit 1 + +fi + +curl -k -H @headers.txt -X PATCH $AGAMA_URL/api/v2/config -d @$1