Skip to content

Commit

Permalink
[REFACT] Make A5 initialization message check if app has started
Browse files Browse the repository at this point in the history
  • Loading branch information
Krlier committed Feb 9, 2019
1 parent da7cf38 commit ccea94e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
7 changes: 3 additions & 4 deletions owasp-top10-2017-apps/a5/ecommerce-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ generate-passwords:
chmod +x app/scripts/generate-passwords.sh
./app/scripts/generate-passwords.sh

## Prints initialization message after compose phase
msg:
printf "${COLOR_YELLOW}SecDevLabs: 👀 Your app is still starting...\n${COLOR_RESET}"
sleep ${SLEEPUNTILAPPSTARTS}
printf "${COLOR_GREEN}SecDevLabs: ☕️ Hmmm... Sounds good!\n"
printf "SecDevLabs: 🔥 ${PROJECT} may be running at ${COLOR_RESET}${COLOR_RED}http://localhost:${PORT}${COLOR_RESET}\n"
chmod +x deployments/check-init.sh
./deployments/check-init.sh


## Prints help message
Expand Down
36 changes: 36 additions & 0 deletions owasp-top10-2017-apps/a5/ecommerce-api/deployments/check-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
#
# This script prints initialization messages after the compose phase.
#

COLOR_RESET='\033[0m'
COLOR_YELLOW='\033[33m'
COLOR_GREEN='\033[32m'
COLOR_BLUE='\033[1;34m'

PROJECT='A5 Vulnerable Ecommerce API'
PORT=8888
TRIES=20

printf "${COLOR_YELLOW}SecDevLabs: 👀 Your app is starting!\n${COLOR_RESET}"
while : ;do
`curl -s -f http://localhost:$PORT > /dev/null`
if [ $? == 0 ]; then
break
fi
if [ $TRIES == 20 ]; then
printf "${COLOR_GREEN}SecDevLabs: ☕️ Hmmm... Sounds good!${COLOR_RESET}\n"
fi
if [ $TRIES == 0 ]; then
break
fi
sleep 5
TRIES=$TRIES-1
printf "${COLOR_YELLOW}SecDevLabs: 👀 Your app is still starting...\n${COLOR_RESET}"
done

if [ $TRIES == 0 ]; then
printf "${COLOR_BLUE}SecDevLabs: Ooops! Something went wrong, please check api details for more information!"
else
printf "${COLOR_GREEN}SecDevLabs: 🔥 ${PROJECT} is now running at ${COLOR_RESET}${COLOR_BLUE}http://localhost:$PORT${COLOR_RESET}\n"
fi

0 comments on commit ccea94e

Please sign in to comment.