forked from akbennett/lava-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getAPItoken.sh
executable file
·29 lines (21 loc) · 928 Bytes
/
getAPItoken.sh
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
#!/bin/bash
# Create an API token in the database and store it in a file
adminuser=admin
adminpass=admin
devicename=kvm01
devicetype=kvm
lavaurl=http://localhost
#obtain the csrf token
data=$(curl -s -c cookies.txt $lavaurl/accounts/login/)
#login
csrf="csrfmiddlewaretoken="$(cat cookies.txt | grep csrftoken | cut -d$'\t' -f 7)
login=$csrf\&username=$adminuser\&password=$adminpass
curl -b cookies.txt -c cookies.txt -d $login -X POST $lavaurl/admin/login/
#create an api key
csrf="csrfmiddlewaretoken="$(cat cookies.txt | grep csrftoken | cut -d$'\t' -f 7)
createapi=$csrf\&description=autogenerated
curl -b cookies.txt -c cookies.txt -d $createapi -X POST $lavaurl/api/tokens/create/
#retrieve the api key and store it in a file
curl -b cookies.txt http://localhost/admin/linaro_django_xmlrpc/authtoken/1/change/ | grep id_secret | sed -n 's/.*value="\([^"]*\).*/\1/p' > apikey.txt
echo -n "APIKEY="
cat apikey.txt