aboutsummaryrefslogtreecommitdiffstats
path: root/jjb/common/include-agl-lava-labs-prepare.sh
blob: e36fa662ff28645eca2e3175a1949a1d6bdae43e (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# (c) 2017 Kevin Hilman <khilman@baylibre.com>
# License GPLv2

#
# Setup LAVA API authentication tokens for various LAVA labs
#
# Uses user/token pairs from Jenkins secrets
#
declare -A labs
labs=(
    [agl]="https://lava.automotivelinux.org/;$LAB_AGL_USER;$LAB_AGL_TOKEN"
    [baylibre]="http://lava.baylibre.com:10080/;$LAB_BAYLIBRE_USER;$LAB_BAYLIBRE_TOKEN"
#    [baylibre_seattle]="http://lava.ished.com/;$LAB_BAYLIBRE_SEATTLE_USER;$LAB_BAYLIBRE_SEATTLE_TOKEN"
    )

#
# Ensure python_keyring is set to plaintext.  Required for
# non-interactive use
#
echo "default keyring config"
mkdir -p ~/.local/share/python_keyring/
cat <<EOF >  ~/.local/share/python_keyring/keyringrc.cfg
[backend]
default-keyring=keyring.backends.file.PlaintextKeyring
EOF

for lab in "${!labs[@]}"; do
    val=${labs[$lab]}
    OFS=${IFS}
    IFS=';'
    arr=(${labs[$lab]})
    IFS=${OFS}

    url=${arr[0]}
    user=${arr[1]}
    token=${arr[2]}
    token_file=$HOME/.local/lab-$lab-token

    if [ -z ${user} ]; then
	echo "WARNING: Lab ${lab}: missing user. Ignoring."
	continue
    fi
    if [ -z ${token} ]; then
	echo "WARNING: Lab ${lab}: missing token. Ignoring."
	continue
    fi

    # LAVA URL with username
    full_url=${url/:\/\//:\/\/${user}\@}
    echo "LAVA auth-add for lab: $lab, URL: $full_url"
    
    # LAVA auth using token
    echo ${token} > $token_file
    lava-tool auth-add --token $token_file $full_url
    if [ $? != 0 ]; then
	echo "ERROR: Lab ${lab}: lava-tool auth-add failed."
    fi
    rm -f $token_file
done