-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New pre commit hook #3
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just cosmetic stuff and standardisation needed for now - fixing this and adding comments will help.
.githooks/pre-commit
Outdated
#!/bin/bash | ||
#set -x | ||
PREFIX="pre-commit:" | ||
RESULTS_FILE=tfsec-scan-output.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote your variables please.
Also, it would help if there were some useful comments - reading comments aids understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
.githooks/pre-commit
Outdated
initialise() { | ||
mkdir -p $TFSEC_WORKING_DIR | ||
mkdir -p $TFSEC_RESULTS_DIR | ||
rm $TFSEC_WORKING_DIR/* 2> /dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove stray space.
Why are you redirecting STDERR to /dev/null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. Redirecting as it gives an error if this is run for the first time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Righto, maybe you could:
- see if the directory exists
- if yes, delete it & recreate it
- if no, create it
.githooks/pre-commit
Outdated
#set -x | ||
PREFIX="pre-commit:" | ||
RESULTS_FILE=tfsec-scan-output.txt | ||
TFSEC_RESULTS_DIR=/tmp/tfsec-results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
.githooks/pre-commit
Outdated
PREFIX="pre-commit:" | ||
RESULTS_FILE=tfsec-scan-output.txt | ||
TFSEC_RESULTS_DIR=/tmp/tfsec-results | ||
TFSEC_WORKING_DIR=/tmp/tfsec-files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
.githooks/pre-commit
Outdated
mkdir -p $TFSEC_WORKING_DIR | ||
mkdir -p $TFSEC_RESULTS_DIR | ||
rm $TFSEC_WORKING_DIR/* 2> /dev/null | ||
rm $TFSEC_RESULTS_DIR/* 2> /dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
.githooks/pre-commit
Outdated
initialise; | ||
populateGlobalVars; | ||
|
||
if [ "$TERRAFORM_FILES_STAGED" = "yes" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you using [ ] or [[ ]]..?
I think [[ ]] is safer, but I can't remember why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[[ now
.githooks/pre-commit
Outdated
copyTerraformFilesToBeScanned; | ||
|
||
#Do the latest tfsec scan on the files that have been staged | ||
if ! tfsec $TFSEC_WORKING_DIR --no-colour --out $TFSEC_RESULTS_DIR/$RESULTS_FILE; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quoting and cuddling, blah, blah.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
.githooks/pre-commit
Outdated
if [ "$ALLOW_TFSEC_ISSUES" = "yes" ] | ||
then | ||
#Check that the file added is exactly the same as the latest tfsec issues. They must be identical in order for the commit to be allowed through | ||
diffResult=$(diff $TFSEC_RESULTS_DIR/$RESULTS_FILE $TFSEC_WORKING_DIR/$RESULTS_FILE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
.githooks/pre-commit
Outdated
diffResult=$(diff $TFSEC_RESULTS_DIR/$RESULTS_FILE $TFSEC_WORKING_DIR/$RESULTS_FILE) | ||
if [ $? -eq 0 ] | ||
then | ||
informUserThatWeAllowCommitThroughDespiteTfsecIssues; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of Camel case function names.
Also, could they be shorter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
.githooks/pre-commit
Outdated
exit 1 | ||
fi | ||
else | ||
informUserThatWeDenyCommitBecauseOutstandingTfSecIssues; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
No description provided.