Skip to content

Commit cd9d5ef

Browse files
committed
The shell script now checks if the Rosette API key is valid before running the examples.
1 parent 12fdd11 commit cd9d5ef

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

examples/docker/run_python.sh

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#Gets called when the user doesn't provide any args
44
function HELP {
5-
echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]"
5+
echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]"
66
echo " API_KEY - Rosette API key (required)"
77
echo " FILENAME - Python source file (optional)"
88
echo " ALT_URL - Alternate service URL (optional)"
@@ -28,25 +28,32 @@ while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
2828
esac
2929
done
3030

31-
# reference the API
32-
curl "https://api.rosette.com/rest/v1/ping" -H "user_key: $1"
31+
#Checks if Rosette API key is valid
32+
function checkAPI {
33+
match=$(curl "https://api.rosette.com/rest/v1/ping" -H "user_key: ${API_KEY}" | grep -o "forbidden")
34+
if [ ! -z $match ]; then
35+
echo -e "\nInvalid Rosette API Key"
36+
exit 1
37+
fi
38+
}
3339

3440
#Copy the mounted content in /source to current WORKDIR
3541
cp /source/*.* .
3642

3743
#Run the examples
3844
if [ ! -z ${API_KEY} ]; then
39-
if [ ! -z ${FILENAME} ]; then
40-
if [ ! -z ${ALT_URL} ]; then
41-
tox -- ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
42-
else
43-
tox -- ${FILENAME} --key ${API_KEY}
44-
fi
45-
elif [ ! -z ${ALT_URL} ]; then
46-
find -maxdepth 1 -name '*.py' -print -exec tox -- {} --key ${API_KEY} --url ${ALT_URL} \;
45+
checkAPI
46+
if [ ! -z ${FILENAME} ]; then
47+
if [ ! -z ${ALT_URL} ]; then
48+
tox -- ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
4749
else
48-
find -maxdepth 1 -name '*.py' -print -exec tox -- {} --key ${API_KEY} \;
50+
tox -- ${FILENAME} --key ${API_KEY}
51+
fi
52+
elif [ ! -z ${ALT_URL} ]; then
53+
find -maxdepth 1 -name '*.py' -print -exec tox -- {} --key ${API_KEY} --url ${ALT_URL} \;
54+
else
55+
find -maxdepth 1 -name '*.py' -print -exec tox -- {} --key ${API_KEY} \;
4956
fi
5057
else
51-
HELP
52-
fi
58+
HELP
59+
fi

0 commit comments

Comments
 (0)