API caller for AquaSec full repository scan #6
This file contains hidden or 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
| name: AquaSec Full Repository Scan | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| types: [ opened, synchronize ] | |
| permissions: | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| security-events: write | |
| jobs: | |
| aquasec: | |
| name: AquaSec Full Repository Scan | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| persist-credentials: false | |
| fetch-depth: 0 | |
| - name: Retrieve AquaSec Scan Results | |
| env: | |
| AQUA_KEY: ${{ secrets.AQUA_KEY }} | |
| AQUA_SECRET: ${{ secrets.AQUA_SECRET }} | |
| run: | | |
| echo "=== Authenticating with AquaSec ===" | |
| TIMESTAMP=$(date -u +%s) | |
| AUTH_ENDPOINT="https://eu-1.api.cloudsploit.com" | |
| METHOD="POST" | |
| POST_BODY='{"validity":240,"allowed_endpoints":["GET","POST"]}' | |
| STRING_TO_SIGN="${TIMESTAMP}${METHOD}/v2/tokens${POST_BODY}" | |
| SIGNATURE=$(echo -n "$STRING_TO_SIGN" | openssl dgst -sha256 -hmac "$AQUA_SECRET" -hex | sed 's/.*= //g') | |
| AUTH_RESPONSE=$(curl -s -X "$METHOD" "$AUTH_ENDPOINT" \ | |
| -H "Content-Type: application/json" \ | |
| -H "X-API-Key: $AQUA_KEY" \ | |
| -H "X-Timestamp: $TIMESTAMP" \ | |
| -H "X-Signature: $SIGNATURE" \ | |
| -d "$POST_BODY") | |
| RESPONSE_STATUS=$(echo "$AUTH_RESPONSE" | jq -r '.status') | |
| if [ "$RESPONSE_STATUS" = "200" ]; then | |
| echo "Login successful." | |
| BEARER_TOKEN=$(echo "$AUTH_RESPONSE" | jq -r '.data') | |
| echo "::add-mask::$BEARER_TOKEN" | |
| else | |
| echo "Login failed" | |
| exit 1 | |
| fi | |
| echo "=== Getting Repository ID from GitHub ===" | |
| REPO_ID=$(curl -s "https://api.github.com/repos/${{ github.repository }}" | jq -r '.id') | |
| if [ -z "$REPO_ID" ] || [ "$REPO_ID" = "null" ]; then | |
| echo "Failed to get repository ID from GitHub" | |
| exit 1 | |
| fi | |
| echo "=== Receiving AquaSec Scan Results ===" | |
| SCAN_RESULTS_ENDPOINT="https://eu-central-1.edge.cloud.aquasec.com/codesec/api/v1/scans/results" | |
| SCAN_RESULTS=$(curl -s -X GET \ | |
| "$SCAN_RESULTS_ENDPOINT?repositoryIds=$REPO_ID" \ | |
| -H "Authorization: Bearer $BEARER_TOKEN" \ | |
| -H "Accept: application/json") | |
| if [ -z "$SCAN_RESULTS" ]; then | |
| echo "Failed to retrieve scan results" | |
| exit 1 | |
| fi | |
| echo "=== Scan Results ===" | |
| echo "$SCAN_RESULTS" | jq '.' |