Skip to content

Commit

Permalink
fix(ci): deduplicate trivy login script
Browse files Browse the repository at this point in the history
also login for license scanning
  • Loading branch information
cwrau committed Nov 26, 2024
1 parent fa2ef87 commit c8b9a77
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
10 changes: 1 addition & 9 deletions .github/scripts/generate-sarif-reports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
set -eu
set -o pipefail

declare -A IMAGE_PULL_TOKENS=(
["registry-gitlab.teuto.net"]="${TEUTO_PORTAL_WORKER_PULL_TOKEN}"
)
source "$(dirname "$0")/trivy-login-to-registries.sh"

function createSarifReports() {
local chart="${1?}"
Expand Down Expand Up @@ -47,12 +45,6 @@ function generateSarifReport() {
}
export -f generateSarifReport

trivy image --download-db-only

for registry in "${!IMAGE_PULL_TOKENS[@]}"; do
TRIVY_PASSWORD="${IMAGE_PULL_TOKENS["$registry"]}" trivy registry login --username github-cve-scanning "$registry"
done

if [[ "$#" == 1 && -d "$1" ]]; then
createSarifReports "$1"
else
Expand Down
10 changes: 1 addition & 9 deletions .github/scripts/scan-for-licenses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
set -eu
set -o pipefail

declare -A IMAGE_PULL_TOKENS=(
["registry-gitlab.teuto.net"]="${TEUTO_PORTAL_WORKER_PULL_TOKEN}"
)
source "$(dirname "$0")/trivy-login-to-registries.sh"

WHITELIST=(
"AGPL-3.0" # We're not writing software 🤷
Expand Down Expand Up @@ -89,12 +87,6 @@ function scanLicenses() {
fi
}

trivy image --download-db-only

for registry in "${!IMAGE_PULL_TOKENS[@]}"; do
TRIVY_PASSWORD="${IMAGE_PULL_TOKENS["$registry"]}" trivy registry login --username github-cve-scanning "$registry"
done

if [[ "$#" == 1 && -d "$1" ]]; then
scanLicenses "$1"
else
Expand Down
16 changes: 16 additions & 0 deletions .github/scripts/trivy-login-to-registries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

if ! (return 0 2>/dev/null); then
echo This must be sourced, not executed. >&2
exit 1
fi

declare -A IMAGE_PULL_TOKENS=(
["registry-gitlab.teuto.net"]="${TEUTO_PORTAL_WORKER_PULL_TOKEN?}"
)

trivy image --download-db-only

for registry in "${!IMAGE_PULL_TOKENS[@]}"; do
TRIVY_PASSWORD="${IMAGE_PULL_TOKENS["$registry"]}" trivy registry login --username github-cve-scanning "$registry"
done

0 comments on commit c8b9a77

Please sign in to comment.