Last active
November 14, 2019 17:04
-
-
Save uchilaka/2c93b193465f42ade7dd405ee72a1639 to your computer and use it in GitHub Desktop.
Brakeman Report Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
## Run Brakeman Report | |
# | |
# IMPORTANT!!! | |
# 1. Make sure you have `realpath` from the coreutils package installed (via brew). To | |
# check this, run `which realpath`. To install, run `brew install coreutils` | |
# | |
# 2. Make sure you have the brakeman gem installed on your machine. If not, | |
# run `gem install brakeman` from your machine $HOME to do so. | |
# | |
# 3. `cd` to the root directory of your project and run this script to generate | |
# a timestamped brakeman report at `<project_root>/.brakeman/<timestamp>.txt` | |
# | |
# | |
if [ -z "$(which realpath)" ]; then | |
cat <<EOF | |
Looks like you don't have realpath. Womp womp :( | |
EOF | |
exit 1 | |
fi | |
# Definitions | |
SCRIPT_PATH=$(realpath $(dirname ${BASH_SOURCE[0]})) | |
APP_PATH=$(dirname $SCRIPT_PATH) | |
BRAKEMAN_PATH="$APP_PATH/.brakeman" | |
BRAKEMAN_REPORT="$BRAKEMAN_PATH/$(date +%Y%m%d__%H%M%S)" | |
# cat <<EOF | |
# Script path: ${SCRIPT_PATH} | |
# App path: ${APP_PATH} | |
# EOF | |
# create .brakeman directory if it's not found | |
! [[ -d "$BRAKEMAN_PATH" ]] && mkdir -pv "$BRAKEMAN_PATH" | |
if [ -z "$(which brakeman)" ]; then | |
echo <<EOF | |
You need to install the brakeman gem on your machine. You can do so by | |
running: | |
\`gem install brakeman\` | |
EOF | |
exit 1 | |
fi | |
# Make sure we have the right directory structure | |
if ! [ -f "$APP_PATH/Gemfile" ]; then | |
echo <<EOF | |
You need to make sure this script is placed in the `<root>/scripts` directory | |
of your project... OR, you can modify the definitions above if you'd | |
REALLY rather put it elsewhere :) | |
EOF | |
exit 1 | |
fi | |
# Run a brakeman text formatted report. For more options, run brakeman --help | |
cd $APP_PATH && brakeman > "$BRAKEMAN_REPORT.txt" --format text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment