Last active
April 20, 2021 20:33
-
-
Save skuenzli/07b46d063d7515c468e4f2a0a15c01a5 to your computer and use it in GitHub Desktop.
Prototype - k9 AWS IAM access summary diff tool
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
#!/opt/local/bin/bash | |
#set -x | |
set -e | |
report_name=$1 | |
acct=$2 | |
date_1=$3 | |
date_2=$4 | |
# find summaries with a command like | |
# find . -path "*/reports/aws/123456789012/*" -name "principal-access-summaries.2021-04-20*.csv" | |
src_file_1=$(find . -path "*/reports/aws/${acct}/*" -name "${report_name}.${date_1}*.csv" | tail -1) | |
src_file_2=$(find . -path "*/reports/aws/${acct}/*" -name "${report_name}.${date_2}*.csv" | tail -1) | |
tmpfile_basename="k9diff" | |
tmpfile_1=$(mktemp -t ${tmpfile_basename}) || exit 1 | |
tmpfile_2=$(mktemp -t ${tmpfile_basename}) || exit 1 | |
compare_fields="2,4" | |
case "${report_name}" in | |
'principal-access-summaries') | |
compare_fields="2,4,6,7,8" | |
;; | |
'resource-access-summaries') | |
compare_fields="2,4,5,6,7" | |
;; | |
*) | |
echo "unhandled report type ${report_type}" | |
exit 1 | |
;; | |
esac | |
cut -d ',' -f "${compare_fields}" "${src_file_1}" > "${tmpfile_1}" | |
cut -d ',' -f "${compare_fields}" "${src_file_2}" > "${tmpfile_2}" | |
diff --unified=0 "${tmpfile_1}" "${tmpfile_2}" | egrep -v -e '^^@@' -e '^--- ' -e '^\+\+\+ ' | |
rm -f "${tmpfile_1}" "${tmpfile_2}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment