Skip to content

Commit

Permalink
Merge pull request #37 from galasa-dev/issue-1884-detect-secrets
Browse files Browse the repository at this point in the history
added .pre-commit-config.yaml file to trigger detect-secrets
  • Loading branch information
KirbyKatcher authored Jun 5, 2024
2 parents d33e311 + 3fde79c commit f1061c0
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/ibm/detect-secrets
rev: 0.13.1+ibm.62.dss
hooks:
- id: detect-secrets # pragma: whitelist secret
args: [--baseline, .secrets.baseline, --use-all-plugins, --fail-on-unaudited]
84 changes: 84 additions & 0 deletions .secrets.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"exclude": {
"files": "galasa-ui/package-lock.json|^.secrets.baseline$",
"lines": null
},
"plugins_used": [
{
"name": "AWSKeyDetector"
},
{
"name": "ArtifactoryDetector"
},
{
"name": "AzureStorageKeyDetector"
},
{
"base64_limit": 4.5,
"name": "Base64HighEntropyString"
},
{
"name": "BasicAuthDetector"
},
{
"name": "BoxDetector"
},
{
"name": "CloudantDetector"
},
{
"ghe_instance": "github.ibm.com",
"name": "GheDetector"
},
{
"name": "GitHubTokenDetector"
},
{
"hex_limit": 3,
"name": "HexHighEntropyString"
},
{
"name": "IbmCloudIamDetector"
},
{
"name": "IbmCosHmacDetector"
},
{
"name": "JwtTokenDetector"
},
{
"keyword_exclude": null,
"name": "KeywordDetector"
},
{
"name": "MailchimpDetector"
},
{
"name": "NpmDetector"
},
{
"name": "PrivateKeyDetector"
},
{
"name": "SlackDetector"
},
{
"name": "SoftlayerDetector"
},
{
"name": "SquareOAuthDetector"
},
{
"name": "StripeDetector"
},
{
"name": "TwilioKeyDetector"
}
],
"results": {},
"version": "0.13.1+ibm.62.dss",
"word_list": {
"file": null,
"hash": null
}
}
40 changes: 38 additions & 2 deletions build-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ None
EOF
}

function check_exit_code () {
# This function takes 3 parameters in the form:
# $1 an integer value of the returned exit code
# $2 an error message to display if $1 is not equal to 0
if [[ "$1" != "0" ]]; then
error "$2"
exit 1
fi
}

#--------------------------------------------------------------------------
#
# Main script logic
Expand Down Expand Up @@ -119,7 +129,8 @@ function download_node_dependencies {
cd ${BASEDIR}/galasa-ui

npm clean-install
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to download node.js dependencies. rc=${rc}" ; exit 1 ; fi
rc=$?
check_exit_code $rc "Failed to download node.js dependencies. rc=${rc}"
success "OK"
}

Expand All @@ -133,7 +144,8 @@ function generate_rest_client {
fi

gradle --warning-mode all --info --debug generateTypeScriptClient
rc=$? ; if [[ "${rc}" != "0" ]]; then error "Failed to generate the TypeScript client code from the openapi.yaml file. rc=${rc}" ; exit 1 ; fi
rc=$?
check_exit_code $rc "Failed to generate the TypeScript client code from the openapi.yaml file. rc=${rc}"
success "Code generation OK"

h2 "Fixing compilation errors in generated code..."
Expand Down Expand Up @@ -177,9 +189,33 @@ function do_build {
fi
success "Built OK."
}
function check_secrets {
h2 "updating secrets baseline"
cd ${BASEDIR}
detect-secrets scan --exclude-files galasa-ui/package-lock.json --update .secrets.baseline
rc=$?
check_exit_code $rc "Failed to run detect-secrets. Please check it is installed properly"
success "updated secrets file"

h2 "running audit for secrets"
detect-secrets audit .secrets.baseline
rc=$?
check_exit_code $rc "Failed to audit detect-secrets."

#Check all secrets have been audited
secrets=$(grep -c hashed_secret .secrets.baseline)
audits=$(grep -c is_secret .secrets.baseline)
if [[ "$secrets" != "$audits" ]]; then
error "Not all secrets found have been audited"
exit 1
fi
sed -i '' '/[ ]*"generated_at": ".*",/d' .secrets.baseline
success "secrets audit complete"
}

generate_rest_client
download_node_dependencies
run_tests
do_build
check_secrets
success "Project built OK."

0 comments on commit f1061c0

Please sign in to comment.