Skip to content
Snippets Groups Projects
Commit a1849ef0 authored by hahn's avatar hahn
Browse files

task 3975 - update api shell script

parent 3098afcb
No related branches found
No related tags found
1 merge request!1Task 3975 add gitlab ci yaml
......@@ -4,7 +4,8 @@
# API CLIENT :: API REQUEST TO IML CI SERVER
#
# ----------------------------------------------------------------------
# 2020-07-23 first lines <axel.hahn@iml.unibe.ch>
# 2020-07-23 v1.0 <axel.hahn@iml.unibe.ch> first lines
# 2020-07-29 v1.1 <axel.hahn@iml.unibe.ch> check "/" in branch; check http status 200
# ======================================================================
# ----------------------------------------------------------------------
......@@ -54,6 +55,8 @@ function makeRequest(){
local apiRequest=$2
local secret=$3
local outfile=$( mktemp )
echo $line
echo $apiMethod ${apiHost}${apiRequest}
echo $line
......@@ -81,12 +84,22 @@ ${apiTS}
-H "Date: ${apiTS}" \
-H "Authorization: demo-bash-client:${myHash}" \
-X $apiMethod \
${IMLCI_URL}${apiRequest}
${IMLCI_URL}${apiRequest} | tee -a $outfile
else
curl -i \
-H "Accept: application/json" -H "Content-Type: application/json" \
-X $apiMethod \
${IMLCI_URL}${apiRequest}
${IMLCI_URL}${apiRequest} | tee -a $outfile
fi
grep "^HTTP\/" $outfile | head -1 | grep " 200 " >/dev/null
local rccurl=$?
rm -f $outfile
if [ $rccurl -ne 0 ]; then
echo
echo "ERROR: API request failed. CURL request did not get respond status code 200."
exit 4
fi
}
......@@ -123,7 +136,7 @@ case ${option} in
;;
*)
echo ERROR: invalid option [${option}]
exit 1
exit 2
esac
done
......@@ -133,6 +146,9 @@ echo "IMLCI_PROJECT = $IMLCI_PROJECT"
echo "IMLCI_API_SECRET = $IMLCI_API_SECRET"
echo
echo $branch | grep '/.*/.*' >/dev/null && ( echo "WARNING: Do NOT use a branch containing a slash [/] in the name"; echo )
echo ACTION: $apiAction
case $apiAction in
......@@ -153,7 +169,7 @@ case $apiAction in
;;
*)
echo "ERROR: unknown action [$apiAction]"
exit 2
exit 3
esac
rc=$?
......@@ -162,4 +178,4 @@ echo $line
date
echo rc=$rc
exit $rc
\ No newline at end of file
exit $rc
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment