forked from akbennett/lava-docker
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetAPItoken.sh
More file actions
executable file
·34 lines (26 loc) · 1.38 KB
/
getAPItoken.sh
File metadata and controls
executable file
·34 lines (26 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Create an API token in the database and store it in a file
curdir="$(dirname "$(readlink -f "$0")")"
if [ -f "${curdir}/lava-credentials.txt" ]; then
. "${curdir}"/lava-credentials.txt
fi
lavaurl=http://localhost
tools_path="${tools_path:-/home/lava/bin}"
#obtain the csrf token
data=$(curl -s -c ${tools_path}/cookies.txt $lavaurl/accounts/login/)
#login
csrf="csrfmiddlewaretoken="$(grep csrftoken ${tools_path}/cookies.txt | cut -d$'\t' -f 7)
login=$csrf\&username=$adminuser\&password=$adminpass
curl -b ${tools_path}/cookies.txt -c ${tools_path}/cookies.txt -d $login -X POST $lavaurl/admin/login/
#create an api key
csrf="csrfmiddlewaretoken="$(grep csrftoken ${tools_path}/cookies.txt | cut -d$'\t' -f 7)
createapi=$csrf\&description=autogenerated
curl -b ${tools_path}/cookies.txt -c ${tools_path}/cookies.txt -d $createapi -X POST $lavaurl/api/tokens/create/
#retrieve the api key and store it in a file
curl -b ${tools_path}/cookies.txt http://localhost/admin/linaro_django_xmlrpc/authtoken/1/ | grep id_secret | sed -n 's/.*value="\([^"]*\).*/\1/p' > ${tools_path}/apikey.txt
echo -e "\n\n#####################################\n"
echo -e "# LAVA ADMIN USER = $adminuser"
echo -e "# LAVA ADMIN PASSWD = $adminpass"
echo -n "# LAVA APIKEY =$(cat ${tools_path}/apikey.txt)"
echo -e "\n\n#####################################\n"
cp ${tools_path}/apikey.txt /var/lib/lava/dispatcher/tmp/