Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions devel/scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
headers.txt
47 changes: 47 additions & 0 deletions devel/scripts/README.md
Original file line number Diff line number Diff line change
@@ -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).
13 changes: 13 additions & 0 deletions devel/scripts/examples/sles-missing-pattern.patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"update": {
"product": {
"id": "SLES"
},
"software": {
"patterns": [
"gnome",
"unknown"
]
}
}
}
12 changes: 12 additions & 0 deletions devel/scripts/examples/sles.patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"update": {
"product": {
"id": "SLES"
},
"software": {
"patterns": [
"gnome"
]
}
}
}
13 changes: 13 additions & 0 deletions devel/scripts/examples/slowroll.patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"update": {
"product": {
"id": "Slowroll"
},
"software": {
"patterns": [
"gnome",
"kde"
]
}
}
}
13 changes: 13 additions & 0 deletions devel/scripts/examples/tumbleweed.patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"update": {
"product": {
"id": "Tumbleweed"
},
"software": {
"patterns": [
"gnome",
"kde"
]
}
}
}
5 changes: 5 additions & 0 deletions devel/scripts/get-config.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions devel/scripts/get-extended-config.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions devel/scripts/get-issues.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions devel/scripts/get-status.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions devel/scripts/get-system.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions devel/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -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"'
19 changes: 19 additions & 0 deletions devel/scripts/login.sh
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 16 additions & 0 deletions devel/scripts/monitor-curl.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions devel/scripts/monitor-websocat.sh
Original file line number Diff line number Diff line change
@@ -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"

14 changes: 14 additions & 0 deletions devel/scripts/set-config.sh
Original file line number Diff line number Diff line change
@@ -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