Skip to content

Instantly share code, notes, and snippets.

@mattatsnyk
Last active March 7, 2024 21:23
Show Gist options
  • Save mattatsnyk/87a58e944db34b2e57136d3cf23c301e to your computer and use it in GitHub Desktop.
Save mattatsnyk/87a58e944db34b2e57136d3cf23c301e to your computer and use it in GitHub Desktop.
A script to run IaC+ scans and retrieve the unique ID associated with them
#!/usr/bin/env bash
set -o nounset -o pipefail
# Run the snyk scan and save exit code
snyk iac test --org=c6605e26-42f6-4c23-a347-72827bdab7cd --report --json > iac-results.json
exit_code=$?
# Query API for ID of previous scan and append to file
curl -s -L 'https://api.snyk.io/rest/orgs/c6605e26-42f6-4c23-a347-72827bdab7cd/cloud/scans?version=2024-02-28~beta&environment_id=58e8a75b-bd88-488c-9eb5-8b2ea8bef0a6' \
--header "authorization: $snyk_token" | jq '.data[0].id' >> iac-results.json
# Return the exit code of the scan
exit $exit_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment